Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit 187a4b2

Browse files
committed
Tidy up
1 parent 672408c commit 187a4b2

File tree

9 files changed

+68
-98
lines changed

9 files changed

+68
-98
lines changed

.devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
"workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind",
3636
"workspaceFolder": "${localWorkspaceFolder}",
3737
// After the container is created, install the python project in editable form
38-
"postCreateCommand": "pip install $([ -f requirements_dev.txt ] && echo -r requirements_dev.txt ) -e .[dev]"
38+
"postCreateCommand": "pip install -e .[dev]"
3939
}

.dockerignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/actions/install_requirements/action.yml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,58 @@
1-
name: "install requirements"
2-
description: "run pip install with requirements and upload resulting requirements"
1+
name: Install requirements
2+
description: Run pip install with requirements and upload resulting requirements
33
inputs:
44
requirements_file:
5-
description: "name of requirements file to use and upload"
5+
description: Name of requirements file to use and upload
66
required: true
77
install_options:
8-
description: "parameters to pass to pip install"
8+
description: Parameters to pass to pip install
99
required: true
1010
python_version:
11-
description: "python version to install"
11+
description: Python version to install
1212
default: "3.x"
1313

1414
runs:
15-
using: "composite"
15+
using: composite
1616

1717
steps:
1818
- name: Setup python
1919
uses: actions/setup-python@v4
2020
with:
2121
python-version: ${{ inputs.python_version }}
2222

23-
- name: Pip Install
23+
- name: Pip install
2424
run: |
2525
touch ${{ inputs.requirements_file }}
2626
# -c uses requirements.txt as constraints, see 'Validate requirements file'
2727
pip install -c ${{ inputs.requirements_file }} ${{ inputs.install_options }}
2828
shell: bash
2929

30-
- name: Create Lockfile
30+
- name: Create lockfile
3131
run: |
3232
mkdir -p lockfiles
3333
pip freeze --exclude-editable > lockfiles/${{ inputs.requirements_file }}
3434
# delete the self referencing line
35-
sed -i '/file:/d' lockfiles/${{ inputs.requirements_file }}
35+
sed -i '/file:/d' lockfiles/${{ inputs.requirements_file }}
3636
shell: bash
3737

38+
- name: Upload lockfiles
39+
uses: actions/upload-artifact@v3
40+
with:
41+
name: lockfiles
42+
path: lockfiles
43+
3844
# This eliminates the class of problems where the requirements being given no
3945
# longer match what the packages themselves dictate. E.g. In the rare instance
4046
# where I install some-package which used to depend on vulnerable-dependency
4147
# but now uses good-dependency (despite being nominally the same version)
4248
# pip will install both if given a requirements file with -r
43-
- name: Validate requirements file
44-
run: if [ -s ${{ inputs.requirements_file }} ] ; then
45-
diff ${{ inputs.requirements_file }} lockfiles/${{ inputs.requirements_file }};
46-
echo "requirements files match";
49+
- name: If requirements file exists, check it matches pip installed packages
50+
run: |
51+
if [ -s ${{ inputs.requirements_file }} ]; then
52+
if ! diff -u ${{ inputs.requirements_file }} lockfiles/${{ inputs.requirements_file }}; then
53+
echo "Error: ${{ inputs.requirements_file }} need the above changes to be exhaustive"
54+
exit 1
55+
fi
4756
fi
4857
shell: bash
4958

50-
- name: Upload lockfiles
51-
uses: actions/upload-artifact@v3
52-
with:
53-
name: lockfiles
54-
path: lockfiles

.github/workflows/code.yml

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@v3
1919

20-
- name: Install
20+
- name: Install python packages
2121
uses: ./.github/actions/install_requirements
2222
with:
2323
requirements_file: requirements-lint.txt
@@ -26,12 +26,6 @@ jobs:
2626
- name: Lint
2727
run: tox -e pre-commit,mypy
2828

29-
- name: Upload lockfiles
30-
uses: actions/upload-artifact@v3
31-
with:
32-
name: lockfiles
33-
path: lockfiles
34-
3529
test:
3630
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
3731
strategy:
@@ -55,17 +49,18 @@ jobs:
5549
- name: Checkout
5650
uses: actions/checkout@v3
5751
with:
52+
# Need this to get version number from last tag
5853
fetch-depth: 0
5954

60-
- name: Install
55+
- name: Install python packages
6156
uses: ./.github/actions/install_requirements
6257
with:
6358
python_version: ${{ matrix.python }}
6459
requirements_file: requirements-test-${{ matrix.os }}-${{ matrix.python }}.txt
6560
install_options: ${{ matrix.install }}
6661

6762
- name: Run tests
68-
run: pytest tests
63+
run: pytest
6964

7065
- name: Upload coverage to Codecov
7166
uses: codecov/codecov-action@v3
@@ -78,32 +73,39 @@ jobs:
7873
runs-on: "ubuntu-latest"
7974

8075
steps:
81-
- name: Checkout Source
76+
- name: Checkout
8277
uses: actions/checkout@v3
8378
with:
79+
# Need this to get version number from last tag
8480
fetch-depth: 0
8581

