Skip to content

71 introduce pip-tools #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install just
uses: extractions/setup-just@v1
- name: Install poetry
uses: abatilo/actions-poetry@v2
- name: Install dependencies
run: |
just install
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ Read [here](https://www.butterfly.com.au/blog/website-development/clean-high-qua
- [MkDocs](https://www.mkdocs.org/)
- generates html documentation

- [Pip-tools]
- Simplifies updating requirements.
- `pip-compile requirements.in` generates requirements.txt
- `pip-sync` installs from requirements.txt
- You can also have dev-requirements if you want

- [Poetry](https://python-poetry.org/)
- Poetry comes with all the tools you might need to manage your projects in a deterministic way
- Dependency resolver, isolation, cli
Expand Down Expand Up @@ -90,17 +96,17 @@ It will create the first commit with the skeleton files.

First installation from scratch (assume python virtualenv active):

just startup # install the latest versions of requirements and check everything is ok

If something fails, try:

just install # use frozen requirements that are already checked
just install # install dependencies and check everything is ok

Optionally, you can also install the git hooks (further automatic
checks, pedantic):

just install-hooks

To install hook to black-format code before commit:

black-hook:

### Badges

If you want to add badges to your project associated with the actions setup in `.github/workflows`, you can use the following command:
Expand Down
6 changes: 3 additions & 3 deletions docs/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

## Flask app

::: src.flask_app.hello_world
::: src.cleanpython.flask_app.hello_world

::: src.flask_app.index
::: src.cleanpython.flask_app.index

## Foobar

::: src.foobar.sum_two_numbers
::: src.cleanpython.foobar.sum_two_numbers
68 changes: 29 additions & 39 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ MIN_COVERAGE := '100'

# just show the help
@help:
echo "# INSTALL\n"
echo "## Install using poetry\n"
echo " poetry install"
echo "## INSTALL"
echo
echo "If you only want to install the project’s runtime dependencies:\n"
echo " poetry install --only main"
echo " just install"
echo " # or pip-sync"
echo
echo "Ensure that the locked dependencies in the poetry.lock file are the only ones present in the environment, removing anything that’s not necessary."
echo " poetry install --sync"
echo
echo "Add dependencies to the current project:\n"
echo " poetry add <dependency>"
echo
echo "Add a development dependency:\n"
echo " poetry add <dependency> --group dev"
echo "## Update"
echo " just up"
echo
echo "## Testing and code quality"
echo
Expand Down Expand Up @@ -92,12 +84,12 @@ MIN_COVERAGE := '100'
git add .
git commit -m "Initial commit (based on CleanPython template)"

# first time installation to get the new versions of libraries and check everything is ok
@startup:
poetry self update
echo "Get the new versions of libraries and check everything is ok"
just up
poetry install
# install everything
@install:
pip install --upgrade pip
pip install --upgrade pip-tools
pip-compile
pip-sync
echo "Complete checkup of code: lint and test coverage"
just check
echo "Creating documentation of current codebase"
Expand All @@ -107,14 +99,11 @@ MIN_COVERAGE := '100'
echo =========================================================================================
echo "You can now run 'just' to get a list of available recipes, or 'just help' to get more info."

# install stuff: dependencies (using poetry) and git hooks
install:
poetry install

# get the latest versions of the installed libraries
up:
poetry update
poetry run pylint --generate-rcfile > pylintrc
pip install --upgrade pip
pip-compile --upgrade
pylint --generate-rcfile > pylintrc
@echo "Now you can call `just install`"

# (beta) for VirtualFish: like 'up' but recreate vf virtualenv to remove also old dependencies
Expand All @@ -131,6 +120,7 @@ install-hooks:
# install pre-push hook
echo "just test" > .git/hooks/pre-push&&chmod +x .git/hooks/pre-push

# install hook to black code before commit
black-hook:
# ensures that all your commits contain Python code formatted according to Black’s rules.
cp pre-commit-black .git/hooks/pre-commit&&chmod +x .git/hooks/pre-commit
Expand All @@ -143,19 +133,19 @@ setenv VIRTUALENV:
@echo Now please activate the virtualenv, then call \"just doc\".

@_mypy:
poetry run mypy --ignore-missing-imports src
mypy --ignore-missing-imports src

@_flake8:
poetry run flake8 .
flake8 .

@_pylint:
poetry run pylint $(git ls-files '*.py') --ignore conf.py
pylint $(git ls-files '*.py') --ignore conf.py

@_isort:
poetry run isort --check-only --recursive --quiet . || just _fail "Fix imports by calling \'just fix\'."
isort --check-only --recursive --quiet . || just _fail "Fix imports by calling \'just fix\'."

@_black:
poetry run black --check -q . || just _fail "Fix code formatting by calling \'just fix\'."
black --check -q . || just _fail "Fix code formatting by calling \'just fix\'."

# statically check the codebase (mypy, flake8, pylint, isort)
@lint:
Expand All @@ -172,29 +162,29 @@ setenv VIRTUALENV:

# auto fix imports and pep8 coding style
@fix:
poetry run isort .
poetry run black .
isort .
black .
# Re-check code quality
just lint

# run tests with coverage
@_test-cov:
poetry run pytest --cov --cov-report=xml .
pytest --cov --cov-report=xml .

# run tests only (with no coverage and no lint)
@test:
poetry run pytest
pytest
echo "Tests: OK ✅✅✅✅"

# run tests with coverage.py, create html report and open it
@cov:
just _test-cov
poetry run coverage html # create an HTML report
coverage html # create an HTML report
just _open-nofail htmlcov/index.html

# check if coverage satisfies requirements
@_check-cov:
poetry run coverage report --fail-under {{MIN_COVERAGE}}
coverage report --fail-under {{MIN_COVERAGE}}
echo "\nTest coverage {{MIN_COVERAGE}}% : OK ✅✅✅✅✅"

# complete checkup: code analysis, tests and coverage
Expand Down Expand Up @@ -234,15 +224,15 @@ setenv VIRTUALENV:

# execute benchmarks tests only, in benchmark mode.
@benchmarks K_SELECTOR="test":
poetry run pytest --benchmark-enable --benchmark-only -k {{K_SELECTOR}} .
pytest --benchmark-enable --benchmark-only -k {{K_SELECTOR}} .

# serve HTML documentation
@doc:
poetry run mkdocs serve
mkdocs build

# deploy HTML documentation to github pages
@doc-deploy:
poetry run mkdocs gh-deploy
mkdocs gh-deploy

# WARNING! Remove untracked stuff (git clean -idx)! Useful to clean artifacts.
clean:
Expand Down
Loading