Skip to content

Commit 289c5d7

Browse files
rnorthclaude
andauthored
Modernise build tooling: switch to uv (#35)
* Add .worktrees/ to .gitignore for git worktree support Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Modernise build tooling: switch to uv for dependency management - Replace setup.py/setup.cfg/requirements.txt with pyproject.toml - Add uv to .mise.toml managed tools, remove manual venv config - Update CI workflow to use astral-sh/setup-uv and uv commands - Update publish workflow to use uv build/publish with OIDC trusted publishers - Add AGENTS.md with updated setup/test instructions - Add uv.lock to .gitignore (library, not application) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Replace flake8 with ruff; fix uv dev dependency group - Switch from [project.optional-dependencies] to [dependency-groups] so that `uv sync --dev` correctly installs dev dependencies - Replace flake8 with ruff in the CI workflow - Remove dead `found_block` variables in resolver.py caught by ruff Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 048fecb commit 289c5d7

File tree

10 files changed

+105
-84
lines changed

10 files changed

+105
-84
lines changed
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
1+
# This workflow will install Python dependencies, run tests and lint with uv
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
33

44
name: Python package
@@ -20,22 +20,14 @@ jobs:
2020
python-version: ["3.11"]
2121

2222
steps:
23-
- uses: actions/checkout@v2
24-
- name: Set up Python ${{ matrix.python-version }}
25-
uses: actions/setup-python@v2
23+
- uses: actions/checkout@v4
24+
- name: Install uv
25+
uses: astral-sh/setup-uv@v5
2626
with:
2727
python-version: ${{ matrix.python-version }}
2828
- name: Install dependencies
29-
run: |
30-
python -m pip install --upgrade pip
31-
pip install flake8 pytest
32-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
33-
- name: Lint with flake8
34-
run: |
35-
# stop the build if there are Python syntax errors or undefined names
36-
flake8 codeinclude tests --count --select=E9,F63,F7,F82 --show-source --statistics
37-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
38-
flake8 codeinclude tests --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
29+
run: uv sync --dev
30+
- name: Lint with ruff
31+
run: uv run ruff check codeinclude tests
3932
- name: Test with pytest
40-
run: |
41-
pytest
33+
run: uv run pytest
Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This workflows will upload a Python Package using Twine when a release is created
1+
# This workflow uploads a Python Package using uv when a release is created
22
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
33

44
name: Upload Python Package
@@ -11,21 +11,16 @@ jobs:
1111
deploy:
1212

1313
runs-on: ubuntu-latest
14+
permissions:
15+
id-token: write
1416

1517
steps:
16-
- uses: actions/checkout@v2
17-
- name: Set up Python
18-
uses: actions/setup-python@v2
18+
- uses: actions/checkout@v4
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v5
1921
with:
20-
python-version: '3.11'
21-
- name: Install dependencies
22-
run: |
23-
python -m pip install --upgrade pip
24-
pip install setuptools wheel twine
25-
- name: Build and publish
26-
env:
27-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
28-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
29-
run: |
30-
python setup.py sdist bdist_wheel
31-
twine upload dist/*
22+
python-version: "3.11"
23+
- name: Build package
24+
run: uv build
25+
- name: Publish to PyPI
26+
run: uv publish

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.worktrees/
12
*.egg-info/
23
.vscode/
34
.direnv/
@@ -9,4 +10,5 @@ __pycache__/
910
.DS_Store
1011
.venv/
1112
build/
12-
dist/
13+
dist/
14+
uv.lock

.mise.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
[tools]
22
python = "3.11"
3-
4-
[env]
5-
_.python.venv = { path = ".venv", create = true }
3+
uv = "latest"

AGENTS.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Agent Instructions
2+
3+
## Project
4+
5+
mkdocs-codeinclude-plugin — an MkDocs plugin that includes code snippets into documentation pages.
6+
7+
## Setup
8+
9+
- Use `mise` for tool version management (see `.mise.toml`)
10+
- `mise install` to install python and uv
11+
- `uv sync --dev` to install the plugin and dev dependencies
12+
13+
## Testing
14+
15+
- Run tests with `uv run pytest tests/`
16+
- Always run the full test suite before committing
17+
18+
## Architecture
19+
20+
- `codeinclude/plugin.py` — MkDocs plugin hook that finds `<!--codeinclude-->` blocks in markdown and substitutes code snippets
21+
- `codeinclude/resolver.py` — selects lines/blocks from source files (by line numbers, block name, or inside_block)
22+
- `codeinclude/languages.py` — maps file extensions to language identifiers via pygments
23+
- `tests/codeinclude/` — unit tests; fixtures live in `tests/codeinclude/fixture/`
24+
25+
## Title modes
26+
27+
The plugin supports multiple code block title formats via the `title_mode` config option:
28+
29+
- `pymdownx.tabbed` (default) — `=== "title"` with 4-space indented content
30+
- `legacy_pymdownx.superfences``` ```lang tab="title" ``
31+
- `mkdocs-material``` ```lang title="title" ``
32+
- `none` — no title
33+
34+
## Releases
35+
36+
- Versioning is handled by `setuptools-scm` (derives version from git tags)
37+
- Publishing to PyPI is triggered automatically when a GitHub release is published
38+
- CI runs on Python 3.11

codeinclude/resolver.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ def select(
2929
if block:
3030
i = 0
3131
delim_count = 0
32-
found_block = False
3332
for line in text.splitlines():
3433
first_line_of_block = False
3534
i = i + 1
3635
if block in line and delim_count <= 0:
37-
found_block = True
3836
delim_count = 0
3937
first_line_of_block = True
4038
delim_count += line.count("{")
@@ -52,13 +50,11 @@ def select(
5250
if inside_block:
5351
delim_count = 0
5452
inside_matching = False
55-
found_block = False
5653
for line_number, line in enumerate(text.splitlines(), start=1):
5754
first_line_of_block = False
5855

5956
# Detect the block beginning
6057
if inside_block in line and delim_count <= 0:
61-
found_block = True
6258
delim_count = 0
6359
first_line_of_block = True
6460
inside_matching = True

pyproject.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "setuptools-scm>=8"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "mkdocs-codeinclude-plugin"
7+
dynamic = ["version"]
8+
description = "A plugin to include code snippets into mkdocs pages"
9+
readme = "README.md"
10+
license = "MIT"
11+
authors = [
12+
{ name = "Richard North", email = "rich.north@gmail.com" }
13+
]
14+
keywords = ["mkdocs", "python", "markdown", "codeinclude"]
15+
classifiers = [
16+
"Intended Audience :: Developers",
17+
"Intended Audience :: Information Technology",
18+
"Programming Language :: Python",
19+
"Programming Language :: Python :: 3 :: Only",
20+
"Programming Language :: Python :: 3.11",
21+
]
22+
requires-python = ">=3.11"
23+
dependencies = [
24+
"mkdocs>=1.2",
25+
"pygments>=2.9.0",
26+
]
27+
28+
[project.urls]
29+
Homepage = "https://github.com/rnorth/mkdocs-codeinclude-plugin"
30+
31+
[dependency-groups]
32+
dev = [
33+
"pytest",
34+
"ruff",
35+
]
36+
37+
[project.entry-points."mkdocs.plugins"]
38+
codeinclude = "codeinclude.plugin:CodeIncludePlugin"
39+
40+
[tool.setuptools.packages.find]
41+
where = ["."]
42+
include = ["codeinclude*"]
43+
44+
[tool.setuptools_scm]

requirements.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

setup.cfg

Whitespace-only changes.

setup.py

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

0 commit comments

Comments
 (0)