Skip to content

Commit 86b42bd

Browse files
authored
Merge pull request #71 from octue/python-range
Widen supported django and python ranges, update developer tools
2 parents 9008a37 + 6fa5367 commit 86b42bd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1709
-1530
lines changed

.devcontainer/devcontainer.json

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,28 @@
1212
"vscode": {
1313
"settings": {
1414
"[python]": {
15-
"editor.defaultFormatter": "ms-python.black-formatter",
1615
"editor.formatOnSave": true,
1716
"editor.codeActionsOnSave": {
1817
"source.organizeImports": "always",
1918
"source.fixAll": "always"
20-
}
19+
},
20+
"editor.defaultFormatter": "charliermarsh.ruff"
2121
},
22-
"black-formatter.args": ["--line-length", "120"],
23-
"black-formatter.importStrategy": "fromEnvironment",
24-
"isort.args": ["--profile", "black"],
25-
"isort.importStrategy": "fromEnvironment",
2622
"austin.mode": "Wall time",
2723
"editor.defaultFormatter": "esbenp.prettier-vscode",
2824
"editor.formatOnSave": true,
29-
"jupyter.widgetScriptSources": ["jsdelivr.com", "unpkg.com"],
30-
// Line length to match black settings
31-
// Disable specific messages:
32-
// - To find the details do: /usr/local/py-utils/bin/pylint --list-msgs
33-
// - Disable missing-module-docstring (C0114) because we don't document modules routinely, just their members
34-
// - Disable invalid-name (C0103) because pylint thinks that eg 'x', 'df', 'np' are invalid due to their lengths
35-
"pylint.args": [
36-
"--max-line-length=120",
37-
"--disable=missing-module-docstring,invalid-name",
38-
"--load-plugins=pylint_django"
39-
],
25+
"python.locator": "native",
4026
"python.testing.pytestEnabled": true,
4127
"python.testing.unittestEnabled": false,
4228
"terminal.integrated.defaultProfile.linux": "zsh",
43-
// Handle this: https://github.com/microsoft/vscode-python/issues/693
44-
"python.testing.pytestArgs": ["--no-cov"]
29+
"ruff.format.args": ["--line-length", "120"],
30+
"ruff.importStrategy": "fromEnvironment"
4531
},
46-
// Add the IDs of extensions you want installed when the container is created.
32+
33+
// IN ALPHABETIC ORDER: Add the IDs of extensions you want installed when the container is created.
4734
"extensions": [
35+
"4ops.terraform",
36+
"charliermarsh.ruff",
4837
"erikphansen.vscode-toggle-column-selection",
4938
"esbenp.prettier-vscode",
5039
"GitHub.copilot",
@@ -53,20 +42,11 @@
5342
"irongeek.vscode-env",
5443
"ms-python.python",
5544
"ms-python.vscode-pylance",
56-
"ms-python.pylint",
57-
"ms-python.black-formatter",
58-
"ms-python.flake8",
59-
"ms-python.isort",
60-
"ms-toolsai.jupyter",
61-
"ms-toolsai.jupyter-renderers",
62-
"ms-toolsai.jupyter-keymap",
6345
"ms-vsliveshare.vsliveshare",
46+
"ninoseki.vscode-mogami",
6447
"p403n1x87.austin-vscode",
6548
"ritwickdey.liveserver",
66-
"shamanu4.django-intellisense",
67-
"thebarkman.vscode-djaneiro",
68-
"trond-snekvik.simple-rst",
69-
"4ops.terraform"
49+
"tamasfe.even-better-toml"
7050
]
7151
}
7252
},

.devcontainer/postattach.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/zsh
22

3-
# Install dependencies
3+
4+
# Install dependencies to a cache that persists across devcontainer builds
5+
poetry config cache-dir /workspace/.poetry_cache
46
poetry install
57

68
# Auto set up remote when pushing new branches
@@ -33,4 +35,5 @@ echo 'alias djm="python manage.py migrate"' >> ~/.zshrc
3335
echo 'alias djr="python manage.py runserver"' >> ~/.zshrc
3436
echo 'alias djreset="python manage.py reset_db -c"' >> ~/.zshrc
3537
echo 'alias djs="python manage.py shell_plus"' >> ~/.zshrc
38+
echo 'alias djt="pytest backend/test"' >> ~/.zshrc
3639
echo 'alias dju="python manage.py show_urls"' >> ~/.zshrc

