Skip to content

Commit caf856f

Browse files
authored
Bump copier template to 5.0.0aX (#132)
* Bump copier template to 5.0.0a4 * Linting fixes * Add requests package
1 parent f97172c commit caf856f

File tree

21 files changed

+473
-867
lines changed

21 files changed

+473
-867
lines changed

.copier-answers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: 4.1.0-7-gb8b3f90
2+
_commit: 5.0.0a4
33
_src_path: gh:DiamondLightSource/python-copier-template
44
author_email: oliver.copping@diamond.ac.uk
55
author_name: Oliver Copping

.devcontainer/devcontainer.json

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88
"remoteEnv": {
99
// Allow X11 apps to run inside the container
1010
"DISPLAY": "${localEnv:DISPLAY}",
11-
// We put venv on a different volume to cache so have to copy
12-
"UV_LINK_MODE": "copy",
11+
// Put things that allow it in the persistent cache
12+
"PRE_COMMIT_HOME": "/cache/pre-commit",
13+
"UV_CACHE_DIR": "/cache/uv",
14+
"UV_PYTHON_CACHE_DIR": "/cache/uv-python",
15+
// Make a venv that is specific for this workspace path as the cache is shared
16+
"UV_PROJECT_ENVIRONMENT": "/cache/venv-for${localWorkspaceFolder}",
1317
// Do the equivalent of "activate" the venv so we don't have to "uv run" everything
14-
"PATH": "/workspaces/${localWorkspaceFolderBasename}/.venv/bin:${localEnv:PATH}"
18+
"VIRTUAL_ENV": "/cache/venv-for${localWorkspaceFolder}",
19+
"PATH": "/cache/venv-for${localWorkspaceFolder}/bin:${containerEnv:PATH}"
1520
},
1621
"customizations": {
1722
"vscode": {
1823
// Set *default* container specific settings.json values on container create.
1924
"settings": {
20-
"python.defaultInterpreterPath": "/workspaces/${localWorkspaceFolderBasename}/.venv/bin/python",
25+
// Use the container's python by default
26+
"python.defaultInterpreterPath": "/cache/venv-for${localWorkspaceFolder}/bin/python",
27+
// Don't activate the venv as it is already in the PATH
2128
"python.terminal.activateEnvInCurrentTerminal": false,
2229
"python.terminal.activateEnvironment": false,
23-
"python.testing.unittestEnabled": false,
24-
"python.testing.pytestEnabled": true,
25-
"editor.formatOnSave": true,
26-
"editor.codeActionsOnSave": {
27-
"source.organizeImports": "explicit"
28-
},
29-
"remote.autoForwardPorts": false,
30-
"[python]": {
31-
"editor.defaultFormatter": "charliermarsh.ruff"
32-
}
30+
// Workaround to prevent garbled python REPL in the terminal
31+
// https://github.com/microsoft/vscode-python/issues/25505
32+
"python.terminal.shellIntegration.enabled": false
3333
},
3434
// Add the IDs of extensions you want installed when the container is created.
3535
"extensions": [
@@ -44,36 +44,29 @@
4444
}
4545
},
4646
// Create the config folder for the bash-config feature and uv cache
47-
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config ${localEnv:HOME}/.cache/uv",
47+
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config",
4848
"runArgs": [
4949
// Allow the container to access the host X11 display and EPICS CA
5050
"--net=host",
5151
// Make sure SELinux does not disable with access to host filesystems like tmp
5252
"--security-opt=label=disable"
5353
],
54-
// Populate the user's terminal config folder with default config if it is blank
55-
"onCreateCommand": "/root/terminal-config/ensure-user-terminal-config.sh",
5654
"mounts": [
5755
// Mount in the user terminal config folder so it can be edited
5856
{
5957
"source": "${localEnv:HOME}/.config/terminal-config",
6058
"target": "/user-terminal-config",
6159
"type": "bind"
6260
},
63-
// Keep a persistent cross container cache for uv
61+
// Keep a persistent cross container cache for uv, pre-commit, and the venvs
6462
{
65-
"source": "${localEnv:HOME}/.cache/uv",
66-
"target": "/root/.cache/uv",
67-
"type": "bind"
68-
},
69-
// Use a volume mount for the uv venv so it is local to the container
70-
{
71-
"target": "/workspaces/${localWorkspaceFolderBasename}/.venv",
63+
"source": "devcontainer-shared-cache",
64+
"target": "/cache",
7265
"type": "volume"
7366
}
7467
],
7568
// Mount the parent as /workspaces so we can pip install peers as editable
7669
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
77-
// After the container is created, install the python project in editable form
78-
"postCreateCommand": "uv sync && uv run pre-commit install"
70+
// After the container is created, recreate the venv then make pre-commit first run faster
71+
"postCreateCommand": "uv venv --clear && uv sync && pre-commit install --install-hooks"
7972
}

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ It is recommended that developers use a [vscode devcontainer](https://code.visua
2424

2525
This project was created using the [Diamond Light Source Copier Template](https://github.com/DiamondLightSource/python-copier-template) for Python projects.
2626

27-
For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/4.1.0/how-to.html).
27+
For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/5.0.0a4/how-to.html).

.github/actions/install_requirements/action.yml

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

.github/workflows/_test.yml

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ on:
33
inputs:
44
python-version:
55
type: string
6-
description: The version of python to install
7-
required: true
6+
description: The version of python to install, default is from .python-version file
7+
default: ""
88
runs-on:
99
type: string
1010
description: The runner to run this job on
@@ -16,6 +16,7 @@ on:
1616
env:
1717
# https://github.com/pytest-dev/pytest/issues/2042
1818
PY_IGNORE_IMPORTMISMATCH: "1"
19+
UV_PYTHON: ${{ inputs.python-version }}
1920

2021
jobs:
2122
run:
@@ -29,30 +30,11 @@ jobs:
2930
fetch-depth: 0
3031
submodules: recursive
3132

32-
- if: inputs.python-version == 'dev'
33-
name: Install dev versions of python packages
34-
uses: ./.github/actions/install_requirements
35-
36-
- if: inputs.python-version == 'dev'
37-
name: Write the requirements as an artifact
38-
run: uv pip freeze --exclude-editable > /tmp/dev-requirements.txt
39-
40-
- if: inputs.python-version == 'dev'
41-
name: Upload dev-requirements.txt
42-
uses: actions/upload-artifact@v5
43-
with:
44-
name: dev-requirements
45-
path: /tmp/dev-requirements.txt
46-
47-
- if: inputs.python-version != 'dev'
48-
name: Install latest versions of python packages
49-
uses: ./.github/actions/install_requirements
50-
with:
51-
python-version: ${{ inputs.python-version }}
52-
uv-sync: ""
33+
- name: Install uv
34+
uses: astral-sh/setup-uv@v7
5335

5436
- name: Run tests
55-
run: tox -e tests
37+
run: uv run --locked tox -e tests
5638

5739
- name: Upload coverage to Codecov
5840
uses: codecov/codecov-action@v5

.github/workflows/_tox.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ jobs:
1515
- name: Checkout
1616
uses: actions/checkout@v5
1717

18-
- name: Install python packages
19-
uses: ./.github/actions/install_requirements
18+
- name: Install uv
19+
uses: astral-sh/setup-uv@v7
2020

2121
- name: Run tox
22-
run: tox -e ${{ inputs.tox }}
22+
run: uv run --locked tox -e ${{ inputs.tox }}

.github/workflows/ci.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ on:
55
branches:
66
- main
77
tags:
8-
- '*'
8+
- "*"
99
pull_request:
1010

1111
jobs:
12-
1312
lint:
1413
uses: ./.github/workflows/_tox.yml
1514
with:
@@ -18,8 +17,8 @@ jobs:
1817
test:
1918
strategy:
2019
matrix:
21-
runs-on: ["ubuntu-latest"] # can add macos-latest
22-
python-version: ["3.12"]
20+
runs-on: ["ubuntu-latest"] # can add windows-latest, macos-latest
21+
python-version: ["3.12", "3.13"]
2322
fail-fast: false
2423
uses: ./.github/workflows/_test.yml
2524
with:
@@ -30,14 +29,14 @@ jobs:
3029

3130
dist:
3231
uses: ./.github/workflows/_dist.yml
33-
32+
3433
pypi:
3534
needs: [dist, test]
3635
if: github.ref_type == 'tag'
3736
uses: ./.github/workflows/_pypi.yml
3837
permissions:
3938
id-token: write
40-
39+
4140
release:
4241
needs: [dist, test]
4342
if: github.ref_type == 'tag'

.gitleaks.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This allow-list is limited to YAML/YML files to cut down SealedSecrets false positives.
2+
# All gitleaks default rules still apply everywhere (useDefault = true).
3+
# To broaden this allow-list to all files, comment out the 'paths' line below.
4+
5+
[extend]
6+
useDefault = true
7+
8+
[[rules]]
9+
id = "generic-api-key"
10+
11+
# Pattern-only allowlist for long Ag… tokens in YAML
12+
[[rules.allowlists]]
13+
condition = "AND"
14+
regexes = [
15+
# Boundary-safe Ag… token without lookarounds (RE2-safe)
16+
'''(?:^|[^A-Za-z0-9+/=])(Ag[A-Za-z0-9+/]{500,}={0,2})(?:[^A-Za-z0-9+/=]|$)'''
17+
]
18+
# Limit to YAML only for now. Comment this out if you want it to apply everywhere.
19+
paths = ['''(?i).*\.ya?ml$''']

.pre-commit-config.yaml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v5.0.0
3+
rev: v6.0.0
44
hooks:
55
- id: check-added-large-files
6+
args: ["--maxkb=1000"] # uv.lock is more than 500kB
67
- id: check-yaml
78
- id: check-merge-conflict
89
- id: end-of-file-fixer
910

10-
- repo: https://github.com/astral-sh/uv-pre-commit
11-
# uv version.
12-
rev: 0.6.14
11+
- repo: local
1312
hooks:
14-
- id: uv-lock
15-
16-
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
# Ruff version.
18-
rev: v0.11.4
19-
hooks:
20-
# Run the linter.
2113
- id: ruff
2214
name: lint with ruff
2315
language: system
2416
entry: ruff check --force-exclude --fix
2517
types: [python]
2618
require_serial: true
2719

28-
# Run the formatter.
2920
- id: ruff-format
3021
name: format with ruff
3122
language: system
3223
entry: ruff format --force-exclude
3324
types: [python]
3425
require_serial: true
26+
27+
- id: uv-sync
28+
name: update uv.lock and venv
29+
pass_filenames: false
30+
language: system
31+
entry: uv sync
32+
files: ^(uv\.lock|pyproject\.toml)$
33+
34+
- repo: https://github.com/gitleaks/gitleaks
35+
rev: v8.28.0
36+
hooks:
37+
- id: gitleaks

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

0 commit comments

Comments
 (0)