Polyglot Programming

Learn C#, Python, and Go through practical examples

Project setup

Learn how to setup a project and add the necessary dependencies and packages

go python

Project setup

Clone the reference C# implementation. This will be used to guide us on creating the Go and Python versions of the CLI tool.

git clone https://github.com/XPRTZ/envtamer

Create a new Git repository for this workshop locally and push it on your own GitHub account. This will be the repository where we will work on.

github.com/username/envtamer-workshop
β”œβ”€β”€ go
β”‚Β Β  └── .gitkeep
└── python
    └── .gitkeep

Go

Make sure you are in the go directory of the project

npx gitignore go
go mod init github.com/username/envtamer-workshop
go get -u github.com/spf13/cobra@latest

In the root of the go folder there should now be a go.mod file. This file lists all the dependencies.

Create the following folder structure. The structure is based on the recommended way to setup a Go project

β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
β”œβ”€β”€ cmd
β”‚Β Β  └── envtamer
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
└── internal
    β”œβ”€β”€ command
    β”œβ”€β”€ storage
    └── util

Python

Make sure you are in the go directory of the project

npx gitignore python
poetry new envtamer
poetry env use 3.13
poetry env activate
poetry add click

In the root of the envtamer folder there will be a pyproject.toml file. This file lists all the dependencies.

Create the following folder structure. The structure is based on the recommended way to setup a poetry python project

When opening the project in your IDE, make sure to select the correct Python interpreter. This should be the one created by poetry. You can check this by pressing ctr + shift + p and typing β€œPython: Select Interpreter”. Select the one that has the path to the envtamer folder in it.

β”œβ”€β”€ envtamer
β”‚Β Β  └── __init__.py
β”œβ”€β”€ tests
β”‚Β Β  └── __init__.py
β”œβ”€β”€ poetry.lock
β”œβ”€β”€ pyproject.toml
└── README.md