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

Commit 2902513

Browse files
coretldependabot[bot]
authored andcommitted
Squash commits from dls-python3-skeleton skeleton branch
Tidy up formatting and docs - Use VSCode default formatter for everything - This changes default format for some yaml, json and svgs - Remove some redundant skips for flake8 and isort - Use pkg-name not pkg_name for pip as that is more truthful - Upload wheel in CI before testing it - Note the docstring style in CONTRIBUTING.rst Check links in Docs CI and fix failures Add explanation of =src in setup.cfg Move link checking to its own scheduled workflow Only look for tests in src/ docs/ and tests/ Specify python version when testing cli Enclose author & email in quotes Revert "Enclose author & email in quotes" This reverts commit e10f52b. Bump black dependency As per psf/black#2976 Ignore localhost links for linkcheck This excludes http://localhost from the periodic check for broken links Check links in Docs CI and fix failures Move link checking to its own scheduled workflow Enclose author & email in quotes Revert "Enclose author & email in quotes" This reverts commit e10f52b. master -> main, remove redundant files applying changes for pip based workflow add devcontainer cope with zero length requirements files pass home to tox so git commands work Add dependabot config for actions & pip add all hidden venv to gitignore Bump actions/download-artifact from 2 to 3 (#3) Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 2 to 3. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](actions/download-artifact@v2...v3) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump black from 22.3.0 to 22.6.0 (#4) Bumps [black](https://github.com/psf/black) from 22.3.0 to 22.6.0. - [Release notes](https://github.com/psf/black/releases) - [Changelog](https://github.com/psf/black/blob/main/CHANGES.md) - [Commits](psf/black@22.3.0...22.6.0) --- updated-dependencies: - dependency-name: black dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump actions/setup-python from 2 to 4 (#5) Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2 to 4. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](actions/setup-python@v2...v4) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump docker/login-action from 1 to 2 (#6) Bumps [docker/login-action](https://github.com/docker/login-action) from 1 to 2. - [Release notes](https://github.com/docker/login-action/releases) - [Commits](docker/login-action@v1...v2) --- updated-dependencies: - dependency-name: docker/login-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump actions/upload-artifact from 2 to 3 (#7) Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](actions/upload-artifact@v2...v3) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump docker/setup-buildx-action from 1 to 2 (#8) Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 1 to 2. - [Release notes](https://github.com/docker/setup-buildx-action/releases) - [Commits](docker/setup-buildx-action@v1...v2) --- updated-dependencies: - dependency-name: docker/setup-buildx-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Bump docker/build-push-action from 2 to 3 (#9) Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 2 to 3. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](docker/build-push-action@v2...v3) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent ededf00 commit 2902513

34 files changed

+561
-274
lines changed

