Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 4.2.0
_commit: 5.0.0a1-3-g470d4fc
_src_path: https://github.com/diamondlightsource/python-copier-template
author_email: giles.knap@diamond.ac.uk
author_name: Giles Knap
Expand Down
38 changes: 29 additions & 9 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
},
"remoteEnv": {
// Allow X11 apps to run inside the container
"DISPLAY": "${localEnv:DISPLAY}"
"DISPLAY": "${localEnv:DISPLAY}",
// Do the equivalent of "activate" the venv so we don't have to "uv run" everything
"PATH": "/workspaces/${localWorkspaceFolderBasename}/.venv/bin:${containerEnv:PATH}"
},
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/venv/bin/python"
"python.defaultInterpreterPath": "/workspaces/${localWorkspaceFolderBasename}/.venv/bin/python",
"python.terminal.activateEnvInCurrentTerminal": false,
"python.terminal.activateEnvironment": false,
"remote.autoForwardPorts": false
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
Expand All @@ -27,20 +32,35 @@
]
}
},
"features": {
// add in eternal history and other bash features
"ghcr.io/diamondlightsource/devcontainer-features/bash-config:1": {}
},
// Create the config folder for the bash-config feature
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/bash-config",
// Create the config folder for the bash-config feature and uv cache
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config ${localEnv:HOME}/.cache/uv",
"runArgs": [
// Allow the container to access the host X11 display and EPICS CA
"--net=host",
// Make sure SELinux does not disable with access to host filesystems like tmp
"--security-opt=label=disable"
],
"mounts": [
// Mount in the user terminal config folder so it can be edited
{
"source": "${localEnv:HOME}/.config/terminal-config",
"target": "/user-terminal-config",
"type": "bind"
},
// Keep a persistent cross container cache for uv
{
"source": "${localEnv:HOME}/.cache/uv",
"target": "/root/.cache/uv",
"type": "bind"
},
// Use a volume mount for the uv venv so it is local to the container
{
"target": "/workspaces/${localWorkspaceFolderBasename}/.venv",
"type": "volume"
}
],
// 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 $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]' && pre-commit install"
"postCreateCommand": "uv sync && uv run pre-commit install --install-hooks"
}
2 changes: 1 addition & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ It is recommended that developers use a [vscode devcontainer](https://code.visua

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

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.2.0/how-to.html).
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.0a1/how-to.html).
35 changes: 0 additions & 35 deletions .github/actions/install_requirements/action.yml

This file was deleted.

11 changes: 6 additions & 5 deletions .github/workflows/_dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ jobs:
# Need this to get version number from last tag
fetch-depth: 0

- name: Install uv
uses: astral-sh/setup-uv@v6

- name: Build sdist and wheel
run: >
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) &&
pipx run build
uvx --from build pyproject-build

- name: Upload sdist and wheel as artifacts
uses: actions/upload-artifact@v4
Expand All @@ -24,12 +27,10 @@ jobs:
path: dist

