Skip to content
Open
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
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
],
// 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"
// After the container is created, install the uv env
"postCreateCommand": "uv pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e '.[dev]' && pre-commit install"
}
20 changes: 15 additions & 5 deletions .github/actions/install_requirements/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
description: Python version to install, default is from Dockerfile
default: "dev"
pip-install:
description: Parameters to pass to pip install
description: Parameters to pass to uv pip install
default: "$([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e .[dev]"

runs:
Expand All @@ -20,15 +20,25 @@ runs:
echo "PYTHON_VERSION=$PYTHON_VERSION" >> "$GITHUB_ENV"
shell: bash

- name: Setup python
uses: actions/setup-python@v5
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Install packages
run: pip install ${{ inputs.pip-install }}
run: uv pip install ${{ inputs.pip-install }}
shell: bash

- name: Report what was installed
run: pip freeze
run: uv pip list
shell: bash

- name: Add venv path to Github environment
run: echo "VENV_PATH=.venv" >> $GITHUB_ENV
shell: bash

- name: Add venv path to Github Path
run: echo "${{ env.VENV_PATH }}/bin:$PATH" >> $GITHUB_PATH
shell: bash
2 changes: 1 addition & 1 deletion .github/workflows/_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Create GitHub Release
# We pin to the SHA, not the tag, for security reasons.
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions
uses: softprops/action-gh-release@7b4da11513bf3f43f9999e90eabced41ab8bb048 # v2.2.0
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda # v2.2.1
with:
prerelease: ${{ contains(github.ref_name, 'a') || contains(github.ref_name, 'b') || contains(github.ref_name, 'rc') }}
files: "*"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

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

- if: inputs.python-version == 'dev'
name: Upload dev-requirements.txt
Expand Down
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ jobs:
test:
needs: check
if: needs.check.outputs.branch-pr == ''
strategy:
matrix:
runs-on: ["ubuntu-latest"] # can add windows-latest, macos-latest
python-version: ["3.11"]
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:
python-version: dev
runs-on: ubuntu-latest
runs-on: ${{ matrix.runs-on }}
python-version: ${{ matrix.python-version }}
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

Expand Down
14 changes: 12 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-yaml
- id: check-merge-conflict
- id: end-of-file-fixer

- repo: local
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.6.14
hooks:
- id: uv-lock

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.11.4
hooks:
# Run the linter.
- id: ruff
name: lint with ruff
language: system
entry: ruff check --force-exclude --fix
types: [python]
require_serial: true

# Run the formatter.
- id: ruff-format
name: format with ruff
language: system
Expand Down
17 changes: 13 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ FROM python:${PYTHON_VERSION} AS developer

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

# Set up a virtual environment and put it in PATH
RUN python -m venv /venv
ENV PATH=/venv/bin:$PATH
# Configure environment
ENV UV_CHECK_UPDATE=false
# Configure UV to use system Python
# ENV UV_SYSTEM_PYTHON=1

# Creates virtual environment
RUN uv venv --seed venv
ENV VIRTUAL_ENV=/venv
ENV PATH=$VIRTUAL_ENV/bin:$PATH
Empty file added __init__.py
Empty file.
76 changes: 51 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ build-backend = "setuptools.build_meta"
name = "python-copier-template"
dynamic = ["version"]
requires-python = ">=3.10"

[project.optional-dependencies]
dev = [
optional-dependencies = { dev = [
"copier",
"myst-parser",
"pre-commit",
Expand All @@ -18,9 +16,13 @@ dev = [
"sphinx-autobuild",
"sphinx-copybutton",
"sphinx-design",
"tox",
"tox-direct",
]
"tox-uv",
"twine>=6.1.0",
] }

# # Without this, setuptools apparently try to scan the whole image's filesystem while working in /
# [tool.setuptools.packages.find]
# where = []

[tool.setuptools_scm]

Expand All @@ -32,27 +34,51 @@ addopts = """
# Doctest python code in docs, python code in src docstrings, test functions in tests
testpaths = "tests"

# tox must currently be configured via an embedded ini string
# See: https://github.com/tox-dev/tox/issues/999

[tool.tox]
legacy_tox_ini = """
[tox]
skipsdist=True
skipsdist = true
requires = ["tox-uv>=1.25.0"]
# envs to runs automatically with tox -p
env_list = ["pre-commit", "tests", "docs"]

[tool.tox.env]
passenv = { "*" = "" }
# Include setuptools, pip, ... in the tox envs
uv_seed = { enabled = true }

[testenv:{pre-commit,tests,docs}]
# Don't create a virtualenv for the command, requires tox-direct plugin
direct = True
passenv = *
allowlist_externals =
pre-commit
pytest
sphinx-build
sphinx-autobuild
commands =
pre-commit: pre-commit run --all-files --show-diff-on-failure {posargs}
tests: pytest {posargs}
docs: sphinx-{posargs:build -EW --keep-going} -T docs build/html
"""
[tool.tox.env.pre-commit]
description = "Run pre-commit"
allowlist_externals = ["pre-commit"]
commands = [
[
"pre-commit",
"run",
#"--all-files",
"--show-diff-on-failure",
"{posargs}",
],
]

[tool.tox.env.tests]
description = "Run tests"
allowlist_externals = ["pytest"]
commands = [["pytest", "{posargs}"]]

[tool.tox.env.docs]
description = "Run docs"
allowlist_externals = ["sphinx-build", "sphinx-autobuild"]
commands = [
[
"sphinx-build",
"-T",
"docs",
"build/html",
{ replace = "posargs", default = [
"-EW",
"--keep-going",
], extend = true },
],
]

[tool.ruff]
src = ["src", "tests"]
Expand Down
26 changes: 19 additions & 7 deletions template/Dockerfile.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,36 @@ FROM python:${PYTHON_VERSION} AS developer

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

# Set up a virtual environment and put it in PATH
RUN python -m venv /venv
ENV PATH=/venv/bin:$PATH{% if docker %}
# Configure environment
ENV UV_CHECK_UPDATE=false
# Configure UV to use system Python
# ENV UV_SYSTEM_PYTHON=1

# Creates virtual environment
RUN uv venv --seed venv
ENV VIRTUAL_ENV=/venv
ENV PATH=$VIRTUAL_ENV/bin:$PATH{% if docker %}

# The build stage installs the context into the venv
FROM developer AS build
COPY . /context
WORKDIR /context
RUN touch dev-requirements.txt && pip install -c dev-requirements.txt .

# install dependencies and project into the local packages directory
RUN touch dev-requirements.txt && uv pip install -c dev-requirements.txt .

# The runtime stage copies the built venv into a slim runtime container
FROM python:${PYTHON_VERSION}-slim AS runtime
# Add apt-get system dependecies for runtime here if needed
COPY --from=build /venv/ /venv/
ENV PATH=/venv/bin:$PATH
COPY --from=build /venv/ .venv/
ENV VIRTUAL_ENV=./.venv
ENV PATH=$VIRTUAL_ENV/bin:$PATH

# change this entrypoint if it is not the same as the repo
ENTRYPOINT ["{{ repo_name }}"]
Expand Down
Loading
Loading