.devcontainer/Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ideas from https://www.docker.com/blog/containerized-python-development-part-1/
2+
3+
# This file is for use as a .vscode devcontainer as well as a runtime
4+
# container. The devcontainer should be rootful and use podman or docker
5+
# with user namespaces.
6+
7+
ARG BASE="mcr.microsoft.com/vscode/devcontainers/python:0-3.10-bullseye"
8+
FROM ${BASE} as base
9+
10+
# use root to pin where the packages will install
11+
USER root
12+
ENV PATH=/root/.local/bin:$PATH
13+
14+
FROM base as developer
15+
16+
WORKDIR /workspace
17+
COPY . .
18+
19+
# install runtime from DIST if there is one
20+
RUN mkdir -p /root/.local && \
21+
if [ -d dist ] ; then \
22+
touch requirements.txt && \
23+
pip install --user -r requirements.txt dist/*.whl ; \
24+
fi
25+
26+
FROM base as runtime
27+
28+
COPY --from=developer /root/.local /root/.local
29+
30+
ENTRYPOINT ["python3-pip-skeleton"]
31+
CMD ["--version"]

.devcontainer/devcontainer.json

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.231.6/containers/python-3
3+
{
4+
"name": "Python 3",
5+
"build": {
6+
"dockerfile": "Dockerfile",
7+
"target": "developer",
8+
"context": "..",
9+
"args": {}
10+
},
11+
"remoteEnv": {
12+
"DISPLAY": "${localEnv:DISPLAY}"
13+
},
14+
// Set *default* container specific settings.json values on container create.
15+
"settings": {
16+
"python.defaultInterpreterPath": "/usr/local/bin/python",
17+
"python.linting.enabled": true,
18+
"python.linting.pylintEnabled": true,
19+
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
20+
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
21+
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
22+
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
23+
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
24+
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
25+
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
26+
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
27+
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
28+
},
29+
// Add the IDs of extensions you want installed when the container is created.
30+
"extensions": [
31+
"ms-python.python",
32+
"ms-python.vscode-pylance",
33+
"streetsidesoftware.code-spell-checker",
34+
"ryanluker.vscode-coverage-gutters",
35+
"mhutchie.git-graph",
36+
"eamodio.gitlens",
37+
"gruntfuggly.todo-tree",
38+
"redhat.vscode-yaml",
39+
"nsd.vscode-epics",
40+
"alefragnani.bookmarks"
41+
],
42+
"features": {
43+
//"docker-from-docker": "20.10",
44+
"git": "os-provided"
45+
},
46+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
47+
// "forwardPorts": [],
48+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
49+
// "remoteUser": "vscode",
50+
// Make sure the files we are mapping into the container exist on the host
51+
"initializeCommand": "bash -c 'for i in $HOME/.inputrc $HOME/.bashrc_dev; do [ -f $i ] || touch $i; done'",
52+
"runArgs": [
53+
"--privileged",
54+
"--net=host",
55+
"-v=${localEnv:HOME}/.ssh:/root/.ssh",
56+
"-v=${localEnv:HOME}/.bashrc_dev:/root/.bashrc",
57+
"-v=${localEnv:HOME}/.inputrc:/root/.inputrc"
58+
],
59+
"mounts": [
60+
// map in home directory - not strictly necessary but may be useful
61+
"source=${localEnv:HOME},target=${localEnv:HOME},type=bind,consistency=cached"
62+
],
63+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind",
64+
"workspaceFolder": "/workspace",
65+
// After the container is created, install the python project in editable form
66+
// This installs into the system python of the container
67+
"postCreateCommand": "pip install $([ -f requirements_dev.txt ] && echo -r requirements_dev.txt ) -e .[dev]"
68+
}

.devcontainer/local_build.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# locally build a runtime container for testing
2+
3+
# first make sure a wheel is built
4+
(
5+
cd ..
6+
pip install build
7+
rm -r dist
8+
python -m build --wheel
9+
)
10+
11+
# make the container name the same as the root folder name of this clone
12+
container_name=$(cd ..; basename $(realpath .))
13+
echo building $container_name ...
14+
15+
# run the build with required build-args for a runtime build
16+
ln -s ../dist .
17+
podman build --build-arg BASE=python:3.10-slim --build-arg ENTRYPOINT=$container_name -t $container_name .. --file ./Dockerfile
18+
unlink dist

.github/dependabot.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"
12+
13+
- package-ecosystem: "pip"
14+
directory: "/"
15+
schedule:
16+
interval: "weekly"

.github/pages/index.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
4-
<title>Redirecting to master branch</title>
3+
4+
<head>
5+
<title>Redirecting to main branch</title>
56
<meta charset="utf-8">
6-
<meta http-equiv="refresh" content="0; url=./master/index.html">
7-
<link rel="canonical" href="master/index.html">
8-
</head>
9-
</html>
7+
<meta http-equiv="refresh" content="0; url=./main/index.html">
8+
<link rel="canonical" href="main/index.html">
9+
</head>
10+
11+
</html>

.github/workflows/code.yml

Lines changed: 139 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,94 +13,140 @@ on:
1313
pull_request:
1414
schedule:
1515
# Run every Monday at 8am to check latest versions of dependencies
16-
- cron: '0 8 * * MON'
16+
- cron: "0 8 * * MON"
1717

1818
jobs:
1919
lint:
2020
runs-on: "ubuntu-latest"
2121
steps:
22-
- name: Run black, flake8, mypy
23-
uses: dls-controls/pipenv-run-action@v1
24-
with:
25-
pipenv-run: lint
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Lint
26+
run: |
27+
pip install --user .[dev]
28+
tox -e pre-commit,mypy
2629
2730
wheel:
28-
runs-on: "ubuntu-latest"
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
os: ["ubuntu-latest"]
35+
python: ["3.8"]
36+
37+
runs-on: ${{ matrix.os }}
2938
steps:
3039
- uses: actions/checkout@v2
31-
with:
32-
fetch-depth: 0
3340

3441
- name: Create Sdist and Wheel
3542
# Set SOURCE_DATE_EPOCH from git commit for reproducible build
3643
# https://reproducible-builds.org/
37-
# Set group writable and umask to do the same to match inside DLS
3844
run: |
39-
chmod -R g+w .
40-
umask 0002
4145
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) pipx run build --sdist --wheel
4246
43-
- name: Test cli works from the installed wheel
44-
# Can remove the repository reference after https://github.com/pypa/pipx/pull/733
45-
run: pipx run --spec dist/*.whl ${GITHUB_REPOSITORY##*/} --version
46-
4747
- name: Upload Wheel and Sdist as artifacts
48-
uses: actions/upload-artifact@v2
48+
uses: actions/upload-artifact@v3
4949
with:
5050
name: dist
51-
path: dist/*
51+
path: dist
52+
53+
- name: Install minimum python version
54+
uses: actions/setup-python@v4
55+
with:
56+
python-version: ${{ matrix.python }}
57+
58+
- name: Install wheel in a venv and check cli works
59+
# ${GITHUB_REPOSITORY##*/} is the repo name without org
60+
# Replace this with the cli command if different to the repo name
61+
run: pipx run --python $(which python${{ matrix.python }}) --spec dist/*.whl ${GITHUB_REPOSITORY##*/} --version
5262

