Skip to content

Commit 3765eab

Browse files
authored
Fix devcontainer venv 2 (#22)
* Fix file copying and pdm install in Dockerfile * Remove Sphinx version pinning as we don't care about Python 3.9 * Update pdm.lock * Fix post-install.sh venv creation * Convert to use uv from pdm Converted to hatch from tox * Add version raw options to remove dev and timestamp tags (for local builds) * Fixes to Dockerfile Removed devcontainer venv create command as not needed and broke things
1 parent 10409c0 commit 3765eab

File tree

11 files changed

+1583
-1621
lines changed

11 files changed

+1583
-1621
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
},
4141
"features": {
4242
// add in eternal history and other bash features
43-
"ghcr.io/diamondlightsource/devcontainer-features/bash-config:1.0.0": {},
43+
"ghcr.io/diamondlightsource/devcontainer-features/bash-config:1.0.2": {},
4444
"ghcr.io/devcontainers/features/common-utils:2": {
4545
"installZsh": true,
4646
"configureZshAsDefaultShell": true,

.devcontainer/post-install.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
pip install --upgrade pip
2-
pdm python install
3-
pdm venv create --force
4-
pdm use -f .venv
5-
pdm install -G dev
2+
uv python install
3+
uv sync --dev

.github/actions/install_requirements/action.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,23 @@ runs:
1717
echo "PYTHON_VERSION=$PYTHON_VERSION" >> "$GITHUB_ENV"
1818
shell: bash
1919

20-
- name: Setup PDM
21-
uses: pdm-project/setup-pdm@v4
20+
- name: Install uv and set the python version
21+
uses: astral-sh/setup-uv@v5
2222
with:
2323
python-version: ${{ env.PYTHON_VERSION }}
24+
enable-cache: true
25+
cache-dependency-glob: "uv.lock"
2426

2527
- name: Install dependencies
26-
run: pdm sync -d -G dev
28+
run: uv sync --dev
2729
shell: bash
2830

2931
- name: Report what was installed
30-
run: pdm list
32+
run: uv pip list
3133
shell: bash
3234

3335
- name: Add venv path to Github environment
34-
run: echo "VENV_PATH=$(pdm venv activate | sed 's/.*source //; s|/bin/activate||')" >> $GITHUB_ENV
36+
run: echo "VENV_PATH=.venv" >> $GITHUB_ENV
3537
shell: bash
3638

3739
- name: Add venv path to Github Path
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
on:
22
workflow_call:
33
inputs:
4-
tox:
4+
hatch:
55
type: string
6-
description: What to run under tox
6+
description: What to run under hatch
77
required: true
88

99

@@ -18,5 +18,10 @@ jobs:
1818
- name: Install python packages
1919
uses: ./.github/actions/install_requirements
2020

21-
- name: Run tox
22-
run: tox -e ${{ inputs.tox }}
21+
- name: Run hatch
22+
run: |
23+
IFS=',' read -ra SCRIPTS <<< "${{ inputs.hatch }}"
24+
for script in "${SCRIPTS[@]}"; do
25+
echo "Running $script"
26+
hatch run $script
27+
done

.github/workflows/_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
pip-install: ".[dev]"
5252

5353
- name: Run tests
54-
run: tox -e tests
54+
run: hatch run tests
5555

5656
- name: Upload coverage to Codecov
5757
uses: codecov/codecov-action@v5

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
lint:
1212
needs: check
1313
if: needs.check.outputs.branch-pr == ''
14-
uses: ./.github/workflows/_tox.yml
14+
uses: ./.github/workflows/_hatch.yml
1515
with:
16-
tox: pre-commit,type-checking
16+
hatch: precommit,type-check
1717

1818
test:
1919
needs: check

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ repos:
77
- id: check-merge-conflict
88
- id: end-of-file-fixer
99

10+
- repo: https://github.com/astral-sh/uv-pre-commit
11+
# uv version.
12+
rev: 0.6.3
13+
hooks:
14+
- id: uv-lock
15+
1016
- repo: https://github.com/astral-sh/ruff-pre-commit
1117
# Ruff version.
1218
rev: v0.9.6

Dockerfile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@ FROM python:${PYTHON_VERSION} AS developer
66
# Add any system dependencies for the developer/build environment here
77
RUN apt-get update && apt upgrade -y && rm -rf /var/lib/apt/lists/*
88
# Install PDM using the official installer script
9-
RUN curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py | python3 -
9+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
1010
RUN wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq \
1111
&& chmod +x /usr/bin/yq
1212

13-
# # The build stage installs the context into the venv
13+
# The build stage installs the context into the venv
1414
FROM developer AS build
15-
# install PDM
16-
RUN pip install -U pdm
15+
# install uv
16+
RUN pip install -U uv
1717
# disable update check
18-
ENV PDM_CHECK_UPDATE=false
18+
ENV UV_CHECK_UPDATE=false
1919
# copy files
20-
COPY pyproject.toml pdm.lock README.md LICENSE /project/
20+
# * means it will only try to copy uv.lock if it exists already
21+
COPY pyproject.toml uv.lock* README.md LICENSE /project/
2122
COPY src/ /project/src
2223

2324
# install dependencies and project into the local packages directory
2425
WORKDIR /project
25-
RUN pdm install --check --prod --no-editable
26+
RUN uv sync --dev --no-editable
2627

2728
# The runtime stage copies the built venv into a slim runtime container
2829
FROM python:${PYTHON_VERSION}-slim AS runtime

pdm.lock

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

pyproject.toml

Lines changed: 51 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ license = { file = "LICENSE" }
1616
readme = "README.md"
1717
requires-python = ">=3.12,<4.0"
1818
dependencies = ["pyyaml>=6.0.2"]
19-
optional-dependencies = { dev = [
20-
"pdm>=2.22.3",
19+
scripts = { phoebus-guibuilder = "phoebus_guibuilder.__main__:main" }
20+
21+
[dependency-groups]
22+
dev = [
23+
"basedpyright>=1.27.1",
24+
"hatch>=1.14.0",
25+
"hatch-vcs",
2126
"pre-commit",
2227
"pydata-sphinx-theme>=0.12",
23-
"pyright",
2428
"pytest>=8.3.4",
2529
"pytest-asyncio",
2630
"pytest-cov",
@@ -29,31 +33,40 @@ optional-dependencies = { dev = [
2933
"pytest-rerunfailures",
3034
"pytest-timeout",
3135
"ruff",
32-
"sphinx<8.2.0",
36+
"sphinx",
3337
"sphinx-autobuild",
3438
"autodoc-pydantic",
3539
"sphinxcontrib-mermaid",
3640
"sphinx-copybutton",
3741
"sphinx-design",
38-
"tox>=4.22",
3942
"types-mock",
4043
"types-pyyaml",
41-
] }
42-
scripts = { phoebus-guibuilder = "phoebus_guibuilder.__main__:main" }
44+
]
4345

4446
[build-system]
45-
requires = ["pdm-backend"]
46-
build-backend = "pdm.backend"
47+
requires = ["hatchling", "hatch-vcs"]
48+
build-backend = "hatchling.build"
49+
50+
[tool.uv]
51+
default-groups = []
4752

48-
[tool.pdm.version]
49-
fallback_version = "0.0.0"
50-
source = "scm"
51-
tag_filter = "*"
53+
[tool.hatch.version]
54+
source = "vcs"
55+
fallback-version = "0.1.0"
5256
# allows for tags with the format 0.1.0a1
53-
tag_regex = "(?P<version>([1-9][0-9]*!)?(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*((a|b|c|rc)(0|[1-9][0-9]*))?)"
57+
tag-pattern = "(?P<version>([1-9][0-9]*!)?(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))*((a|b|c|rc)(0|[1-9][0-9]*))?)"
5458
#version_format = "phoebus_guibuiler.version:format_version"
55-
write_to = "phoebus_guibuilder/_version.py"
56-
write_template = "__version__ = '{}'\n"
59+
raw-options = { version_scheme = "only-version", local_scheme = "dirty-tag" }
60+
61+
[tool.hatch.build.hooks.vcs]
62+
version-file = "src/phoebus_guibuilder/_version.py"
63+
template = '''
64+
# This file is automatically generated by Hatch
65+
# Do not modify this file directly
66+
67+
__version__ = "{version}"
68+
version_tuple = {version_tuple}
69+
'''
5770

5871
[tool.pyright]
5972
typeCheckingMode = "standard"
@@ -87,59 +100,35 @@ data_file = "/tmp/phoebus_guibuilder.coverage"
87100
# Tests are run from installed location, map back to the src directory
88101
source = ["src", "**/site-packages/"]
89102

90-
[tool.tox]
91-
skipsdist = true
103+
[tool.hatch.envs.default.scripts]
104+
all = [
105+
"hatch run precommit:precommit",
106+
"hatch run type-check:type-check",
107+
"hatch run tests:tests",
108+
# "hatch run docs:docs"
109+
]
110+
precommit = ["hatch run precommit:precommit"]
111+
type-check = ["hatch run type-check:type-check"]
112+
tests = ["hatch run tests:tests"]
113+
docs = ["hatch run docs:docs"]
92114

93-
[tool.tox.env.pre-commit]
115+
[tool.hatch.envs.precommit]
94116
description = "Run pre-commit"
95-
direct = true
96-
allowlist_externals = ["pre-commit"]
97-
commands = [
98-
[
99-
"pre-commit",
100-
"run",
101-
#"--all-files",
102-
"--show-diff-on-failure",
103-
"{posargs}",
104-
],
105-
]
117+
scripts = { precommit = ["pre-commit run --show-diff-on-failure {args}"] }
106118

107-
[tool.tox.env.type-checking]
119+
[tool.hatch.envs.type-check]
108120
description = "Run type-checking"
109-
direct = true
110-
allowlist_externals = ["pyright"]
111-
commands = [["pyright", "src", "{posargs}"]]
121+
scripts = { type-check = ["basedpyright --stats src {args}"] }
112122

113-
[tool.tox.env.tests]
123+
[tool.hatch.envs.tests]
114124
description = "Run tests"
115-
direct = true
116-
allowlist_externals = ["pytest"]
117-
commands = [
118-
[
119-
"pytest",
120-
"--cov=phoebus_guibuilder",
121-
"--cov-report",
122-
"term",
123-
"--cov-report",
124-
"xml:cov.xml",
125-
"{posargs}",
126-
],
127-
]
125+
scripts = { tests = [
126+
"pytest --cov=phoebus_guibuilder --cov-report term --cov-report xml:cov.xml {args}",
127+
] }
128128

129-
[tool.tox.env.docs]
129+
[tool.hatch.envs.docs]
130130
description = "Run docs"
131-
direct = true
132-
allowlist_externals = ["sphinx-build", "sphinx-autobuild"]
133-
commands = [
134-
[
135-
"sphinx-{posargs:build}",
136-
"-EW",
137-
"--keep-going",
138-
"-T",
139-
"docs",
140-
"build/html",
141-
],
142-
]
131+
scripts = { docs = ["sphinx-{args:build} -EW --keep-going -T docs build/html"] }
143132

144133
[tool.ruff]
145134
src = ["src", "tests", "system_tests"]
@@ -160,3 +149,4 @@ lint.select = [
160149
# See https://github.com/DiamondLightSource/python-copier-template/issues/154
161150
# Remove this line to forbid private member access in tests
162151
"tests/**/*" = ["SLF001"]
152+
# dependencies = ["sphinx-build", "sphinx-autobuild"]

0 commit comments

Comments
 (0)