Skip to content

Commit faea062

Browse files
committed
Update template files for uv
1 parent 0375c2d commit faea062

File tree

2 files changed

+72
-30
lines changed

2 files changed

+72
-30
lines changed

template/Dockerfile.jinja

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,36 @@ FROM python:${PYTHON_VERSION} AS developer
55

66
# Add any system dependencies for the developer/build environment here
77
RUN apt-get update && apt-get install -y --no-install-recommends \
8-
graphviz \
8+
graphviz vim \
99
&& rm -rf /var/lib/apt/lists/*
10+
# Install uv using the official installer script
11+
RUN curl -LsSf https://astral.sh/uv/install.sh | \
12+
env UV_INSTALL_DIR="/usr/local/bin" sh
1013

11-
# Set up a virtual environment and put it in PATH
12-
RUN python -m venv /venv
13-
ENV PATH=/venv/bin:$PATH{% if docker %}
14+
# Configure environment
15+
ENV UV_CHECK_UPDATE=false
16+
# Configure UV to use system Python
17+
# ENV UV_SYSTEM_PYTHON=1
18+
19+
# Creates virtual environment
20+
RUN uv venv --seed venv
21+
ENV VIRTUAL_ENV=/venv
22+
ENV PATH=$VIRTUAL_ENV/bin:$PATH{% if docker %}
1423

1524
# The build stage installs the context into the venv
1625
FROM developer AS build
1726
COPY . /context
1827
WORKDIR /context
19-
RUN touch dev-requirements.txt && pip install -c dev-requirements.txt .
28+
29+
# install dependencies and project into the local packages directory
30+
RUN touch dev-requirements.txt && uv pip install -c dev-requirements.txt .
2031

2132
# The runtime stage copies the built venv into a slim runtime container
2233
FROM python:${PYTHON_VERSION}-slim AS runtime
2334
# Add apt-get system dependecies for runtime here if needed
2435
COPY --from=build /venv/ /venv/
25-
ENV PATH=/venv/bin:$PATH
36+
ENV VIRTUAL_ENV=/venv
37+
ENV PATH=$VIRTUAL_ENV/bin:$PATH
2638

2739
# change this entrypoint if it is not the same as the repo
2840
ENTRYPOINT ["{{ repo_name }}"]

template/pyproject.toml.jinja

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ dev = [
2626
{% endif %}"pipdeptree",
2727
"pre-commit",
2828
{% if sphinx %}"pydata-sphinx-theme>=0.12",
29-
{% endif %}{% if type_checker=="pyright" %}"pyright",
30-
{% endif %}"pytest",
29+
{% endif %} {% if type_checker=="pyright" %}"pyright",
30+
{% endif %}"pytest>8.3.4",
3131
"pytest-cov",
3232
"ruff",
3333
{% if sphinx %}"sphinx-autobuild",
3434
"sphinx-copybutton",
3535
"sphinx-design",
36-
{% endif %}"tox-direct",
36+
{% endif %}"tox-uv",
3737
"types-mock",
3838
]
3939

@@ -77,30 +77,60 @@ data_file = "/tmp/{{ package_name }}.coverage"
7777
# Tests are run from installed location, map back to the src directory
7878
source = ["src", "**/site-packages/"]
7979

80-
# tox must currently be configured via an embedded ini string
81-
# See: https://github.com/tox-dev/tox/issues/999
8280
[tool.tox]
83-
legacy_tox_ini = """
84-
[tox]
85-
skipsdist=True
81+
skipsdist = true
8682

87-
[testenv:{pre-commit,type-checking,tests{% if sphinx %},docs{% endif %}}]
88-
# Don't create a virtualenv for the command, requires tox-direct plugin
89-
direct = True
90-
passenv = *
91-
allowlist_externals =
92-
pytest
93-
pre-commit
94-
{{ type_checker }}
95-
{% if sphinx %} sphinx-build
96-
sphinx-autobuild
97-
{% endif %}commands =
98-
pre-commit: pre-commit run --all-files --show-diff-on-failure {posargs}
99-
type-checking: {{ type_checker }} src tests {posargs}
100-
tests: pytest --cov={{ package_name }} --cov-report term --cov-report xml:cov.xml {posargs}
101-
{% if sphinx %} docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
102-
{% endif %}"""
83+
[tool.tox.env.pre-commit]
84+
description = "Run pre-commit"
85+
direct = true
86+
allowlist_externals = ["pre-commit"]
87+
commands = [
88+
[
89+
"pre-commit",
90+
"run",
91+
#"--all-files",
92+
"--show-diff-on-failure",
93+
"{posargs}",
94+
],
95+
]
96+
97+
[tool.tox.env.type-checking]
98+
description = "Run type-checking"
99+
direct = true
100+
allowlist_externals = ["{{ type_checker }}"]
101+
commands = [["{{ type_checker }}", "src", "{posargs}"]]
102+
103+
[tool.tox.env.tests]
104+
description = "Run tests"
105+
direct = true
106+
allowlist_externals = ["pytest"]
107+
commands = [
108+
[
109+
"pytest",
110+
"--cov={{ package_name}}",
111+
"--cov-report",
112+
"term",
113+
"--cov-report",
114+
"xml:cov.xml",
115+
"{posargs}",
116+
],
117+
]
103118

119+
{% if sphinx %}[tool.tox.env.docs]
120+
description = "Run docs"
121+
direct = true
122+
allowlist_externals = ["sphinx-build", "sphinx-autobuild"]
123+
commands = [
124+
[
125+
"sphinx-{posargs:build}",
126+
"-EW",
127+
"--keep-going",
128+
"-T",
129+
"docs",
130+
"build/html",
131+
],
132+
]
133+
{% endif %}
104134
[tool.ruff]
105135
src = ["src", "tests"]
106136
line-length = 88

0 commit comments

Comments
 (0)