- name: Check for packaging errors
run: pipx run twine check --strict dist/*
run: uvx twine check --strict dist/*

- name: Install produced wheel
uses: ./.github/actions/install_requirements
with:
pip-install: dist/*.whl
run: python -m pip install dist/*.whl

- name: Test module --version works using the installed wheel
# If more than one module in src/ replace with module name to test
Expand Down
30 changes: 6 additions & 24 deletions .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ on:
inputs:
python-version:
type: string
description: The version of python to install
required: true
description: The version of python to install, default is from .python-version file
default: ""
runs-on:
type: string
description: The runner to run this job on
Expand All @@ -16,6 +16,7 @@ on:
env:
# https://github.com/pytest-dev/pytest/issues/2042
PY_IGNORE_IMPORTMISMATCH: "1"
UV_PYTHON: ${{ inputs.python-version }}

jobs:
run:
Expand All @@ -28,30 +29,11 @@ jobs:
# Need this to get version number from last tag
fetch-depth: 0

- if: inputs.python-version == 'dev'
name: Install dev versions of python packages
uses: ./.github/actions/install_requirements

- if: inputs.python-version == 'dev'
name: Write the requirements as an artifact
run: pip freeze --exclude-editable > /tmp/dev-requirements.txt

- if: inputs.python-version == 'dev'
name: Upload dev-requirements.txt
uses: actions/upload-artifact@v4
with:
name: dev-requirements
path: /tmp/dev-requirements.txt

- if: inputs.python-version != 'dev'
name: Install latest versions of python packages
uses: ./.github/actions/install_requirements
with:
python-version: ${{ inputs.python-version }}
pip-install: ".[dev]"
- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Run tests
run: tox -e tests
run: uv run --locked tox -e tests

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/_tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Install python packages
uses: ./.github/actions/install_requirements
- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Run tox
run: tox -e ${{ inputs.tox }}
run: uv run --locked tox -e ${{ inputs.tox }}
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ jobs:
matrix:
runs-on: ["ubuntu-latest"] # can add windows-latest, macos-latest
python-version: ["3.11", "3.12", "3.13"]
include:
# Include one that runs in the dev environment
- runs-on: "ubuntu-latest"
python-version: "dev"
fail-fast: false
uses: ./.github/workflows/_test.yml
with:
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repos:
rev: v5.0.0
hooks:
- id: check-added-large-files
args: ["--maxkb=1000"] # uv.lock is more than 500kB
- id: check-yaml
exclude: ^helm\/.*\/templates\/.*|catalog-info.yaml
- id: check-merge-conflict
Expand All @@ -23,3 +24,10 @@ repos:
entry: ruff format --force-exclude
types: [python]
require_serial: true

- id: uv-sync
name: update uv.lock and venv
pass_filenames: false
language: system
entry: uv sync
files: ^(uv\.lock|pyproject\.toml)$
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
79 changes: 38 additions & 41 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,65 +1,62 @@
# The devcontainer should use the developer target and run as root with podman
# or docker with user namespaces.
ARG PYTHON_VERSION=3.11

# The developer is used by devcontainers ###############################################
FROM python:${PYTHON_VERSION} AS developer
FROM ghcr.io/diamondlightsource/ubuntu-devcontainer:noble AS developer

# Add any system dependencies for the developer/build environment here
RUN apt-get update && apt-get install -y --no-install-recommends \
gdb \
busybox \
RUN apt-get update -y && apt-get install -y --no-install-recommends \
graphviz \
&& rm -rf /var/lib/apt/lists/* \
&& busybox --install -s

# Set up a virtual environment and put it in PATH
RUN python -m venv /venv
ENV PATH=/venv/bin:$PATH
&& apt-get dist-clean

# The build stage installs the context into the venv ###################################
# The build stage installs the context into the venv
FROM developer AS build

# Requires buildkit 0.17.0
COPY --chmod=o+wrX . /workspaces/fastcs-example
WORKDIR /workspaces/fastcs-example
RUN touch dev-requirements.txt && pip install stdio-socket>=1.3.1 debugpy \
-c dev-requirements.txt .[demo]
# Change the working directory to the `app` directory
# and copy in the project
WORKDIR /app
COPY . /app
RUN chmod o+wrX .

# Tell uv sync to install python in a known location so we can copy it out later
ENV UV_PYTHON_INSTALL_DIR=/python

# Sync the project without its dev dependencies
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --no-editable --no-dev


# The debug stage allows for debugging and development #################################
FROM build AS debug

# Set origin to use ssh
RUN git remote set-url origin git@github.com:DiamondLightSource/fastcs-example.git

# Make editable and debuggable
RUN pip install debugpy -e '.[dev]'
RUN chmod o+wrX /venv /workspaces

RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
busybox \
gdb \
libnss-ldapd \
&& rm -rf /var/lib/apt/lists/* \
&& busybox --install -s

# For this pod to understand finding user information from LDAP
RUN apt update
RUN DEBIAN_FRONTEND=noninteractive apt install libnss-ldapd -y
RUN sed -i 's/files/ldap files/g' /etc/nsswitch.conf

# Alternate entrypoint to allow restarting the IOC
ENTRYPOINT [ "/bin/bash", "-c", "sleep infinity" ]
# Make editable and debuggable
RUN uv pip install debugpy
RUN uv pip install -e .

# Alternate entrypoint to allow devcontainer to attach
ENTRYPOINT [ "/bin/bash", "-c", "--" ]
CMD [ "while true; do sleep 30; done;" ]

# The runtime stage copies the built venv into a runtime container
FROM ubuntu:noble AS runtime

# The runtime stage has built venv only ################################################
FROM python:${PYTHON_VERSION}-slim AS runtime
# Add apt-get system dependecies for runtime here if needed
# RUN apt-get update -y && apt-get install -y --no-install-recommends \
# some-library \
# && apt-get dist-clean

# Add apt-get system dependecies for runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
gdb \
&& rm -rf /var/lib/apt/lists/*
# Copy the python installation from the build stage
COPY --from=build /python /python

COPY --from=build /venv/ /venv/
ENV PATH=/venv/bin:$PATH
# Copy the environment, but not the source code
COPY --from=build /app/.venv /app/.venv
ENV PATH=/app/.venv/bin:$PATH

# change this entrypoint if it is not the same as the repo
ENTRYPOINT ["fastcs-example"]
Expand Down
Loading