-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from dls-controls/dev
Add latest python3-pip-skeleton
- Loading branch information
Showing
59 changed files
with
2,774 additions
and
549 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# ideas from https://www.docker.com/blog/containerized-python-development-part-1/ | ||
|
||
# This file is for use as a .vscode devcontainer as well as a runtime | ||
# container. The devcontainer should be rootful and use podman or docker | ||
# with user namespaces. | ||
|
||
FROM python:3.9 as base | ||
|
||
# use root to pin where the packages will install | ||
USER root | ||
ENV PATH=/root/.local/bin:$PATH | ||
|
||
# install additional packages | ||
RUN apt-get update && apt-get upgrade -y && \ | ||
apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
python3-pyqt5 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
FROM base as developer | ||
|
||
WORKDIR /workspace | ||
COPY . . | ||
|
||
# install runtime from DIST if there is one | ||
RUN mkdir -p /root/.local && \ | ||
if [ -d dist ] ; then \ | ||
touch requirements.txt && \ | ||
pip install --user -r requirements.txt dist/*.whl ; \ | ||
fi | ||
|
||
FROM base as runtime | ||
|
||
COPY --from=developer /root/.local /root/.local | ||
|
||
ENTRYPOINT ["dls-backup-bl"] | ||
CMD ["--version"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: | ||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.231.6/containers/python-3 | ||
{ | ||
"name": "Python 3", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"target": "developer", | ||
"context": "..", | ||
"args": {} | ||
}, | ||
"remoteEnv": { | ||
"DISPLAY": "${localEnv:DISPLAY}" | ||
}, | ||
// Set *default* container specific settings.json values on container create. | ||
"settings": { | ||
"python.defaultInterpreterPath": "/usr/local/bin/python", | ||
"python.linting.enabled": true, | ||
"python.linting.pylintEnabled": true, | ||
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", | ||
"python.formatting.blackPath": "/usr/local/py-utils/bin/black", | ||
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", | ||
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit", | ||
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", | ||
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", | ||
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", | ||
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", | ||
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint" | ||
}, | ||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [ | ||
"ms-python.python", | ||
"ms-python.vscode-pylance", | ||
"streetsidesoftware.code-spell-checker", | ||
"ryanluker.vscode-coverage-gutters", | ||
"mhutchie.git-graph", | ||
"eamodio.gitlens", | ||
"gruntfuggly.todo-tree", | ||
"redhat.vscode-yaml", | ||
"nsd.vscode-epics", | ||
"alefragnani.bookmarks" | ||
], | ||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. | ||
// "remoteUser": "vscode", | ||
// Make sure the files we are mapping into the container exist on the host | ||
"initializeCommand": "bash -c 'for i in $HOME/.inputrc $HOME/.bashrc_dev; do [ -f $i ] || touch $i; done'", | ||
"runArgs": [ | ||
"--privileged", | ||
"--net=host", | ||
"-v=${localEnv:HOME}/.ssh:/root/.ssh", | ||
"-v=${localEnv:HOME}/.bashrc_dev:/root/.bashrc", | ||
"-v=${localEnv:HOME}/.inputrc:/root/.inputrc" | ||
], | ||
"mounts": [ | ||
// map in home directory - not strictly necessary but may be useful | ||
"source=${localEnv:HOME},target=${localEnv:HOME},type=bind,consistency=cached" | ||
], | ||
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind", | ||
"workspaceFolder": "/workspace", | ||
// After the container is created, install the python project in editable form | ||
// This installs into the system python of the container | ||
"postCreateCommand": "pip install $([ -f requirements_dev.txt ] && echo -r requirements_dev.txt ) -e .[dev]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# locally build a runtime container for testing | ||
|
||
# first make sure a wheel is built | ||
( | ||
cd .. | ||
pip install build | ||
rm -r dist | ||
python -m build --wheel | ||
) | ||
|
||
# make the container name the same as the root folder name of this clone | ||
container_name=$(cd ..; basename $(realpath .)) | ||
echo building $container_name ... | ||
|
||
# run the build with required build-args for a runtime build | ||
ln -s ../dist . | ||
podman build --build-arg BASE=python:3.10-slim --build-arg ENTRYPOINT=$container_name -t $container_name .. --file ./Dockerfile | ||
unlink dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
* module-contact=hgv27681 | ||
src/*/_version_git.py export-subst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# To get started with Dependabot version updates, you'll need to specify which | ||
# package ecosystems to update and where the package manifests are located. | ||
# Please see the documentation for all configuration options: | ||
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates | ||
|
||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
|
||
- package-ecosystem: "pip" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Redirecting to main branch</title> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="refresh" content="0; url=./main/index.html"> | ||
<link rel="canonical" href="main/index.html"> | ||
</head> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
name: Code CI | ||
|
||
on: | ||
push: | ||
branches: | ||
# Restricting to these branches and tags stops duplicate jobs on internal | ||
# PRs but stops CI running on internal branches without a PR. Delete the | ||
# next 5 lines to restore the original behaviour | ||
- master | ||
- main | ||
tags: | ||
- "*" | ||
pull_request: | ||
schedule: | ||
# Run every Monday at 8am to check latest versions of dependencies | ||
- cron: "0 8 * * MON" | ||
|
||
jobs: | ||
lint: | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Lint | ||
run: | | ||
pip install --user .[dev] | ||
tox -e pre-commit,mypy | ||
wheel: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: ["ubuntu-latest"] | ||
python: ["3.8"] | ||
|
||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Create Sdist and Wheel | ||
# Set SOURCE_DATE_EPOCH from git commit for reproducible build | ||
# https://reproducible-builds.org/ | ||
run: | | ||
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) pipx run build --sdist --wheel | ||
- name: Upload Wheel and Sdist as artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: dist | ||
path: dist | ||
|
||
- name: Install minimum python version | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python }} | ||
|
||
- name: Install wheel in a venv and check cli works | ||
# ${GITHUB_REPOSITORY##*/} is the repo name without org | ||
# Replace this with the cli command if different to the repo name | ||
run: pipx run --python $(which python${{ matrix.python }}) --spec dist/*.whl dls-backup-bl --version | ||
|
||
test: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: ["ubuntu-latest"] # can add windows-latest, macos-latest | ||
python: ["3.8", "3.9", "3.10"] | ||
lock: [false] | ||
|
||
include: | ||
# Add an extra Python3.10 runner to use the lockfile | ||
- os: "ubuntu-latest" | ||
python: "3.10" | ||
lock: true | ||
|
||
runs-on: ${{ matrix.os }} | ||
env: | ||
# https://github.com/pytest-dev/pytest/issues/2042 | ||
PY_IGNORE_IMPORTMISMATCH: "1" | ||
# enable QT tests with no X Display | ||
QT_QPA_PLATFORM: "offscreen" | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Setup python ${{ matrix.python }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python }} | ||
|
||
- name: Install with locked dependencies | ||
if: matrix.lock | ||
run: | | ||
echo '# runtime dependencies' > requirements.txt | ||
echo '# developer dependencies' > requirements_dev.txt | ||
# above avoids zero length requirements files | ||
pip install -r requirements.txt -e . | ||
pip freeze --exclude-editable >> requirements.txt | ||
pip install -r requirements_dev.txt -e .[dev] | ||
pip freeze --exclude-editable >> requirements_dev.txt | ||
- name: Install with latest dependencies | ||
if: ${{ ! matrix.lock }} | ||
run: pip install -e .[dev] | ||
|
||
- name: Run tests | ||
run: pytest tests | ||
|
||
- name: Create requirements_dev.txt | ||
run: | | ||
pip freeze --exclude-editable > requirements_dev.txt | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v2 | ||
with: | ||
name: ${{ matrix.python }}/${{ matrix.os }}/${{ matrix.lock }} | ||
files: cov.xml | ||
|
||
- name: Upload build files | ||
if: matrix.lock | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: buildfiles | ||
path: | | ||
requirements.txt | ||
requirements_dev.txt | ||
release: | ||
needs: [lint, wheel, test] | ||
runs-on: ubuntu-latest | ||
# upload to PyPI and make a release on every tag | ||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') | ||
steps: | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
path: artifacts | ||
|
||
- name: Github Release | ||
# We pin to the SHA, not the tag, for security reasons. | ||
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions | ||
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14 | ||
with: | ||
files: | | ||
artifacts/dist/* | ||
artifacts/buildfiles/* | ||
generate_release_notes: true | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Publish to PyPI | ||
env: | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ secrets.pypi_token }} | ||
run: pipx run twine upload artifacts/dist/* | ||
|
||
make-container: | ||
needs: [lint, wheel, test] | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: dist | ||
path: dist | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v2 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Log in to GitHub Docker Registry | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ghcr.io/${{ github.repository }} | ||
tags: | | ||
type=ref,event=branch | ||
type=ref,event=tag | ||
type=raw,value=latest | ||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Build runtime image | ||
uses: docker/build-push-action@v3 | ||
with: | ||
file: .devcontainer/Dockerfile | ||
context: . | ||
push: ${{ github.event_name != 'pull_request' }} | ||
build-args: BASE=python:3.10-slim | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=local,src=/tmp/.buildx-cache | ||
cache-to: type=local,dest=/tmp/.buildx-cache |
Oops, something went wrong.