5363
test:
5464
strategy:
5565
fail-fast: false
5666
matrix:
57-
os: ["ubuntu-latest"] # can add windows-latest, macos-latest
58-
python: ["3.7", "3.8", "3.9"]
59-
pipenv: ["skip-lock"]
67+
os: ["ubuntu-latest"] # can add windows-latest, macos-latest
68+
python: ["3.8", "3.9", "3.10"]
69+
lock: [false]
6070

6171
include:
62-
# Add an extra Python3.7 runner to use the lockfile
72+
# Add an extra Python3.10 runner to use the lockfile
6373
- os: "ubuntu-latest"
64-
python: "3.7"
65-
pipenv: "deploy"
74+
python: "3.10"
75+
lock: true
6676

6777
runs-on: ${{ matrix.os }}
6878
env:
6979
# https://github.com/pytest-dev/pytest/issues/2042
7080
PY_IGNORE_IMPORTMISMATCH: "1"
81+
# enable QT tests with no X Display
82+
QT_QPA_PLATFORM: "offscreen"
7183

7284
steps:
73-
- name: Setup repo and test
74-
uses: dls-controls/pipenv-run-action@v1
85+
- name: Checkout
86+
uses: actions/checkout@v2
87+
with:
88+
fetch-depth: 0
89+
90+
- name: Setup python ${{ matrix.python }}
91+
uses: actions/setup-python@v4
7592
with:
7693
python-version: ${{ matrix.python }}
77-
pipenv-install: --dev --${{ matrix.pipenv }}
78-
allow-editable-installs: ${{ matrix.pipenv == 'deploy' }}
79-
pipenv-run: tests
94+
95+
- name: Install with locked dependencies
96+
if: matrix.lock
97+
run: |
98+
echo '# runtime dependencies' > requirements.txt
99+
echo '# developer dependencies' > requirements_dev.txt
100+
# above avoids zero length requirements files
101+
pip install -r requirements.txt -e .
102+
pip freeze --exclude-editable >> requirements.txt
103+
pip install -r requirements_dev.txt -e .[dev]
104+
pip freeze --exclude-editable >> requirements_dev.txt
105+
106+
- name: Install with latest dependencies
107+
if: ${{ ! matrix.lock }}
108+
run: pip install -e .[dev]
109+
110+
- name: Run tests
111+
run: pytest tests
112+
113+
- name: Create requirements_dev.txt
114+
run: |
115+
pip freeze --exclude-editable > requirements_dev.txt
80116
81117
- name: Upload coverage to Codecov
82118
uses: codecov/codecov-action@v2
83119
with:
84-
name: ${{ matrix.python }}/${{ matrix.os }}/${{ matrix.pipenv }}
120+
name: ${{ matrix.python }}/${{ matrix.os }}/${{ matrix.lock }}
85121
files: cov.xml
86122