.github/workflows/cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99

1010
jobs:
1111
release:
12-
if: "${{ github.event.pull_request.merged == true }}"
12+
if: '${{ github.event.pull_request.merged == true }}'
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout repository

.github/workflows/ci.yml

Lines changed: 154 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,108 @@ on:
2424

2525
jobs:
2626
check-semantic-version:
27-
if: github.event.pull_request.draft == false
27+
if: github.ref != 'refs/heads/main'
2828
uses: octue/workflows/.github/workflows/check-semantic-version.yml@main
2929
with:
3030
path: pyproject.toml
3131
breaking_change_indicated_by: minor
3232

33-
run-tests:
33+
check-ahead-of-main:
34+
if: github.ref != 'refs/heads/main'
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Check branch is ahead of main
43+
run: |
44+
if ! git merge-base --is-ancestor origin/main ${{ github.event.pull_request.head.sha }};
45+
then echo "::error::This branch is not up-to-date with the latest main branch commit.";
46+
exit 1; fi
47+
48+
lint:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v4
53+
54+
- name: Setup python
55+
uses: actions/setup-python@v5
56+
with:
57+
python-version: '3.11'
58+
59+
- name: Install and configure poetry
60+
uses: snok/install-poetry@v1
61+
with:
62+
virtualenvs-create: true
63+
virtualenvs-in-project: true
64+
65+
- name: Setup virtual environment cache
66+
id: cached-poetry-dependencies
67+
uses: actions/cache@v4
68+
with:
69+
path: .venv
70+
key: venv-${{ runner.os }}-3.11-${{ hashFiles('**/poetry.lock') }}
71+
72+
- name: Install dependencies (if not cached)
73+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
74+
run: poetry install --only dev --no-interaction --no-root
75+
76+
- name: Install root project
77+
run: poetry install --no-interaction
78+
79+
- name: Run precommit
80+
run: SKIP=build-docs,check-branch-name poetry run pre-commit run --all-files
81+
82+
publish-test:
83+
runs-on: ubuntu-latest
84+
needs:
85+
- lint
86+
- check-ahead-of-main
87+
- check-semantic-version
88+
permissions:
89+
id-token: write
90+
contents: read
91+
steps:
92+
- name: Checkout repository
93+
uses: actions/checkout@v4
94+
95+
- name: Install poetry
96+
uses: snok/[email protected]
97+
98+
- name: Build a binary wheel and a source tarball
99+
run: poetry build
100+
101+
- name: Test package is publishable with PyPI test server
102+
uses: pypa/[email protected]
103+
with:
104+
repository-url: https://test.pypi.org/legacy/
105+
skip-existing: true
106+
verbose: true
107+
108+
test:
34109
if: github.event.pull_request.draft == false
110+
needs:
111+
- lint
112+
- check-ahead-of-main
113+
- check-semantic-version
35114
strategy:
36-
fail-fast: true
115+
fail-fast: false
37116
matrix:
38-
python: ['3.9', '3.10', '3.11']
39-
os: [ubuntu-latest] # [ubuntu-latest, windows-latest, macos-latest] for full coverage but this gets expensive quickly
40-
runs-on: ${{ matrix.os }}
117+
python-version: ['3.9', '3.10', '3.11', '3.12']
118+
django-version: ['>=4.2,<4.3', '>=5.0,<5.1']
119+
database-engine: ['sqlite', 'postgres']
120+
121+
exclude:
122+
# Exclude Django 5 with Python 3.9
123+
- python-version: '3.9'
124+
django-version: '>=5.0,<5.1'
125+
126+
permissions:
127+
id-token: write
128+
contents: read
41129

42130
services:
43131
postgres:
@@ -55,63 +143,85 @@ jobs:
55143
--health-timeout 5s
56144
--health-retries 5
57145
146+
runs-on: 'ubuntu-latest'
147+
148+
env:
149+
DJANGO_SETTINGS_MODULE: tests.server.settings
150+
DATABASE_ENGINE: ${{ matrix.database-engine }}
151+
58152
steps:
59-
- name: Checkout repository
153+
- name: Check out repository
60154
uses: actions/checkout@v4
61155

