This repository has been archived by the owner on Nov 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(python): Use Poetry for package management
In CI, since the packages are now installed in a virtualenv rather than globally, we have to activate the virtualenv at the start of jobs. The cattrs package has to be kept back to before version 1.1.0 until we either upgrade to Python 3.7 or AWS CDK moves to a dependency which doesn't transitively depend on Python 3.7. Issue linked on the relevant pyproject.toml line. This merges the production dependencies of the backend and infra subdirectories, which is not ideal. Once subproject support <python-poetry/poetry#2270> arrives we should pull this apart, maybe keeping only the development and test dependencies in the root. To mitigate this in the meantime, bundle.bash pulls out only those dependencies which the Lambda function needs.
- Loading branch information
Showing
11 changed files
with
2,146 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,32 +22,31 @@ jobs: | |
- name: Install Python dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements-dev.txt | ||
pip install -r infra/requirements.txt | ||
pip install -r backend/endpoints/datasets/requirements.txt | ||
python -m pip install poetry | ||
python -m poetry install | ||
- name: Check last commit message | ||
if: github.event_name == 'push' | ||
run: | | ||
gitlint | ||
poetry run gitlint | ||
- name: Check all commit messages in Pull Request | ||
if: github.event_name == 'pull_request' | ||
run: > | ||
gitlint --commits | ||
poetry run gitlint --commits | ||
origin/${{ github.base_ref }}..${{ github.event.pull_request.head.sha }} | ||
- name: Check Python code formatting | ||
run: | | ||
black . --check --diff | ||
poetry run black . --check --diff | ||
- name: Check Python code quality | ||
run: | | ||
pylint backend/ infra/ | ||
poetry run pylint backend/ infra/ | ||
- name: Check Python code import statements | ||
run: | | ||
isort . --check --diff | ||
poetry run isort . --check --diff | ||
test: | ||
|
@@ -69,12 +68,12 @@ jobs: | |
- name: Install Python dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements-dev.txt | ||
pip install -r infra/requirements.txt | ||
python -m pip install poetry | ||
python -m poetry install | ||
- name: Run unit tests | ||
run: | | ||
pytest tests/ | ||
poetry run pytest tests/ | ||
test-infra: | ||
|
@@ -96,9 +95,8 @@ jobs: | |
- name: Install Python dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements-dev.txt | ||
pip install -r infra/requirements.txt | ||
pip install -r backend/endpoints/datasets/requirements.txt | ||
python -m pip install poetry | ||
python -m poetry install | ||
- name: Use Node.js 12.x for CDK deployment | ||
uses: actions/[email protected] | ||
|
@@ -110,7 +108,7 @@ jobs: | |
run: npm install -g aws-cdk | ||
|
||
- name: Print CDK version | ||
run: cdk --version | ||
run: poetry run cdk --version | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
|
@@ -128,21 +126,21 @@ jobs: | |
- name: Deploy AWS stack for testing | ||
run: | | ||
cdk bootstrap aws://unknown-account/ap-southeast-2 | ||
cdk deploy --require-approval never geospatial-data-lake | ||
poetry run cdk bootstrap aws://unknown-account/ap-southeast-2 | ||
poetry run cdk deploy --require-approval never geospatial-data-lake | ||
working-directory: infra | ||
|
||
- name: Run AWS infra tests | ||
run: | | ||
pytest infra/tests/ | ||
poetry run pytest infra/tests/ | ||
- name: Run AWS backend tests | ||
run: | | ||
pytest backend/tests/ | ||
poetry run pytest backend/tests/ | ||
- name: Destroy AWS stack used for testing | ||
run: | | ||
cdk destroy --force geospatial-data-lake | ||
poetry run cdk destroy --force geospatial-data-lake | ||
working-directory: infra | ||
|
||
|
||
|
@@ -167,8 +165,8 @@ jobs: | |
- name: Install Python dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements-dev.txt | ||
pip install -r infra/requirements.txt | ||
python -m pip install poetry | ||
python -m poetry install --no-dev | ||
- name: Use Node.js 12.x for CDK deployment | ||
uses: actions/[email protected] | ||
|
@@ -180,7 +178,7 @@ jobs: | |
run: npm install -g aws-cdk | ||
|
||
- name: Print CDK version | ||
run: cdk --version | ||
run: poetry run cdk --version | ||
|
||
# NONPROD DEPLOYMENT | ||
- name: (NonProd) Configure AWS credentials | ||
|
@@ -199,9 +197,11 @@ jobs: | |
if: > | ||
github.ref == 'refs/heads/master' | ||
&& github.repository == 'linz/geospatial-data-lake' | ||
env: | ||
DEPLOY_ENV: nonprod | ||
run: | | ||
cdk bootstrap aws://unknown-account/ap-southeast-2 | ||
DEPLOY_ENV=nonprod cdk deploy --require-approval never geospatial-data-lake | ||
poetry run cdk bootstrap aws://unknown-account/ap-southeast-2 | ||
poetry run cdk deploy --require-approval never geospatial-data-lake | ||
working-directory: infra | ||
|
||
# PROD DEPLOYMENT | ||
|
@@ -221,7 +221,9 @@ jobs: | |
if: > | ||
startsWith(github.ref, 'release') | ||
&& github.repository == 'linz/geospatial-data-lake' | ||
env: | ||
DEPLOY_ENV: prod | ||
run: | | ||
cdk bootstrap aws://unknown-account/ap-southeast-2 | ||
DEPLOY_ENV=prod cdk deploy --require-approval never geospatial-data-lake | ||
poetry run cdk bootstrap aws://unknown-account/ap-southeast-2 | ||
poetry run cdk deploy --require-approval never geospatial-data-lake | ||
working-directory: infra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o errexit -o noclobber -o nounset | ||
|
||
python -m venv .venv | ||
. .venv/bin/activate | ||
python -m pip install --upgrade pip | ||
python -m pip install poetry | ||
|
||
work_dir="$(mktemp --directory)" | ||
all_requirements_file="${work_dir}/all-requirements.txt" | ||
backend_requirements_file="${work_dir}/backend-requirements.txt" | ||
|
||
# Get requirements file for entries in requirements.txt | ||
poetry export --output="$all_requirements_file" --without-hashes | ||
grep --file=./requirements.txt "$all_requirements_file" > "$backend_requirements_file" | ||
|
||
pip install --requirement="$backend_requirements_file" --target=/asset-output | ||
cp --archive --update --verbose ./endpoints /asset-output/ |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.