Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt python-copier-template #384

Merged
merged 56 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
03db188
Add .copier-answers.yml
joeshannon Mar 6, 2024
1572b4e
Move Dockerfile
joeshannon Mar 6, 2024
2aa0664
Add ADR
joeshannon Mar 6, 2024
c7a4a29
Copier template changes to docs
joeshannon Mar 6, 2024
4667ff4
Copier template changes to .gitignore
joeshannon Mar 6, 2024
ed75360
Copier template to CONTRIBUTING
joeshannon Mar 6, 2024
f9f2d83
Copier changes to pyproject.toml
joeshannon Mar 6, 2024
0d47a27
Copier changes to vscode files
joeshannon Mar 6, 2024
36ebcfb
Copier changes to .pre-commit-config.yaml
joeshannon Mar 6, 2024
4e1d377
Copier changes to .github
joeshannon Mar 6, 2024
42399f8
Move container-startup.sh to root
joeshannon Mar 6, 2024
5bb0037
Add resolved conflicts for template 2.0.0
joeshannon Mar 6, 2024
d9c94a0
Add template 2.0.1 .github changes
joeshannon Mar 6, 2024
3e76961
Add template 2.0.1 pre-commit and gitignore
joeshannon Mar 6, 2024
337a520
Don't run CI against Python 3.8
joeshannon Mar 6, 2024
d150db3
Add ActiveMQ service to test CI
joeshannon Mar 7, 2024
c4388cb
copier 2.0.0 devcontainer
joeshannon Mar 7, 2024
0db041b
Copier 2.0.0 answers
joeshannon Mar 7, 2024
817da02
Add Copier 2.0.0 .vscode
joeshannon Mar 7, 2024
52402ab
Copier 2.0.0 convert README and CONTRIBUTING to markdown
joeshannon Mar 7, 2024
39f42c6
Convert developer and user docs to markdown
joeshannon Mar 7, 2024
2c5d733
Revert "Convert developer and user docs to markdown"
joeshannon Mar 7, 2024
fc3f9ee
Convert with myst
joeshannon Mar 7, 2024
85e3787
Combine developer and user docs
joeshannon Mar 7, 2024
4a5d157
Add copier 2.0.0 COPYME
joeshannon Mar 7, 2024
8bcea6f
Add copier 2.0.0 non-conflict document files
joeshannon Mar 7, 2024
18785f9
Replace copier decision file
joeshannon Mar 7, 2024
780574e
Delete remaining rst files
joeshannon Mar 7, 2024
2c23d71
Use proper contributing
joeshannon Mar 7, 2024
ad76c06
Fix README.md to match copier 2.0.0
joeshannon Mar 7, 2024
94d39e2
Fix CI after API schema file move
joeshannon Mar 7, 2024
ec35708
Fix readme in pyproject.toml
joeshannon Mar 7, 2024
55f40a5
Move and convert new write plans documentation
joeshannon Mar 7, 2024
3641e9b
Fix image links after combining documentation
joeshannon Mar 7, 2024
d15638a
Add back exclude for helm yaml lint
joeshannon Mar 8, 2024
d875557
Switch cli and rest-spec back to rst
joeshannon Mar 8, 2024
ee13fff
Add missing sphinx extensions
joeshannon Mar 8, 2024
7a96ee0
Attempt fixing docs references
joeshannon Mar 8, 2024
0103c4a
Fix links after docs conversion to single tree
joeshannon Mar 8, 2024
6cd95ca
Add temporary link to external dev-install
joeshannon Mar 8, 2024
d8ce5ec
Update description to match recent change in README
joeshannon Mar 8, 2024
2ec4f78
Use absolute link for README image
joeshannon Mar 8, 2024
278c94b
Disable UP ruff checks
joeshannon Mar 8, 2024
42b0cf5
Disable B008 for FastAPI Depends etc.
joeshannon Mar 11, 2024
17fed4d
Fix ruff issues
joeshannon Mar 11, 2024
39b7fdd
Switch back to relative image in README
joeshannon Mar 11, 2024
a798c2f
Switch README and CONTRIBUTING back to rst
joeshannon Mar 14, 2024
9e83630
Restore non copier explainations back to rst
joeshannon Mar 14, 2024
d7d6c63
Convert how-to back to rst
joeshannon Mar 14, 2024
e8f2eb2
Convert reference back to rst
joeshannon Mar 14, 2024
39407dd
Convert tutorials back to rst
joeshannon Mar 14, 2024
49fe911
Fix docs refs after reconversion back to rst
joeshannon Mar 14, 2024
dceab11
Update docs/explanations/decisions/0004-switched-to-python-copier-tem…
joeshannon Mar 15, 2024
681ee0f
Add test to fix coverage
joeshannon Mar 15, 2024
1e8eb00
Remove src from imports
joeshannon Mar 15, 2024
6b35b4c
Ignore read-only property
joeshannon Mar 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Changes here will be overwritten by Copier
_commit: 2.0.1
_src_path: gh:DiamondLightSource/python-copier-template
author_email: [email protected]
author_name: Callum Forrester
component_owner: user:vid18871
description: Lightweight bluesky-as-a-service wrapper application. Also usable as
a library.
distribution_name: blueapi
docker: true
docs_type: sphinx
git_platform: github.com
github_org: DiamondLightSource
package_name: blueapi
pypi: true
repo_name: blueapi
type_checker: mypy
41 changes: 0 additions & 41 deletions .devcontainer/Dockerfile