123+
- name: Upload build files
124+
if: matrix.lock
125+
uses: actions/upload-artifact@v3
126+
with:
127+
name: buildfiles
128+
path: |
129+
requirements.txt
130+
requirements_dev.txt
131+
87132
release:
88133
needs: [lint, wheel, test]
89134
runs-on: ubuntu-latest
90135
# upload to PyPI and make a release on every tag
91136
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
92137
steps:
93-
- uses: actions/download-artifact@v2
138+
- uses: actions/download-artifact@v3
94139
with:
95-
name: dist
96-
path: dist
140+
path: artifacts
97141

98142
- name: Github Release
99143
# We pin to the SHA, not the tag, for security reasons.
100144
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
101-
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
145+
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
102146
with:
103-
files: dist/*
147+
files: |
148+
artifacts/dist/*
149+
artifacts/buildfiles/*
104150
generate_release_notes: true
105151
env:
106152
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -109,4 +155,62 @@ jobs:
109155
env:
110156
TWINE_USERNAME: __token__
111157
TWINE_PASSWORD: ${{ secrets.pypi_token }}
112-
run: pipx run twine upload dist/*
158+
run: pipx run twine upload artifacts/dist/*
159+
160+
make-container:
161+
needs: [lint, wheel, test]
162+
runs-on: ubuntu-latest
163+
permissions:
164+
contents: read
165+
packages: write
166+
167+
steps:
168+
- name: Checkout
169+
uses: actions/checkout@v2
170+
171+
- uses: actions/download-artifact@v3
172+
with:
173+
name: dist
174+
path: dist
175+
176+
- name: Cache Docker layers
177+
uses: actions/cache@v2
178+
with:
179+
path: /tmp/.buildx-cache
180+
key: ${{ runner.os }}-buildx-${{ github.sha }}
181+
restore-keys: |
182+
${{ runner.os }}-buildx-
183+
184+
- name: Log in to GitHub Docker Registry
185+
if: github.event_name != 'pull_request'
186+
uses: docker/login-action@v2
187+
with:
188+
registry: ghcr.io
189+
username: ${{ github.actor }}
190+
password: ${{ secrets.GITHUB_TOKEN }}
191+
192+
- name: Docker meta
193+
id: meta
194+
uses: docker/metadata-action@v4
195+
with:
196+
images: ghcr.io/${{ github.repository }}
197+
tags: |
198+
type=ref,event=branch
199+
type=ref,event=tag
200+
type=raw,value=latest
201+
202+
- name: Set up Docker Buildx
203+
id: buildx
204+
uses: docker/setup-buildx-action@v2
205+
206+
- name: Build runtime image
207+
uses: docker/build-push-action@v3
208+
with:
209+
file: .devcontainer/Dockerfile
210+
context: .
211+
push: ${{ github.event_name != 'pull_request' }}
212+
build-args: BASE=python:3.10-slim
213+
tags: ${{ steps.meta.outputs.tags }}
214+
labels: ${{ steps.meta.outputs.labels }}
215+
cache-from: type=local,src=/tmp/.buildx-cache
216+
cache-to: type=local,dest=/tmp/.buildx-cache

0 commit comments

Comments
 (0)