Note: some badges above will not work until Github CI has been set up and the app is published in Pypi
The dwarf_copier project gives a straightforward way to extract image files from a Dwarf II smart telescope onto a PC for further processing (e.g. using Siril) or as a backup.
There are multiple good Python IDE, but I'm would suggest using vscode with at least these plugins:
- Python to add python language support
- Mypy for type checking
- ruff formatting and linting your code
- even-better-toml for a better TOML file support (and poetry configuration file is a toml file)
- textual validates Textual's CSS
Poetry is used to handle dependencies:
poetry add
to add a new dependenciespoetry install
to create a virtualenv with all needed libraries to run your apppoetry shell
to enter your virtualenv and run your app or testspoetry build
to create a distributable binary package of your app
To run the tests, you need to be in the virtualenv then just run tox
or pytest
:
# init your virtualenv if it is not
$ poetry install
# enter your virtualenv
$ poetry shell
# note that your shell prompt is updated once you are in a virtualenv
(dwarf_copier-py3.10) $ pytest
====================================== test session starts ======================================
platform linux -- Python 3.10.13, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/kupuguy/dwarf_copier
plugins: dotenv-0.5.2, cov-4.0.0
collected 3 items
tests/test_cli.py ... [ 66%]
tests/test_user.py . [100%]
======================================= 3 passed in 0.07s =======================================
You can use Poetry to build the app and get a .whl
$ poetry build
Building cool-project (0.1.0)
- Building sdist
- Built cool_project-0.1.0.tar.gz
- Building wheel
- Built cool_project-0.1.0-py3-none-any.whl
$ ls -l dist
total 20
-rw-r--r-- 1 seb users 8569 17 oct. 11:12 cool_project-0.1.0-py3-none-any.whl
-rw-r--r-- 1 seb users 7484 17 oct. 11:12 cool_project-0.1.0.tar.gz
You can use Poetry to publish your app to PyPI
$ poetry publish
By default, Github Actions are configured to
- build your app and run your unit tests with coverage on every push
- build the wheel package and upload it to Pypi on every tag
Note: to allow Github CI to publish on PyPI, you need to create a token and add it to your project settings, the name of the token should be
PYPI_TOKEN
I personnally use this command to bump the version using poetry, create the associated git tag and push to Github:
# for a patch bump
$ poetry version patch && git commit -a -m '๐ New release' && git tag -f $(poetry version -s) && git push --tags
# for a minor bump
$ poetry version minor && git commit -a -m '๐ New release' && git tag -f $(poetry version -s) && git push --tags
# for a major bump
$ poetry version major && git commit -a -m '๐ New release' && git tag -f $(poetry version -s) && git push --tags
Install from the sources
$ pip3 install poetry
$ pip3 install git+https://github.com/jdoe/cool-project
$ cool-command --help
Install from PyPI if you published it
$ pip3 install cool-project
$ cool-command --help
# create the new project folder
$ mkdir cool-project && cd cool-project
# create a README
$ cat << EOF >> README.md
Here is my cool project
EOF
# configure excluded files
$ cat << EOF >> .gitignore
# Generated files
__pycache__
*.pyc
/.pytest_cache
/.coverage*
/dist
# IDE configuration
/.vscode/*
!/.vscode/settings.json
EOF
# init the root python module
$ mkdir cool_project
$ cat << EOF >> cool_project/__init__.py
from importlib.metadata import version
__version__ = version(__name__)
EOF
# create the first commit
$ git init
$ git add .
$ git commit -m "๐ First release"
# init the poetry pyproject.toml
$ poetry init -n
# configure poetry to create the virtualenv dir in the project folder
$ cat << EOF >> poetry.toml
[virtualenvs]
in-project = true
EOF
# create the virtualenv
$ poetry shell
# add some runtime dependencies
$ poetry add colorama
# add some development dependencies
$ poetry add --group dev black isort pylint pytest pytest-cov pytest-dotenv
# install your package
$ poetry install
# test that your app is installed in your virtualenv
$ python -c 'import cool_project; print(cool_project.__version__)'
Snippet to add an entrypoint
[tool.poetry.scripts]
mycommand = 'cool_project.cli:run'