This file was deleted.

54 changes: 23 additions & 31 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,45 @@
{
"name": "Python 3 Developer Container",
"build": {
"dockerfile": "Dockerfile",
"target": "build",
// Only upgrade pip, we will install the project below
"args": {
"PIP_OPTIONS": "--upgrade pip"
}
"dockerfile": "../Dockerfile",
"target": "developer"
},
"remoteEnv": {
// Allow X11 apps to run inside the container
"DISPLAY": "${localEnv:DISPLAY}"
},
// Add the URLs of features you want added when the container is built.
"features": {
"ghcr.io/devcontainers/features/common-utils:1": {
"username": "none",
"upgradePackages": false
}
},
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/venv/bin/python"
},
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/venv/bin/python"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"github.vscode-github-actions",
"tamasfe.even-better-toml",
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters"
"ryanluker.vscode-coverage-gutters",
"charliermarsh.ruff",
"ms-azuretools.vscode-docker"
]
}
},
// Make sure the files we are mapping into the container exist on the host
"initializeCommand": "bash -c 'for i in $HOME/.inputrc; do [ -f $i ] || touch $i; done'",
"features": {
// Some default things like git config
"ghcr.io/devcontainers/features/common-utils:2": {
"upgradePackages": false
}
},
"runArgs": [
// Allow the container to access the host X11 display and EPICS CA
"--net=host",
"--security-opt=label=type:container_runtime_t"
],
"mounts": [
"source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind",
"source=${localEnv:HOME}/.inputrc,target=/root/.inputrc,type=bind",
// map in home directory - not strictly necessary but useful
"source=${localEnv:HOME},target=${localEnv:HOME},type=bind,consistency=cached"
// Make sure SELinux does not disable with access to host filesystems like tmp
"--security-opt=label=disable"
],
// make the workspace folder the same inside and outside of the container
"workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind",
"workspaceFolder": "${localWorkspaceFolder}",
// Mount the parent as /workspaces so we can pip install peers as editable
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
// After the container is created, install the python project in editable form
"postCreateCommand": "pip install -e .[dev]"
"postCreateCommand": "pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]' && pre-commit install"
}
65 changes: 21 additions & 44 deletions .github/actions/install_requirements/action.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,34 @@
name: Install requirements
description: Run pip install with requirements and upload resulting requirements
description: Install a version of python then call pip install and report what was installed
inputs:
requirements_file:
description: Name of requirements file to use and upload
required: true
install_options:
python-version:
description: Python version to install, default is from Dockerfile
default: "dev"
pip-install:
description: Parameters to pass to pip install
required: true
python_version:
description: Python version to install
default: "3.9"
default: "$([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e .[dev]"

runs:
using: composite

steps:
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python_version }}

- name: Pip install
run: |
touch ${{ inputs.requirements_file }}
# -c uses requirements.txt as constraints, see 'Validate requirements file'
pip install -c ${{ inputs.requirements_file }} ${{ inputs.install_options }}
shell: bash

- name: Create lockfile
- name: Get version of python
run: |
mkdir -p lockfiles
pip freeze --exclude-editable --exclude ophyd-async --exclude dls-dodal --exclude dls-bluesky-core --exclude bluesky > lockfiles/${{ inputs.requirements_file }}
# delete the self referencing line and make sure it isn't blank
sed -i '/file:/d' lockfiles/${{ inputs.requirements_file }}
PYTHON_VERSION="${{ inputs.python-version }}"
if [ $PYTHON_VERSION == "dev" ]; then
PYTHON_VERSION=$(sed -n "s/ARG PYTHON_VERSION=//p" Dockerfile)
fi
echo "PYTHON_VERSION=$PYTHON_VERSION" >> "$GITHUB_ENV"
shell: bash