62-
- name: Setup python ${{ matrix.python }}
156+
- name: Prepare Integration Test Credentials
157+
# Workload Identity Federation works great for using the GCloud API, but the credentials required by
158+
# the storages client in integration tests don't like it; they need a private key to sign blobs.
159+
# So until the credentials APIs are sensibly applied across the google client libraries, we inject
160+
# a private service account key (against recommended practice, but this is the only thing that works).
161+
id: application-credentials
162+
run: |
163+
echo '${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }}' > $(pwd)/gha-creds-github-actions.json
164+
echo "GOOGLE_APPLICATION_CREDENTIALS=$(pwd)/gha-creds-github-actions.json" >> $GITHUB_ENV
165+
166+
# - name: Authenticate with GCP Workload Identity
167+
# id: auth
168+
# uses: google-github-actions/auth@v2
169+
# with:
170+
# # NOTE: If setting create_credentials_file=true when building docker images,
171+
# # a .dockerignore file must be present and include `gha-creds-*.json` to
172+
# # avoid baking these credentials into the container
173+
# create_credentials_file: true
174+
# workload_identity_provider: projects/134056372703/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
175+
# service_account: [email protected]
176+
177+
# - name: Setup gcloud
178+
# uses: 'google-github-actions/setup-gcloud@v2'
179+
180+
- name: Set up python ${{ matrix.python-version }}
181+
id: setup-python
63182
uses: actions/setup-python@v5
64183
with:
65-
python-version: ${{ matrix.python }}
184+
python-version: ${{ matrix.python-version }}
66185

67-
# See the repo of this action for way more advanced caching strategies than used here
68-
- name: Install poetry
69-
uses: snok/[email protected]
186+
- name: Install Poetry
187+
uses: snok/install-poetry@v1
188+
with:
189+
virtualenvs-create: true
190+
virtualenvs-in-project: true
70191

71-
# For more advanced configuration see https://github.com/ymyzk/tox-gh-actions
72-
- name: Install tox and plugins
192+
- name: Setup virtual environment cache
193+
id: cached-poetry-dependencies
194+
uses: actions/cache@v4
195+
with:
196+
path: .venv
197+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
198+
199+
- name: Install dependencies (if not cached)
200+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
201+
run: poetry install --no-interaction --no-root
202+
203+
- name: Install root project
204+
run: poetry install --no-interaction
205+
206+
- name: Install django ${{ matrix.django-version }}
73207
run: |
74-
python -m pip install --upgrade pip
75-
python -m pip install tox==3.24.5 tox-gh-actions==2.9.1 tox-poetry==0.4.1
208+
source .venv/bin/activate
209+
pip install "django${{ matrix.django-version }}"
76210
77211
- name: Setup tmate session [DEBUG]
78212
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true'}}
79213
uses: mxschmitt/action-tmate@v3
80214

81-
# For more advanced configuration see https://github.com/ymyzk/tox-gh-actions
82-
- name: Run tests using tox
83-
run: tox
215+
- name: Run tests
216+
run: poetry run pytest --cov=django_gcp --cov-report=xml
84217

85218
- name: Upload coverage to Codecov
86219
# This seems redundant inside the test matrix but actually isn't, since different
87220
# dependency combinations may cause different lines of code to be hit (e.g. backports)
88-
uses: codecov/codecov-action@v3
221+
uses: codecov/codecov-action@v4
89222
with:
90223
files: coverage.xml
91224
fail_ci_if_error: false
92-
# Token is not required for public repos, but see:
225+
# Token is not strictly required for public repos, but see:
93226
# https://community.codecov.com/t/upload-issues-unable-to-locate-build-via-github-actions-api/3954
94227
token: ${{ secrets.CODECOV_TOKEN }}
95-
96-
test-publish:
97-
runs-on: ubuntu-latest
98-
needs: run-tests
99-
permissions:
100-
id-token: write
101-
contents: read
102-
steps:
103-
- name: Checkout repository
104-
uses: actions/checkout@v4
105-
106-
- name: Install poetry
107-
uses: snok/[email protected]
108-
109-
- name: Build a binary wheel and a source tarball
110-
run: poetry build
111-
112-
- name: Test package is publishable with PyPI test server
113-
uses: pypa/[email protected]
114-
with:
115-
repository-url: https://test.pypi.org/legacy/
116-
skip-existing: true
117-
verbose: true

0 commit comments

Comments
 (0)