A template repository for Python development
-
Install
pyenv
:curl https://pyenv.run | bash
Then install a Python interpreter in
pyenv
:pyenv install 3.12 pyenv global 3.12
To allow multi-version testing, install multiple versions, e.g.:
pyenv install 3.12 3.11 3.10 pyenv global 3.12 3.11 3.10
-
Install the development dependencies:
pip install -r requirements-dev.txt
-
Install the pre-commit hooks:
pre-commit install
-
If your IDE or editor doesn't do it for you, create virtual environment:
python -m venv venv
Then activate it (do this every time you work on the project):
. venv/bin/activate
After you're done, deactivate the virtual environment:
deactivate
-
Change
pyproject.toml
to match your needs (in particular project name, description, keywords, authors, and maintainers). -
Change the
multiplier
directory to your project name, write your project code, your tests, and your example scripts. -
Install your package locally:
pip install -e .
-
After programming, put all packages you used into the
requirements.txt
file:pip freeze > requirements.txt
Then remove the local package from the file (line starts with
-e
). -
Test your code:
tox
-
Add all new files via
git add
. -
Do a dry-run of all pre-commit checks:
pre-commit run --all-files
-
Commit and push your code, then check result of GitHub actions.
-
download, via brew (in the terminal) the version needed
brew install python@3.12
-
check if good version
python --version
or
python3.12 --version
-
to obtain the list of the libraries inside the old environment :
pip freeze > requirements.txt
-
To create a new environment inside VSCode
- first delete the old environment
- use command line to create a new environement with the Python version needed :
where here ".venv" is the name of the environment
python3.12 -m venv .venv
- activate the environment :
source .venv/bin/activate
- put the "requirement.txt" file INSIDE the folder of the code and import the old librairies
pip3 install -r requirements.txt
- finally check if the Python version is the good one
python --version
For example : DS_Store
-
Open the terminal, and select the path and the GitHub folder
-
Check on "GitHub Desktop" if the folder is sync with GitHub (and do it previously otherwise)
-
Remove the file wanted, from Git (but no physical deletion on the PC) - here .DS_Store is the name of the file -> To change • rm : commande to delete files of the Git index • --cached : commande to delete files of the Git index, not on the hardisk
git rm --cached .DS_Store
-
Confirme the deletion of the file
git status
-> We should have a message of this kind : Changes to be committed: (use "git restore --staged ..." to unstage) deleted: .DS_Store
-
Save the modifications in Git history (change the message between "" to match the modification)
git commit -m "Remove .DS_Store file from repository"
-
Open GitHub Desktop, and select "Fetch History"
-
Add the ".DS_Store" mention inside the ".gitignore" file
-
If the version in GitHub is not the one that is available locally (updated by another user) -> needs to be actualised -> (to set the "pull" command to "merge" the local version [if we made modifications or not], and the online one, globally (= by default))
git config pull.rebase false --global
Then
git pull
-
To commit all & add a message
git commit -a -m "write the comment here"
-
Add a tag (= version, readable by PyPi)
git tag v0.0.4
(here nb of the version wanted)
-
Push both (code and tags) on Git
git push git push --tags
-
Remove the old version on PyPi first (won't allow to add the file on another one) (dist folder)
rm -rf dist
-
Construct the "environment" for PyPi
hatch build
-
Publish on PyPi
hatch publish
/!\ Need to "log in" via API token (easiest way) -> settings of the account and "Create API token"
/!\ The token code will appear only ONCE, so save it somewhere /!
It will be asked when using "hatch publish" :
username = "token" (2 underscores to fill)
password = token code given
It will open the whole folder in VSCode
code .
command S to save
Pay attention of the format of the files used, if there is a format problem :
ruff format