Skip to content

Commit

Permalink
WIP: Migrate dependency management to poetry
Browse files Browse the repository at this point in the history
Switch dependency management to use poetry, which is much nicer than
pip-tools. This is largely based off of
<freedomofpress/securedrop-proxy#122> and
applies the same changes to the Makefile and CI.

The main difference is that we install PyQt5 via system packages, so the
two versions we specifically need are listed in pyproject.toml and vary
on the Python versions shipped with bullseye and bookworm.

We also don't actually need the pathlib2 dependency any more because
our Python version is high enough, so it's dropped now that poetry
is smart enough to detect it!
  • Loading branch information
legoktm committed Dec 6, 2023
1 parent 3635064 commit 9c8d083
Show file tree
Hide file tree
Showing 17 changed files with 2,529 additions and 4,388 deletions.
96 changes: 35 additions & 61 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
---
common-steps:
- &install_poetry
run:
name: Install Poetry
command: |
set -e
source /etc/os-release
if [[ "$VERSION_CODENAME" == "bullseye" ]]; then
# Install Poetry via PyPI
apt-get update && apt-get install --yes --no-install-recommends python3-pip
pip install poetry==1.6.1
elif [[ "$VERSION_CODENAME" == "bookworm" ]]; then
# Install Poetry via system package
apt-get update && apt-get install --yes --no-install-recommends python3-poetry
else
echo "Unsupported Debian version: $VERSION_CODENAME"
exit 1
fi
- &install_testing_dependencies
run:
name: Install testing dependencies
command: |
set -e
apt update && apt install -y git gnupg libarchive13 libmagic1 libqt5x11extras5 make python3-tk python3-dev gnupg python3-venv sqlite3 xvfb
poetry install --no-ansi
- &configure_locales
run:
Expand All @@ -21,90 +40,57 @@ common-steps:
run:
name: Install build dependencies
command: |
set -e
apt update && apt install -y git make sudo
- &run_unit_tests
run:
name: Install requirements and run unit tests
command: |
set -e
export VERSION_CODENAME=$(~/project/scripts/codename)
make venv
source .venv/bin/activate
export PYTHONPATH=$PYTHONPATH:. # so alembic can get to Base metadata
make test-random
- &run_integration_tests
run:
name: Install requirements and run integration tests
command: |
set -e
export VERSION_CODENAME=$(~/project/scripts/codename)
make venv
source .venv/bin/activate
export PYTHONPATH=$PYTHONPATH:. # so alembic can get to Base metadata
make test-integration
- &run_functional_tests
run:
name: Install requirements and run functional tests
command: |
set -e
export VERSION_CODENAME=$(~/project/scripts/codename)
make venv
source .venv/bin/activate
export PYTHONPATH=$PYTHONPATH:. # so alembic can get to Base metadata
make test-functional
- &run_lint
run:
name: Run lint, type checking, code formatting
command: |
set -e
export VERSION_CODENAME=$(~/project/scripts/codename)
make venv
source .venv/bin/activate
make check-black check-isort lint mypy
- &check_security
run:
name: Run static analysis on source code to find security issues
command: |
set -e
export VERSION_CODENAME=$(~/project/scripts/codename)
make venv
source .venv/bin/activate
make semgrep bandit
- &check_source_strings
run:
name: Check that source strings are updated
command: |
set -e
export VERSION_CODENAME=$(~/project/scripts/codename)
make venv
source .venv/bin/activate
make check-strings
- &check_mo_repro
run:
name: Check that translation machine objects are reproducible
command: |
set -e
export VERSION_CODENAME=$(~/project/scripts/codename)
make venv
source .venv/bin/activate
make verify-mo
- &check_python_dependencies_for_vulnerabilities
run:
name: Check Python dependencies for known vulnerabilities
command: |
set -e
export VERSION_CODENAME=$(~/project/scripts/codename)
make venv
source .venv/bin/activate
make safety
- &install_packaging_dependencies
Expand All @@ -119,6 +105,7 @@ common-steps:
cd securedrop-builder
apt-get update && apt-get install -y sudo make
make install-deps
source .venv/bin/activate
PKG_DIR=~/project make requirements
- &check_packaging_requirements
Expand All @@ -129,17 +116,6 @@ common-steps:
# Fail if unstaged changes exist that are not comments (after `make requirements` in the previous run step).
git diff --ignore-matching-lines=# --exit-code
- &check_testing_requirements
run:
name: Ensure that the same Python requirements are used for development/testing and production.
command: |
set -e
export VERSION_CODENAME=$(~/project/scripts/codename)
make venv
source .venv/bin/activate
make requirements
git diff --exit-code requirements/dev-${VERSION_CODENAME}-requirements.txt
- &build_debian_package
run:
name: Build debian package
Expand All @@ -149,6 +125,7 @@ common-steps:
cd ~/packaging/securedrop-builder
export PKG_VERSION=1000.0
export PKG_PATH=~/project/
source .venv/bin/activate
make securedrop-client
version: 2.1
Expand All @@ -171,9 +148,10 @@ jobs:
parameters: *parameters
docker: *docker
steps:
- *install_poetry
- checkout
- *install_testing_dependencies
- *configure_locales
- checkout
- *run_unit_tests
- store_test_results:
path: test-results
Expand All @@ -182,60 +160,58 @@ jobs:
parameters: *parameters
docker: *docker
steps:
- *install_testing_dependencies
- *install_poetry
- checkout
- *install_testing_dependencies
- *run_integration_tests

functional-test:
parameters: *parameters
docker: *docker
steps:
- *install_testing_dependencies
- *install_poetry
- checkout
- *install_testing_dependencies
- *run_functional_tests

lint:
parameters: *parameters
docker: *docker
steps:
- *install_testing_dependencies
- *install_poetry
- checkout
- *install_testing_dependencies
- *run_lint

check-security:
parameters: *parameters
docker: *docker
steps:
- *install_testing_dependencies
- *install_poetry
- checkout
- *install_testing_dependencies
- *check_security

check-python-security:
parameters: *parameters
docker: *docker
steps:
- *install_testing_dependencies
- *install_poetry
- checkout
- *install_testing_dependencies
- *check_python_dependencies_for_vulnerabilities


check-internationalization:
parameters: *parameters
docker: *docker
steps:
- *install_testing_dependencies
- *install_poetry
- checkout
- *install_testing_dependencies
- *check_source_strings
- *check_mo_repro

check-testing-requirements:
parameters: *parameters
docker: *docker
steps:
- *install_testing_dependencies
- checkout
- *check_testing_requirements

workflows:
securedrop_client_ci:
jobs: &jobs
Expand All @@ -251,8 +227,6 @@ workflows:
matrix: *matrix
- lint:
matrix: *matrix
- check-testing-requirements:
matrix: *matrix
- check-security:
matrix: *matrix
- check-python-security:
Expand Down
Loading

0 comments on commit 9c8d083

Please sign in to comment.