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

Commit dfaf088

Browse files
committed
Merge branch 'review-nov22' of github.com:DiamondLightSource/python3-pip-skeleton into review-nov22
2 parents 6ff90e3 + cbd082e commit dfaf088

File tree

6 files changed

+113
-117
lines changed

6 files changed

+113
-117
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
build/
2-
dist/
32
.mypy_cache
43
.tox
54
.venv*

.github/workflows/code.yml

Lines changed: 84 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,29 @@ jobs:
2020
- name: Setup python
2121
uses: actions/setup-python@v4
2222
with:
23-
python-version: "3.10"
23+
python-version: "3.x"
2424

2525
- name: Lint
2626
run: |
27-
touch requirements_dev.txt requirements.txt
28-
pip install -r requirements.txt -r requirements_dev.txt -e .[dev]
27+
touch requirements-lint.txt requirements.txt
28+
pip install -r requirements.txt -r requirements-lint.txt -e .[dev]
2929
tox -e pre-commit,mypy
30+
mkdir -p lockfiles
31+
pip freeze > lockfiles/requirements-lint.txt
32+
33+
- name: Upload lockfiles
34+
uses: actions/upload-artifact@v3
35+
with:
36+
name: lockfiles
37+
path: lockfiles
3038

3139
test:
3240
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
3341
strategy:
3442
fail-fast: false
3543
matrix:
3644
os: ["ubuntu-latest"] # can add windows-latest, macos-latest
37-
python: ["3.8", "3.9", "3.10"]
45+
python: ["3.8", "3.9", "3.10", "3.11"]
3846

3947
runs-on: ${{ matrix.os }}
4048
env:
@@ -58,7 +66,10 @@ jobs:
5866
python-version: ${{ matrix.python }}
5967

6068
- name: Install with latest dependencies
61-
run: pip install .[dev]
69+
run: |
70+
pip install .[dev]
71+
mkdir -p lockfiles
72+
pip freeze > lockfiles/requirements-test-${{ matrix.python }}-${{ matrix.os }}.txt
6273
6374
- name: Run tests
6475
run: pytest tests
@@ -69,18 +80,65 @@ jobs:
6980
name: ${{ matrix.python }}/${{ matrix.os }}
7081
files: cov.xml
7182