86-
- name: Build Sdist and wheel
82+
- name: Build sdist and wheel
8783
run: |
8884
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \
8985
pipx run build
9086
91-
- name: Test module --version works using the installed wheel
92-
run: |
93-
touch requirements.txt
94-
pip install -r requirements.txt dist/*.whl
95-
# If more than one module in src/ replace with module name to test
96-
python -m $(ls src | head -1) --version
97-
98-
- name: Check for packaging errors
99-
run: pipx run twine check dist/*
100-
10187
- name: Upload sdist and wheel as artifacts
10288
uses: actions/upload-artifact@v3
10389
with:
10490
name: dist
10591
path: dist
10692

93+
- name: Check for packaging errors
94+
run: pipx run twine check dist/*
95+
96+
- name: Install python packages
97+
uses: ./.github/actions/install_requirements
98+
with:
99+
# Must match dockerfile
100+
python_version: "3.11"
101+
requirements_file: requirements.txt
102+
install_options: dist/*.whl
103+
104+
- name: Test module --version works using the installed wheel
105+
run: |
106+
# If more than one module in src/ replace with module name to test
107+
python -m $(ls src | head -1) --version
108+
107109
container:
108110
needs: [lint, dist, test]
109111
runs-on: ubuntu-latest
@@ -120,8 +122,8 @@ jobs:
120122
- name: Generate image repo name
121123
run: echo IMAGE_REPOSITORY=ghcr.io/$(tr '[:upper:]' '[:lower:]' <<< "${{ github.repository }}") >> $GITHUB_ENV
122124

123-
# obtain the python wheel from the dist step
124-
- uses: actions/download-artifact@v3
125+
- name: Download wheel and lockfiles
126+
uses: actions/download-artifact@v3
125127

126128
- name: Log in to GitHub Docker Registry
127129
if: github.event_name != 'pull_request'
@@ -155,17 +157,7 @@ jobs:
155157
cache-to: type=gha,mode=max
156158

157159
- name: Test cli works in runtime image
158-
run: |
159-
docker run ${{ env.IMAGE_REPOSITORY }} --version
160-
mkdir -p lockfiles
161-
docker run --entrypoint pip ${{ env.IMAGE_REPOSITORY }} freeze | \
162-
sed '/file:/s/^/# Requirements for /' > lockfiles/requirements.txt
163-
164-
- name: Upload lockfiles
165-
uses: actions/upload-artifact@v3
166-
with:
167-
name: lockfiles
168-
path: lockfiles
160+
run: docker run ${{ env.IMAGE_REPOSITORY }} --version
169161

170162
release:
171163
# upload to PyPI and make a release on every tag
@@ -176,6 +168,10 @@ jobs:
176168
steps:
177169
- uses: actions/download-artifact@v3
178170

171+
- name: Fixup blank lockfiles
172+
# Github release artifacts can't be blank
173+
run: for f in lockfiles/*; [ -s $f ] || echo '# No requirements' >> $f; done
174+
179175
- name: Github Release
180176
# We pin to the SHA, not the tag, for security reasons.
181177
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions

.github/workflows/docs.yml

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,28 @@ on:
77
jobs:
88
docs:
99
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
10-
strategy:
11-
fail-fast: false
12-
matrix:
13-
python: ["3.10"]
14-
1510
runs-on: ubuntu-latest
1611

1712
steps:
1813
- name: Avoid git conflicts when tag and branch pushed at same time
1914
if: startsWith(github.ref, 'refs/tags')
2015
run: sleep 60
2116

22-
- name: Install python version
23-
uses: actions/setup-python@v4
17+
- name: Checkout
18+
uses: actions/checkout@v3
2419
with:
25-
python-version: ${{ matrix.python }}
20+
# Need this to get version number from last tag
21+
fetch-depth: 0
2622

27-
- name: Install Packages
23+
- name: Install system packages
2824
# Can delete this if you don't use graphviz in your docs
2925
run: sudo apt-get install graphviz
3026

31-
- name: checkout
32-
uses: actions/checkout@v3
27+
- name: Install python packages
28+
uses: ./.github/actions/install_requirements
3329
with:
34-
fetch-depth: 0
35-
36-
- name: Install dependencies
37-
run: |
38-
touch requirements_dev.txt
39-
pip install -r requirements_dev.txt -e .[dev]
30+
requirements_file: requirements-docs.txt
31+
install_options: -e .[dev]
4032

4133
- name: Build docs
4234
run: tox -e docs

.github/workflows/docs_clean.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818

1919
steps:
20-
- name: checkout
20+
- name: Checkout
2121
uses: actions/checkout@v3
2222
with:
2323
ref: gh-pages
@@ -35,7 +35,7 @@ jobs:
3535

3636
- name: update index and push changes
3737
run: |
38-
rm -r ${{ env.DOCS_VERSION }}
38+
rm -r $DOCS_VERSION
3939
python make_switcher.py --remove $DOCS_VERSION ${{ github.repository }} switcher.json
4040
git config --global user.name 'GitHub Actions Docs Cleanup CI'
4141
git config --global user.email '[email protected]'

.github/workflows/pip_install.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ FROM python:3.11 as build
1111
# desired-packages \
1212
# && rm -rf /var/lib/apt/lists/*
1313

14-
COPY . /project
14+
COPY dist /project/dist
15+
COPY lockfiles /project/lockfiles
1516
WORKDIR /project
1617

1718
# set up a virtual environment and put it in PATH
1819
RUN python -m venv /venv
1920
ENV PATH=/venv/bin:$PATH
2021

2122
# install the wheel
22-
RUN touch requirements.txt && \
23-
pip install -r requirements.txt dist/*.whl
23+
RUN pip install -r lockfiles/requirements.txt dist/*.whl
2424

2525
FROM python:3.11-slim as runtime
2626

setup.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ classifiers =
1212
Programming Language :: Python :: 3.8
1313
Programming Language :: Python :: 3.9
1414
Programming Language :: Python :: 3.10
15+
Programming Language :: Python :: 3.11
1516

1617
[options]
1718
python_requires = >=3.8
@@ -50,8 +51,6 @@ dev =
5051

5152
[options.packages.find]
5253
where = src
53-
# Don't include our tests directory in the distribution
54-
exclude = tests
5554

5655
# Specify any package data to be included in the wheel below.
5756
# [options.package_data]

0 commit comments

Comments
 (0)