Skip to content

Commit de4f36c

Browse files
authored
build: upgrade scaffolding
1 parent 8cebf2e commit de4f36c

File tree

13 files changed

+195
-3848
lines changed

13 files changed

+195
-3848
lines changed

.copier-answers.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
_commit: v1.5.0
2+
_src_path: gh:superlinear-ai/substrate
3+
author_email: laurent@superlinear.eu
4+
author_name: Laurent Sorber
5+
project_description: wtpsplit with minimal dependencies
6+
project_name: wtpsplit-lite
7+
project_type: package
8+
project_url: https://github.com/superlinear-ai/wtpsplit-lite
9+
python_version: '3.10'
10+
typing: strict
11+
with_conventional_commits: true
12+
with_typer_cli: false

.cruft.json

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

.devcontainer/devcontainer.json

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
"dockerComposeFile": "../docker-compose.yml",
44
"service": "devcontainer",
55
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}/",
6-
"remoteUser": "user",
6+
"features": {
7+
"ghcr.io/devcontainers-extra/features/starship:1": {}
8+
},
79
"overrideCommand": true,
8-
"postStartCommand": "cp --update /opt/build/poetry/poetry.lock /workspaces/${localWorkspaceFolderBasename}/ && mkdir -p /workspaces/${localWorkspaceFolderBasename}/.git/hooks/ && cp --update /opt/build/git/* /workspaces/${localWorkspaceFolderBasename}/.git/hooks/",
10+
"remoteUser": "user",
11+
"postStartCommand": "sudo chown -R user:user /opt/ && uv sync --python ${localEnv:PYTHON_VERSION:3.10} --resolution ${localEnv:RESOLUTION_STRATEGY:highest} --all-extras && pre-commit install --install-hooks",
912
"customizations": {
13+
"jetbrains": {
14+
"backend": "PyCharm",
15+
"plugins": [
16+
"com.github.copilot"
17+
]
18+
},
1019
"vscode": {
1120
"extensions": [
1221
"charliermarsh.ruff",
@@ -41,25 +50,30 @@
4150
100
4251
],
4352
"files.autoSave": "onFocusChange",
53+
"github.copilot.chat.agent.enabled": true,
54+
"github.copilot.chat.edits.codesearch.enabled": true,
4455
"github.copilot.chat.edits.enabled": true,
45-
"jupyter.kernels.excludePythonEnvironments": ["/usr/local/bin/python"],
56+
"github.copilot.nextEditSuggestions.enabled": true,
57+
"jupyter.kernels.excludePythonEnvironments": [
58+
"/usr/local/bin/python"
59+
],
4660
"mypy-type-checker.importStrategy": "fromEnvironment",
4761
"mypy-type-checker.preferDaemon": true,
4862
"notebook.codeActionsOnSave": {
4963
"notebook.source.fixAll": "explicit",
5064
"notebook.source.organizeImports": "explicit"
5165
},
5266
"notebook.formatOnSave.enabled": true,
53-
"python.defaultInterpreterPath": "/opt/wtpsplit-lite-env/bin/python",
67+
"python.defaultInterpreterPath": "/opt/venv/bin/python",
5468
"python.terminal.activateEnvironment": false,
5569
"python.testing.pytestEnabled": true,
5670
"ruff.importStrategy": "fromEnvironment",
5771
"ruff.logLevel": "warning",
58-
"terminal.integrated.defaultProfile.linux": "zsh",
59-
"terminal.integrated.profiles.linux": {
60-
"zsh": {
61-
"path": "/usr/bin/zsh"
62-
}
72+
"terminal.integrated.env.linux": {
73+
"GIT_EDITOR": "code --wait"
74+
},
75+
"terminal.integrated.env.mac": {
76+
"GIT_EDITOR": "code --wait"
6377
}
6478
}
6579
}

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@
33

44
# Git
55
.git/
6+
7+
# Python
8+
.venv/

.github/workflows/publish.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,18 @@ on:
88
jobs:
99
publish:
1010
runs-on: ubuntu-latest
11+
environment: pypi
12+
permissions:
13+
id-token: write
1114

1215
steps:
1316
- name: Checkout
1417
uses: actions/checkout@v4
1518

16-
- name: Set up Python
17-
uses: actions/setup-python@v5
18-
with:
19-
python-version: "3.10"
20-
21-
- name: Install Poetry
22-
run: pip install --no-input poetry
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v5
2321

2422
- name: Publish package
2523
run: |
26-
poetry config pypi-token.pypi "${{ secrets.POETRY_PYPI_TOKEN_PYPI }}"
27-
poetry publish --build
24+
uv build
25+
uv publish

.github/workflows/test.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
python-version: ["3.10"]
17+
python-version: ["3.10", "3.12"]
18+
resolution-strategy: ["highest", "lowest-direct"]
1819

19-
name: Python ${{ matrix.python-version }}
20+
name: Python ${{ matrix.python-version }} (resolution=${{ matrix.resolution-strategy }})
2021

2122
steps:
2223
- name: Checkout
@@ -28,20 +29,18 @@ jobs:
2829
node-version: 23
2930

3031
- name: Install @devcontainers/cli
31-
run: npm install --location=global @devcontainers/cli@0.72.0
32+
run: npm install --location=global @devcontainers/cli@0.73.0
3233

3334
- name: Start Dev Container
3435
run: |
3536
git config --global init.defaultBranch main
36-
PYTHON_VERSION=${{ matrix.python-version }} devcontainer up --workspace-folder .
37+
devcontainer up --workspace-folder .
38+
env:
39+
PYTHON_VERSION: ${{ matrix.python-version }}
40+
RESOLUTION_STRATEGY: ${{ matrix.resolution-strategy }}
3741

3842
- name: Lint package
3943
run: devcontainer exec --workspace-folder . poe lint
4044

4145
- name: Test package
4246
run: devcontainer exec --workspace-folder . poe test
43-
44-
- name: Upload coverage
45-
uses: codecov/codecov-action@v5
46-
with:
47-
files: reports/coverage.xml

.gitignore

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
htmlcov/
33
reports/
44

5-
# cruft
5+
# Copier
66
*.rej
77

88
# Data
@@ -30,17 +30,16 @@ notebooks/
3030
# macOS
3131
.DS_Store
3232

33+
# mise
34+
mise.local.toml
35+
3336
# mypy
3437
.dmypy.json
3538
.mypy_cache/
3639

3740
# Node.js
3841
node_modules/
3942

40-
# Poetry
41-
.venv/
42-
dist/
43-
4443
# PyCharm
4544
.idea/
4645

@@ -52,13 +51,19 @@ dist/
5251

5352
# Python
5453
__pycache__/
54+
*.egg-info/
5555
*.py[cdo]
56+
.venv/
57+
dist/
5658

5759
# Ruff
5860
.ruff_cache/
5961

6062
# Terraform
6163
.terraform/
6264

65+
# uv
66+
uv.lock
67+
6368
# VS Code
6469
.vscode/

.pre-commit-config.yaml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ repos:
1616
- id: rst-inline-touching-normal
1717
- id: text-unicode-replacement-char
1818
- repo: https://github.com/pre-commit/pre-commit-hooks
19-
rev: v4.5.0
19+
rev: v5.0.0
2020
hooks:
2121
- id: check-added-large-files
2222
- id: check-ast
2323
- id: check-builtin-literals
2424
- id: check-case-conflict
2525
- id: check-docstring-first
26+
- id: check-illegal-windows-names
2627
- id: check-json
2728
- id: check-merge-conflict
2829
- id: check-shebang-scripts-are-executable
@@ -65,17 +66,6 @@ repos:
6566
require_serial: true
6667
language: system
6768
types_or: [python, pyi]
68-
- id: shellcheck
69-
name: shellcheck
70-
entry: shellcheck
71-
args: [--check-sourced]
72-
language: system
73-
types: [shell]
74-
- id: poetry-check
75-
name: poetry check
76-
entry: poetry check
77-
language: system
78-
pass_filenames: false
7969
- id: mypy
8070
name: mypy
8171
entry: mypy

Dockerfile

Lines changed: 18 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,29 @@
11
# syntax=docker/dockerfile:1
2-
ARG PYTHON_VERSION=3.10
3-
FROM python:$PYTHON_VERSION-slim AS base
2+
FROM ghcr.io/astral-sh/uv:python3.10-bookworm AS dev
43

5-
# Remove docker-clean so we can keep the apt cache in Docker build cache.
6-
RUN rm /etc/apt/apt.conf.d/docker-clean
4+
# Create and activate a virtual environment [1].
5+
# [1] https://docs.astral.sh/uv/concepts/projects/config/#project-environment-path
6+
ENV VIRTUAL_ENV=/opt/venv
7+
ENV PATH=$VIRTUAL_ENV/bin:$PATH
8+
ENV UV_PROJECT_ENVIRONMENT=$VIRTUAL_ENV
79

8-
# Configure Python to print tracebacks on crash [1], and to not buffer stdout and stderr [2].
9-
# [1] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONFAULTHANDLER
10-
# [2] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED
11-
ENV PYTHONFAULTHANDLER 1
12-
ENV PYTHONUNBUFFERED 1
10+
# Tell Git that the workspace is safe to avoid 'detected dubious ownership in repository' warnings.
11+
RUN git config --system --add safe.directory '*'
1312

14-
# Create a non-root user and switch to it [1].
13+
# Create a non-root user and give it passwordless sudo access [1].
1514
# [1] https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
16-
ARG UID=1000
17-
ARG GID=$UID
18-
RUN groupadd --gid $GID user && \
19-
useradd --create-home --gid $GID --uid $UID user --no-log-init && \
20-
chown user /opt/
21-
USER user
22-
23-
# Create and activate a virtual environment.
24-
ENV VIRTUAL_ENV /opt/wtpsplit-lite-env
25-
ENV PATH $VIRTUAL_ENV/bin:$PATH
26-
RUN python -m venv $VIRTUAL_ENV
27-
28-
# Set the working directory.
29-
WORKDIR /workspaces/wtpsplit-lite/
30-
31-
32-
33-
FROM base AS poetry
34-
35-
USER root
36-
37-
# Install Poetry in separate venv so it doesn't pollute the main venv.
38-
ENV POETRY_VERSION 1.8.0
39-
ENV POETRY_VIRTUAL_ENV /opt/poetry-env
40-
RUN --mount=type=cache,target=/root/.cache/pip/ \
41-
python -m venv $POETRY_VIRTUAL_ENV && \
42-
$POETRY_VIRTUAL_ENV/bin/pip install poetry~=$POETRY_VERSION && \
43-
ln -s $POETRY_VIRTUAL_ENV/bin/poetry /usr/local/bin/poetry
44-
45-
# Install compilers that may be required for certain packages or platforms.
46-
RUN --mount=type=cache,target=/var/cache/apt/ \
47-
--mount=type=cache,target=/var/lib/apt/ \
48-
apt-get update && \
49-
apt-get install --no-install-recommends --yes build-essential
50-
51-
USER user
52-
53-
# Install the run time Python dependencies in the virtual environment.
54-
COPY --chown=user:user poetry.lock* pyproject.toml /workspaces/wtpsplit-lite/
55-
RUN mkdir -p /home/user/.cache/pypoetry/ && mkdir -p /home/user/.config/pypoetry/ && \
56-
mkdir -p src/wtpsplit_lite/ && touch src/wtpsplit_lite/__init__.py && touch README.md
57-
RUN --mount=type=cache,uid=$UID,gid=$GID,target=/home/user/.cache/pypoetry/ \
58-
poetry install --only main --all-extras --no-interaction
59-
60-
61-
62-
FROM poetry AS dev
63-
64-
# Install development tools: curl, git, gpg, ssh, starship, sudo, vim, and zsh.
65-
USER root
6615
RUN --mount=type=cache,target=/var/cache/apt/ \
6716
--mount=type=cache,target=/var/lib/apt/ \
68-
apt-get update && \
69-
apt-get install --no-install-recommends --yes curl git gnupg ssh sudo vim zsh && \
70-
sh -c "$(curl -fsSL https://starship.rs/install.sh)" -- "--yes" && \
71-
usermod --shell /usr/bin/zsh user && \
17+
groupadd --gid 1000 user && \
18+
useradd --create-home --no-log-init --gid 1000 --uid 1000 --shell /usr/bin/bash user && \
19+
chown user:user /opt/ && \
20+
apt-get update && apt-get install --no-install-recommends --yes sudo && \
7221
echo 'user ALL=(root) NOPASSWD:ALL' > /etc/sudoers.d/user && chmod 0440 /etc/sudoers.d/user
73-
RUN git config --system --add safe.directory '*'
7422
USER user
7523

76-
# Install the development Python dependencies in the virtual environment.
77-
RUN --mount=type=cache,uid=$UID,gid=$GID,target=/home/user/.cache/pypoetry/ \
78-
poetry install --all-extras --no-interaction
79-
80-
# Persist output generated during docker build so that we can restore it in the dev container.
81-
COPY --chown=user:user .pre-commit-config.yaml /workspaces/wtpsplit-lite/
82-
RUN mkdir -p /opt/build/poetry/ && cp poetry.lock /opt/build/poetry/ && \
83-
git init && pre-commit install --install-hooks && \
84-
mkdir -p /opt/build/git/ && cp .git/hooks/commit-msg .git/hooks/pre-commit /opt/build/git/
85-
8624
# Configure the non-root user's shell.
87-
ENV ANTIDOTE_VERSION 1.8.6
88-
RUN git clone --branch v$ANTIDOTE_VERSION --depth=1 https://github.com/mattmc3/antidote.git ~/.antidote/ && \
89-
echo 'zsh-users/zsh-syntax-highlighting' >> ~/.zsh_plugins.txt && \
90-
echo 'zsh-users/zsh-autosuggestions' >> ~/.zsh_plugins.txt && \
91-
echo 'source ~/.antidote/antidote.zsh' >> ~/.zshrc && \
92-
echo 'antidote load' >> ~/.zshrc && \
93-
echo 'eval "$(starship init zsh)"' >> ~/.zshrc && \
94-
echo 'HISTFILE=~/.history/.zsh_history' >> ~/.zshrc && \
95-
echo 'HISTSIZE=1000' >> ~/.zshrc && \
96-
echo 'SAVEHIST=1000' >> ~/.zshrc && \
97-
echo 'setopt share_history' >> ~/.zshrc && \
98-
echo 'bindkey "^[[A" history-beginning-search-backward' >> ~/.zshrc && \
99-
echo 'bindkey "^[[B" history-beginning-search-forward' >> ~/.zshrc && \
100-
mkdir ~/.history/ && \
101-
zsh -c 'source ~/.zshrc'
25+
RUN mkdir ~/.history/ && \
26+
echo 'HISTFILE=~/.history/.bash_history' >> ~/.bashrc && \
27+
echo 'bind "\"\e[A\": history-search-backward"' >> ~/.bashrc && \
28+
echo 'bind "\"\e[B\": history-search-forward"' >> ~/.bashrc && \
29+
echo 'eval "$(starship init bash)"' >> ~/.bashrc

0 commit comments

Comments
 (0)