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

Commit 07569f3

Browse files
committed
merge switch to pip workflow from skeleton branch
1 parent ffa7044 commit 07569f3

File tree

25 files changed

+470
-259
lines changed

25 files changed

+470
-259
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/pages/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<html>
33

44
<head>
5-
<title>Redirecting to master branch</title>
6-
<meta charset="utf-8">
7-
<meta http-equiv="refresh" content="0; url=./master/index.html">
8-
<link rel="canonical" href="master/index.html">
5+
<title>Redirecting to main branch</title>
6+
<meta charset="utf-8">
7+
<meta http-equiv="refresh" content="0; url=./main/index.html">
8+
<link rel="canonical" href="main/index.html">
99
</head>
1010

1111
</html>

.github/workflows/code.yml

Lines changed: 115 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,36 @@ 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:
2831
strategy:
2932
fail-fast: false
3033
matrix:
3134
os: ["ubuntu-latest"]
32-
python: ["3.7"]
35+
python: ["3.8"]
3336

3437
runs-on: ${{ matrix.os }}
3538
steps:
3639
- uses: actions/checkout@v2
37-
with:
38-
fetch-depth: 0
3940

4041
- name: Create Sdist and Wheel
4142
# Set SOURCE_DATE_EPOCH from git commit for reproducible build
4243
# https://reproducible-builds.org/
43-
# Set group writable and umask to do the same to match inside DLS
4444
run: |
45-
chmod -R g+w .
46-
umask 0002
4745
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) pipx run build --sdist --wheel
4846
4947
- name: Upload Wheel and Sdist as artifacts
5048
uses: actions/upload-artifact@v2
5149
with:
5250
name: dist
53-
path: dist/*
51+
path: dist
5452

5553
- name: Install minimum python version
5654
uses: actions/setup-python@v2
@@ -67,40 +65,68 @@ jobs:
6765
fail-fast: false
6866
matrix:
6967
os: ["ubuntu-latest"] # can add windows-latest, macos-latest
70-
python: ["3.7", "3.8", "3.9"]
71-
pipenv: ["skip-lock"]
68+
python: ["3.8", "3.9", "3.10"]
69+
lock: [false]
7270

7371
include:
74-
# Add an extra Python3.7 runner to use the lockfile
72+
# Add an extra Python3.10 runner to use the lockfile
7573
- os: "ubuntu-latest"
76-
python: "3.7"
77-
pipenv: "deploy"
74+
python: "3.10"
75+
lock: true
7876

7977
runs-on: ${{ matrix.os }}
8078
env:
8179
# https://github.com/pytest-dev/pytest/issues/2042
8280
PY_IGNORE_IMPORTMISMATCH: "1"
81+
# enable QT tests with no X Display
82+
QT_QPA_PLATFORM: "offscreen"
8383

8484
steps:
85-
- name: Setup git
86-
run: |
87-
git config --global user.email "[email protected]"
88-
git config --global user.name "Your Name"
85+
- name: Checkout
86+
uses: actions/checkout@v2
87+
with:
88+
fetch-depth: 0
8989

90-
- name: Setup repo and test
91-
uses: dls-controls/pipenv-run-action@v1
90+
- name: Setup python ${{ matrix.python }}
91+
uses: actions/setup-python@v2
9292
with:
9393
python-version: ${{ matrix.python }}
94-
pipenv-install: --dev --${{ matrix.pipenv }}
95-
allow-editable-installs: ${{ matrix.pipenv == 'deploy' }}
96-
pipenv-run: tests
94+
95+
- name: Install with locked dependencies
96+
if: matrix.lock
97+
run: |
98+
touch requirements.txt requirements_dev.txt
99+
pip install -r requirements.txt -e .
100+
pip freeze --exclude-editable > requirements.txt
101+
pip install -r requirements_dev.txt -e .[dev]
102+
pip freeze --exclude-editable > requirements_dev.txt
103+
104+
- name: Install with latest dependencies
105+
if: ${{ ! matrix.lock }}
106+
run: pip install -e .[dev]
107+
108+
- name: Run tests
109+
run: pytest tests
110+
111+
- name: Create requirements_dev.txt
112+
run: |
113+
pip freeze --exclude-editable > requirements_dev.txt
97114
98115
- name: Upload coverage to Codecov
99116
uses: codecov/codecov-action@v2
100117
with:
101-
name: ${{ matrix.python }}/${{ matrix.os }}/${{ matrix.pipenv }}
118+
name: ${{ matrix.python }}/${{ matrix.os }}/${{ matrix.lock }}
102119
files: cov.xml
103120

121+
- name: Upload build files
122+
if: matrix.lock
123+
uses: actions/upload-artifact@v2
124+
with:
125+
name: buildfiles
126+
path: |
127+
requirements.txt
128+
requirements_dev.txt
129+
104130
release:
105131
needs: [lint, wheel, test]
106132
runs-on: ubuntu-latest
@@ -109,15 +135,16 @@ jobs:
109135
steps:
110136
- uses: actions/download-artifact@v2
111137
with:
112-
name: dist
113-
path: dist
138+
path: artifacts
114139

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

0 commit comments

Comments
 (0)