- name: Upload lockfiles
uses: actions/upload-artifact@v3
- name: Setup python
uses: actions/setup-python@v5
with:
name: lockfiles
path: lockfiles
python-version: ${{ env.PYTHON_VERSION }}

# This eliminates the class of problems where the requirements being given no
# longer match what the packages themselves dictate. E.g. In the rare instance
# where I install some-package which used to depend on vulnerable-dependency
# but now uses good-dependency (despite being nominally the same version)
# pip will install both if given a requirements file with -r
- name: If requirements file exists, check it matches pip installed packages
run: |
if [ -s ${{ inputs.requirements_file }} ]; then
if ! diff -u ${{ inputs.requirements_file }} lockfiles/${{ inputs.requirements_file }}; then
echo "Error: ${{ inputs.requirements_file }} need the above changes to be exhaustive"
exit 1
fi
fi
- name: Install packages
run: pip install ${{ inputs.pip-install }}
shell: bash

- name: Report what was installed
run: pip freeze
shell: bash
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ updates:
directory: "/"
schedule:
interval: "weekly"
groups:
actions:
patterns:
- "*"

- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
groups:
dev-dependencies:
patterns:
- "*"
8 changes: 4 additions & 4 deletions .github/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<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">
<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>
17 changes: 5 additions & 12 deletions .github/pages/make_switcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_sorted_tags_list() -> List[str]:
return report_output(stdout, "Tags list")


def get_versions(ref: str, add: Optional[str], remove: Optional[str]) -> List[str]:
def get_versions(ref: str, add: Optional[str]) -> List[str]:
"""Generate the file containing the list of all GitHub Pages builds."""
# Get the directories (i.e. builds) from the GitHub Pages branch
try:
Expand All @@ -36,9 +36,6 @@ def get_versions(ref: str, add: Optional[str], remove: Optional[str]) -> List[st
# Add and remove from the list of builds
if add:
builds.add(add)
if remove:
assert remove in builds, f"Build '{remove}' not in {sorted(builds)}"
builds.remove(remove)

# Get a sorted list of tags
tags = get_sorted_tags_list()
Expand All @@ -59,26 +56,22 @@ def get_versions(ref: str, add: Optional[str], remove: Optional[str]) -> List[st
def write_json(path: Path, repository: str, versions: str):
org, repo_name = repository.split("/")
struct = [
dict(version=version, url=f"https://{org}.github.io/{repo_name}/{version}/")
{"version": version, "url": f"https://{org}.github.io/{repo_name}/{version}/"}
for version in versions
]
text = json.dumps(struct, indent=2)
print(f"JSON switcher:\n{text}")
path.write_text(text)
path.write_text(text, encoding="utf-8")


def main(args=None):
parser = ArgumentParser(
description="Make a versions.txt file from gh-pages directories"
description="Make a versions.json file from gh-pages directories"
)
parser.add_argument(
"--add",
help="Add this directory to the list of existing directories",
)
parser.add_argument(
"--remove",
help="Remove this directory from the list of existing directories",
)
parser.add_argument(
"repository",
help="The GitHub org and repository name: ORG/REPO",
Expand All @@ -91,7 +84,7 @@ def main(args=None):
args = parser.parse_args(args)

# Write the versions file
versions = get_versions("origin/gh-pages", args.add, args.remove)
versions = get_versions("origin/gh-pages", args.add)
write_json(args.output, args.repository, versions)


Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on:
workflow_call:
outputs:
branch-pr:
description: The PR number if the branch is in one
value: ${{ jobs.pr.outputs.branch-pr }}

jobs:
pr:
runs-on: "ubuntu-latest"
outputs:
branch-pr: ${{ steps.script.outputs.result }}
steps:
- uses: actions/github-script@v7
id: script
if: github.event_name == 'push'
with:
script: |
const prs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: context.repo.owner + ':${{ github.ref_name }}'
})
if (prs.data.length) {
console.log(`::notice ::Skipping CI on branch push as it is already run in PR #${prs.data[0]["number"]}`)
return prs.data[0]["number"]
}
56 changes: 56 additions & 0 deletions .github/workflows/_container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
on:
workflow_call:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Need this to get version number from last tag
fetch-depth: 0

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Docker Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and export to Docker local cache
uses: docker/build-push-action@v5
with:
context: .
# Need load and tags so we can test it below
load: true
tags: tag_for_testing

- name: Test cli works in cached runtime image
run: docker run --rm tag_for_testing --version

- name: Create tags for publishing image
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=tag
type=raw,value=latest

- name: Push cached image to container registry
if: github.ref_type == 'tag'
uses: docker/build-push-action@v5
# This does not build the image again, it will find the image in the
# Docker cache and publish it
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Loading
Loading