72-
container:
83+
- name: Upload lockfiles
84+
uses: actions/upload-artifact@v3
85+
with:
86+
name: lockfiles
87+
path: lockfiles
88+
89+
dist:
7390
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
91+
runs-on: "ubuntu-latest"
92+
93+
steps:
94+
- name: Checkout Source
95+
uses: actions/checkout@v3
96+
with:
97+
fetch-depth: 0
98+
99+
- name: Build Sdist and wheel
100+
run: |
101+
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \
102+
pipx run build
103+
104+
# ${GITHUB_REPOSITORY##*/} is the repo name without org
105+
# Replace this with the cli command if different to the repo name
106+
- name: Test cli works using the wheel installed in local python
107+
run: |
108+
touch requirements.txt
109+
pip install -r requirements.txt dist/*.whl
110+
${GITHUB_REPOSITORY##*/} --version
111+
112+
- name: Test Publish to PyPI
113+
env:
114+
TWINE_USERNAME: __token__
115+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
116+
run: pipx run twine check dist/*
117+
118+
- name: Upload sdist and wheel as artifacts
119+
uses: actions/upload-artifact@v3
120+
with:
121+
name: dist
122+
path: dist
123+
124+
container:
125+
needs: [lint, dist, test]
74126
runs-on: ubuntu-latest
127+
75128
permissions:
76129
contents: read
77130
packages: write
78131

79132
steps:
80133
- name: Checkout
81134
uses: actions/checkout@v3
82-
with:
83-
fetch-depth: 0
135+
136+
# image names must be all lower case
137+
- run: |
138+
echo IMAGE_REPOSITORY=ghcr.io/$(tr '[:upper:]' '[:lower:]' <<< "${{ github.repository }}") >> $GITHUB_ENV
139+
140+
# obtain the python wheel from the dist step
141+
- uses: actions/download-artifact@v3
84142

85143
- name: Log in to GitHub Docker Registry
86144
if: github.event_name != 'pull_request'
@@ -94,75 +152,51 @@ jobs:
94152
id: meta
95153
uses: docker/metadata-action@v4
96154
with:
97-
images: ghcr.io/${{ github.repository }}
155+
images: ${{ env.IMAGE_REPOSITORY }}
98156
tags: |
99-
type=ref,event=branch
100157
type=ref,event=tag
158+
type=raw,value=latest
101159
102160
- name: Set up Docker Buildx
103161
id: buildx
104162
uses: docker/setup-buildx-action@v2
105163

106-
- name: Build developer image for testing
107-
uses: docker/build-push-action@v3
108-
with:
109-
tags: build:latest
110-
context: .
111-
target: build
112-
load: true
113-
114-
- name: Run tests in the container locked with requirements_dev.txt
115-
run: |
116-
docker run --name test build bash /project/.github/workflows/container_tests.sh
117-
docker cp test:/project/dist .
118-
docker cp test:/project/lockfiles .
119-
docker cp test:/project/cov.xml .
120-
121-
- name: Upload coverage to Codecov
122-
uses: codecov/codecov-action@v3
123-
with:
124-
name: 3.10-locked/ubuntu-latest
125-
files: cov.xml
126-
127164
- name: Build runtime image
128165
uses: docker/build-push-action@v3
129166
with:
130-
push: ${{ github.event_name != 'pull_request' }}
167+
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
168+
load: ${{ ! (github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) }}
131169
tags: ${{ steps.meta.outputs.tags }}
132170
context: .
133-
labels: ${{ steps.meta.outputs.labels }}
171+
cache-from: type=gha
172+
cache-to: type=gha,mode=max
134173

135174
- name: Test cli works in runtime image
136-
# check that the first tag can run with --version parameter
137-
run: docker run $(echo ${{ steps.meta.outputs.tags }} | head -1) --version
138-
139-
- name: Test cli works in sdist installed in local python
140-
# ${GITHUB_REPOSITORY##*/} is the repo name without org
141-
# Replace this with the cli command if different to the repo name
142-
# (python3-pip-skeleton-cli replaces this with python3-pip-skeleton)
143-
run: pip install dist/*.gz && python3-pip-skeleton --version
144-
145-
- name: Upload build files
146-
uses: actions/upload-artifact@v3
147-
with:
148-
name: dist
149-
path: dist
175+
# check that the latest tag can run with --version parameter
176+
run: |
177+
docker run ${{ env.IMAGE_REPOSITORY }} --version
178+
mkdir -p lockfiles
179+
docker run --entrypoint pip ${{ env.IMAGE_REPOSITORY }} freeze > lockfiles/requirements.txt
150180
151-
- name: Upload lock files
181+
- name: Upload lockfiles
152182
uses: actions/upload-artifact@v3
153183
with:
154184
name: lockfiles
155185
path: lockfiles
156186

157187
release:
158188
# upload to PyPI and make a release on every tag
159-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
160-
needs: container
189+
needs: [lint, dist, test]
190+
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
161191
runs-on: ubuntu-latest
162192

163193
steps:
164194
- uses: actions/download-artifact@v3
165195

196+
- name: fixup requirements files
197+
# use sed to comment out the self references in requirements files
198+
run: sed -i '/file:/s/^/# Requirements for /' lockfiles/requirements*.txt
199+
166200
- name: Github Release
167201
# We pin to the SHA, not the tag, for security reasons.
168202
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions

.github/workflows/container_tests.sh

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

.github/workflows/linkcheck.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Link Check
22

33
on:
4+
workflow_dispatch:
45
schedule:
56
# Run every Monday at 8am to check URL links still resolve
67
- cron: "0 8 * * WED"
@@ -31,4 +32,4 @@ jobs:
3132
pip install -r requirements_dev.txt -e .[dev]
3233
3334
- name: Check links
34-
run: tox -e docs -- -b linkcheck
35+
run: tox -e docs build -- -b linkcheck

Dockerfile

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,27 @@
33
# The devcontainer should use the build target and run as root with podman
44
# or docker with user namespaces.
55
#
6-
FROM python:3.10 as build
7-
8-
# Add any system dependencies for the developer/build environment here
9-
RUN apt-get update && apt-get upgrade -y && \
10-
apt-get install -y --no-install-recommends \
11-
build-essential \
12-
busybox \
13-
git \
14-
graphviz \
15-
net-tools \
16-
vim \
17-
&& rm -rf /var/lib/apt/lists/* \
18-
&& busybox --install
6+
FROM python:3.11 as build
7+
8+
# Add any system dependencies for the developer/build environment here e.g.
9+
# RUN apt-get update && apt-get upgrade -y && \
10+
# apt-get install -y --no-install-recommends \
11+
# busybox \
12+
# && rm -rf /var/lib/apt/lists/* \
13+
# && busybox --install
1914

2015
COPY . /project
2116
WORKDIR /project
2217

23-
# make the wheel outside of the venv so 'build' does not dirty requirements.txt
24-
RUN pip install --upgrade pip build && \
25-
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \
26-
git diff && \
27-
python -m build && \
28-
touch requirements.txt
29-
3018
# set up a virtual environment and put it in PATH
3119
RUN python -m venv /venv
3220
ENV PATH=/venv/bin:$PATH
33-
ENV TOX_DIRECT=1
34-
35-
# install the wheel and generate the requirements file
36-
RUN pip install --upgrade pip && \
37-
pip install -r requirements.txt dist/*.whl && \
38-
mkdir -p lockfiles && \
39-
pip freeze > lockfiles/requirements.txt && \
40-
# we don't want to include our own wheel in requirements - remove with sed
41-
# and replace with a comment to avoid a zero length asset upload later
42-
sed -i '/file:/s/^/# Requirements for /' lockfiles/requirements.txt
43-
44-
FROM python:3.10-slim as runtime
21+
22+
# install the wheel
23+
RUN touch requirements.txt && \
24+
pip install -r requirements.txt dist/*.whl
25+
26+
FROM python:3.11-slim as runtime
4527

4628
# Add apt-get system dependecies for runtime here if needed
4729

setup.cfg

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,21 @@ source =
106106
# NOTE that we pre-install all tools in the dev dependencies (including tox).
107107
# Hence the use of allowlist_externals instead of using the tox virtualenvs.
108108
# This ensures a match between developer time tools in the IDE and tox tools.
109-
# Setting TOX_DIRECT=1 in the environment will make this even faster
110109
[tox:tox]
111110
skipsdist = True
112111

113-
[testenv:pytest]
114-
allowlist_externals = pytest
115-
commands = pytest {posargs}
116-
117-
[testenv:mypy]
118-
allowlist_externals = mypy
119-
commands = mypy src tests {posargs}
120-
121-
[testenv:pre-commit]
122-
allowlist_externals = pre-commit
123-
commands = pre-commit run --all-files {posargs}
124-
125-
[testenv:docs]
126-
allowlist_externals =
112+
[testenv:{pre-commit,mypy,pytest,docs}]
113+
# Don't create a virtualenv for the command, requires tox-direct plugin
114+
direct = True
115+
passenv = *
116+
allowlist_externals =
117+
pytest
118+
pre-commit
119+
mypy
127120
sphinx-build
128121
sphinx-autobuild
129-
commands = sphinx-{posargs:build -EW --keep-going} -T docs build/html
122+
commands =
123+
pytest: pytest {posargs}
124+
mypy: mypy src tests {posargs}
125+
pre-commit: pre-commit run --all-files {posargs}
126+
docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html

0 commit comments

Comments
 (0)