Skip to content

Commit

Permalink
Switch to poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsasha committed Feb 23, 2023
1 parent 4b0b8dc commit 086978c
Show file tree
Hide file tree
Showing 10 changed files with 3,315 additions and 251 deletions.
66 changes: 27 additions & 39 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,33 +102,29 @@ commands:
name: Installing psql client, enchant, netcat, rust
command: $SUDO apt -y install postgresql-client netcat python3-enchant rustc

- run:
name: Installing poetry if needed
command: which poetry || curl -sSL https://install.python-poetry.org | POETRY_HOME=/usr python3 -

- restore_cache:
keys:
- v21-dependencies-{{ .Environment.CIRCLE_JOB }}-{{ checksum
"requirements.txt" }}
- v2-dependencies-{{ .Environment.CIRCLE_JOB }}-{{ checksum
"poetry.lock" }}
# fallback to using the latest cache if no exact match is found
- v21-dependencies-{{ .Environment.CIRCLE_JOB }}

- run:
name: install latest pip
command: |
$PYTHON_INTERPRETER -m venv venv
. venv/bin/activate
pip install -U pip
- v2-dependencies-{{ .Environment.CIRCLE_JOB }}

- run:
name: install dependencies
command: |
PATH=$PATH:/root/.cargo/bin/
$PYTHON_INTERPRETER -m venv venv
. venv/bin/activate
pip install -vUr requirements.txt
name: install python dependencies
working_directory: irrd
environment:
POETRY_VIRTUALENVS_IN_PROJECT: true
command: poetry -n --no-ansi --no-root --with=dev,docs install

- save_cache:
paths:
- ./venv
key: v21-dependencies-{{ .Environment.CIRCLE_JOB }}-{{ checksum
"requirements.txt" }}
- /mnt/ramdisk/.venv
key: v2-dependencies-{{ .Environment.CIRCLE_JOB }}-{{ checksum
"poetry.lock" }}

wait_for_postgres:
steps:
Expand All @@ -147,9 +143,7 @@ commands:
steps:
- run:
name: run regular tests
command: |
. venv/bin/activate
py.test -s -vvvv --cov=irrd irrd --junitxml=test-reports/junit.xml --cov-fail-under=100 --cov-report term-missing:skip-covered
command: poetry -n --no-ansi run py.test -s -vvvv --cov=irrd irrd --junitxml=test-reports/junit.xml --cov-fail-under=100 --cov-report term-missing:skip-covered

create_integration_test_db:
steps:
Expand All @@ -167,9 +161,7 @@ commands:
steps:
- run:
name: run integration tests
command: |
. venv/bin/activate
py.test irrd/integration_tests/run.py -s
command: poetry -n --no-ansi run py.test irrd/integration_tests/run.py -s

store_results:
steps:
Expand Down Expand Up @@ -227,7 +219,7 @@ jobs:
redis_version:
type: string

resource_class: small
resource_class: medium
working_directory: /mnt/ramdisk
docker:
- image: pypy:<< parameters.python_version >>
Expand Down Expand Up @@ -352,21 +344,19 @@ jobs:

- run:
name: run ruff
command: |
. venv/bin/activate
ruff irrd
command: poetry -n --no-ansi run ruff irrd

- run:
name: run isort
command: |
. venv/bin/activate
isort --check --diff irrd
command: poetry -n --no-ansi run isort --check --diff irrd

- run:
name: run mypy
command: |
. venv/bin/activate
mypy irrd
command: poetry -n --no-ansi run mypy irrd

- run:
name: run black
command: poetry -n --no-ansi run black --check irrd


build_docs:
Expand Down Expand Up @@ -398,13 +388,11 @@ jobs:
- run:
name: hack sphinx_immaterial
command: |
sed -i 's/max_workers=32/max_workers=1/' /mnt/ramdisk/venv/lib/py*/site-packages/sphinx_immaterial/google_fonts.py
sed -i 's/max_workers=32/max_workers=1/' /mnt/ramdisk/.venv/lib/py*/site-packages/sphinx_immaterial/google_fonts.py
- run:
name: build docs
command: |
. venv/bin/activate
sphinx-build -nW -b spelling docs/ docs/build
command: poetry -n --no-ansi run sphinx-build -nW -b spelling docs/ docs/build

- save_cache:
paths:
Expand Down
3 changes: 0 additions & 3 deletions .isort.cfg

This file was deleted.

34 changes: 19 additions & 15 deletions docs/development/development-setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ Development setup
Development environment & unit tests
------------------------------------

This project uses poetry_.
The basic method to set up a local environment is::

mkvirtualenv -p `which python3` irrd
pip install -r requirements.txt
poetry install --no-root --with=dev,docs

Poetry will make a virtualenv by default, details of which you
can find in ``poetry env info``. The rest of this page assumes
you are running commands inside ``poetry shell``.

.. _poetry: https://python-poetry.org/

Some of the test use a live database for thoroughness. The database
URL needs to be set in ``IRRD_DATABASE_URL``, e.g. for a local database,
Expand Down Expand Up @@ -79,30 +85,28 @@ Code coverage is not measured for the integration test, as its purpose is
not to test all paths, but rather verify that the most important paths
are working end-to-end.

Mypy and flake8
---------------
Linting and formatting
----------------------

In addition to the tests, this project uses `mypy` for type checking and `flake8`
In addition to the tests, this project uses `mypy`, `ruff`, `isort` and `black`
for style checking. To run these, run::

mypy irrd
flake8
ruff irrd
isort irrd
black irrd

If all is well, neither command should provide output.
The versions of these tools may only work on newer CPython versions.

Exclusions from checks
----------------------

Code can be excluded from code coverage, and can be excluded from checks by
`mypy` and `flake8`. This should be done in rare cases, where the quality of
`mypy`. This should be done in rare cases, where the quality of
the code would suffer otherwise, and for tests where the risks are small and
the effort would be great.

To ignore a line or block for test coverage, add ``# pragma: no cover`` to
the end, ``# type:ignore`` to ignore `mypy` errors, and ``# noqa: <number>``
for `flake8` violations. For the latter, the number is the error number
from the command output.
the end, and ``# type:ignore`` to ignore `mypy` errors.

Docs
----
Expand All @@ -128,14 +132,14 @@ To create a new packaged version of IRRD:
cherry-pick the changes from the main branch, at least including the release
notes commit. Version updates of dependencies are not generally applied to
the release branch, except in case of known important bugs or security issues.
* Ensure the version is correct/updated in ``irrd/__init__.py``.
* Ensure the version is correct/updated in ``irrd/__init__.py`` and ``pyproject.toml``.
* Commit the version change (in the existing release branch if there is one).
* Tag the new release with git (`git tag v<version>`),
and push the tag (`git push origin v<version>`).
* Run ``./setup.py sdist bdist_wheel``
* Run ``poetry build``
* Your source archive and built distribution are now in ``dist/``
* Create a new release on GitHub
* If this is not a pre-release, upload to PyPI with ``twine upload dist/*``
* If this is not a pre-release, upload to PyPI with ``poetry publish``
* If this was a new minor release (x.y), create a new branch for it.

For more background, a good start is the `Python packaging tutorial`_.
Expand Down
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ integrations
journaling
keepalive
keychain
keyring
logfile
loglevel
logrotate
Expand Down
Loading

0 comments on commit 086978c

Please sign in to comment.