Skip to content
Merged
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
37 changes: 37 additions & 0 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: 16ecf4e
_src_path: gh:pdhall99/python-project-template
author_email: 20580126+pdhall99@users.noreply.github.com
author_name: PD Hall
copyright_year: 2026
docs_enabled: false
github_owner: pdhall99
keywords:
- annotation
- anywidget
- data labeling
- data labelling
- human in the loop
- information extraction
- jupyter
- named entity recognition
- ner
- nlp
- notebook
- sequence labeling
- sequence labelling
- span annotation
- text annotation
- text labeling
- text labelling
- widget
package_name: spanmark
project_description: Annotate text datasets with labelled spans in Jupyter and other
notebook environments
project_name: spanmark
python_support: eol
runtime_dependencies:
- anywidget
- filelock>=3.16
- ipython
- traitlets
28 changes: 28 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 2

# Each update waits a week before proposing a new release (cooldown), so a
# compromised release has time to be noticed before it reaches the project.
updates:
# Workflow actions are pinned to commit SHAs with version comments, which
# Dependabot updates together.
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
cooldown:
default-days: 7
groups:
github-actions:
patterns: ["*"]

# When this bumps ruff-pre-commit, bump ruff in pyproject.toml's check-code
# group to the same version in the same pull request.
- package-ecosystem: "pre-commit"
directory: "/"
schedule:
interval: "monthly"
cooldown:
default-days: 7
groups:
pre-commit:
patterns: ["*"]
203 changes: 58 additions & 145 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
- "[0-9]+.[0-9]+.[0-9]+"
pull_request:
branches: ["main"]
types: [ready_for_review]
workflow_dispatch:

permissions:
Expand All @@ -16,13 +15,10 @@ permissions:
env:
RUNNER: &runner "ubuntu-24.04"
JOB_TIMEOUT: &job_timeout 30
# The oldest supported Python: runs the tools, type checks and release checks.
TOOL_PYTHON_VERSION: "3.11"
HATCH_VERSION: "1.18.1"
HATCH_VERSION: "1.18.2"
UV_VERSION: "0.13.9"
DISTRIBUTION_NAME: "spanmark"
IMPORT_NAME: "spanmark"
DOCS_ENABLED: "false"
DOCS_DIR: "site"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -62,7 +58,6 @@ jobs:
timeout-minutes: *job_timeout
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
coverage_env: ${{ steps.matrix.outputs.coverage_env }}
coverage_python: ${{ steps.matrix.outputs.coverage_python }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand Down Expand Up @@ -106,19 +101,13 @@ jobs:
if not rows:
raise SystemExit("No Python versions found in the Hatch test matrix")

coverage = next(
(
row
for row in rows
if row["python"] == os.environ["TOOL_PYTHON_VERSION"]
),
rows[0],
)
# Coverage is measured on one Python only, the newest: its tracer
# (sys.monitoring with branches, 3.14+) has the lowest overhead.
coverage = max(rows, key=lambda row: tuple(map(int, row["python"].split("."))))

with open(os.environ["GITHUB_OUTPUT"], "a") as output:
matrix = json.dumps({"include": rows}, separators=(",", ":"))
print(f"matrix={matrix}", file=output)
print(f"coverage_env={coverage['environment']}", file=output)
print(f"coverage_python={coverage['python']}", file=output)
PY

Expand Down Expand Up @@ -151,146 +140,35 @@ jobs:
- name: Install hatch
run: uv tool install "hatch==$HATCH_VERSION"

- name: Run tests
- name: Run tests with coverage
if: matrix.python == needs.discover-tests.outputs.coverage_python
env:
TEST_ENVIRONMENT: ${{ matrix.environment }}
TEST_PYTHON: ${{ matrix.python }}
run: |
hatch test --python "$TEST_PYTHON" --cover
hatch run "$TEST_ENVIRONMENT:cov-report-markdown" >> "$GITHUB_STEP_SUMMARY"

- name: Rename coverage files
- name: Run tests
if: matrix.python != needs.discover-tests.outputs.coverage_python
env:
TEST_PYTHON: ${{ matrix.python }}
run: |
shopt -s nullglob
files=(.coverage*)
if ((${#files[@]} == 0)); then
echo "No coverage files found" >&2
exit 1
fi
for f in "${files[@]}"; do
mv "$f" "$f.$TEST_PYTHON"
done
run: hatch test --python "$TEST_PYTHON"

- name: Upload coverage files
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: coverage-${{ matrix.python }}
path: .coverage*
compression-level: 0
include-hidden-files: true
if-no-files-found: ignore

coverage:
name: Coverage report
if: github.ref_type != 'tag'
runs-on: *runner
timeout-minutes: *job_timeout
needs: [discover-tests, test]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
version: ${{ env.UV_VERSION }}
enable-cache: ${{ !startsWith(github.ref, 'refs/tags/') }} # zizmor: ignore[cache-poisoning] disabled for release tags

- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ needs.discover-tests.outputs.coverage_python }}

- name: Install hatch
run: uv tool install "hatch==$HATCH_VERSION"

- name: Download coverage artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: coverage*
merge-multiple: true

- name: Combine and report
env:
COVERAGE_ENVIRONMENT: ${{ needs.discover-tests.outputs.coverage_env }}
run: |
hatch run "$COVERAGE_ENVIRONMENT:cov-combine"
hatch run "$COVERAGE_ENVIRONMENT:cov-report"
hatch run "$COVERAGE_ENVIRONMENT:cov-report-markdown" >> "$GITHUB_STEP_SUMMARY"

- name: Upload HTML report
- name: Upload HTML coverage report
if: matrix.python == needs.discover-tests.outputs.coverage_python
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: coverage-report
path: htmlcov/

docs:
name: Build docs
if: github.ref_type != 'tag'
runs-on: *runner
timeout-minutes: *job_timeout
outputs:
enabled: ${{ steps.config.outputs.enabled }}
steps:
- name: Read docs configuration
id: config
run: echo "enabled=$DOCS_ENABLED" >> "$GITHUB_OUTPUT"

- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
if: steps.config.outputs.enabled == 'true'
with:
fetch-depth: 0
persist-credentials: false

- uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
if: steps.config.outputs.enabled == 'true'
with:
version: ${{ env.UV_VERSION }}
enable-cache: ${{ !startsWith(github.ref, 'refs/tags/') }} # zizmor: ignore[cache-poisoning] disabled for release tags

- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
if: steps.config.outputs.enabled == 'true'
with:
python-version: ${{ env.TOOL_PYTHON_VERSION }}

- name: Install hatch
if: steps.config.outputs.enabled == 'true'
run: uv tool install "hatch==$HATCH_VERSION"

- name: Build docs
if: steps.config.outputs.enabled == 'true'
run: hatch run docs:build

- name: Upload Pages artifact
if: steps.config.outputs.enabled == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4
with:
path: ${{ env.DOCS_DIR }}

pages:
name: Deploy docs
if: needs.docs.outputs.enabled == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: docs
runs-on: *runner
timeout-minutes: *job_timeout
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4

build:
name: Build package
runs-on: *runner
timeout-minutes: *job_timeout
needs: [precommit, test]
outputs:
distribution_name: ${{ steps.project.outputs.name }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand All @@ -309,6 +187,19 @@ jobs:
- name: Install hatch
run: uv tool install "hatch==$HATCH_VERSION"

- name: Read project name
id: project
run: |
python - <<'PY'
import os
import tomllib
from pathlib import Path

project = tomllib.loads(Path("pyproject.toml").read_text())["project"]
with open(os.environ["GITHUB_OUTPUT"], "a") as output:
print(f"name={project['name']}", file=output)
PY

- name: Validate release tag
if: github.ref_type == 'tag'
env:
Expand All @@ -330,6 +221,8 @@ jobs:

- name: Extract release notes
if: github.ref_type == 'tag'
env:
DISTRIBUTION_NAME: ${{ steps.project.outputs.name }}
run: |
mkdir -p release-notes
awk -v heading="## [$GITHUB_REF_NAME]" '
Expand Down Expand Up @@ -357,18 +250,37 @@ jobs:
- name: Build
run: hatch build

- name: Smoke-test release wheel
if: github.ref_type == 'tag'
# Runs on every build, so packaging problems show up before a release.
# Only a release tag also checks the version against the tag.
- name: Smoke-test wheel
env:
TAG: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
run: |
uv venv --python "$TOOL_PYTHON_VERSION" /tmp/package-smoke
uv pip install --python /tmp/package-smoke/bin/python dist/*.whl
TAG="$GITHUB_REF_NAME" /tmp/package-smoke/bin/python - <<'PY'
/tmp/package-smoke/bin/python - <<'PY'
import os
from email.parser import HeaderParser
from importlib import import_module
from importlib.metadata import version

assert version(os.environ["DISTRIBUTION_NAME"]) == os.environ["TAG"]
import_module(os.environ["IMPORT_NAME"])
from pathlib import Path
from zipfile import ZipFile

# Both names come from the wheel's own metadata (PEP 794 Import-Name).
(wheel,) = Path("dist").glob("*.whl")
with ZipFile(wheel) as zf:
(meta,) = [n for n in zf.namelist() if n.endswith(".dist-info/METADATA")]
metadata = HeaderParser().parsestr(zf.read(meta).decode())

name = metadata["Name"]
import_names = [
n.split(";")[0].strip() for n in metadata.get_all("Import-Name", [])
]
assert import_names, f"{wheel.name} has no Import-Name: set import-names"
if os.environ["TAG"]:
assert version(name) == os.environ["TAG"], (version(name), os.environ["TAG"])
for import_name in import_names:
import_module(import_name)
PY

- name: Upload release distributions
Expand All @@ -395,7 +307,7 @@ jobs:
- test
- build
steps:
- name: Require precommit, test, build
- name: Require every check
env:
PRECOMMIT: ${{ needs.precommit.result }}
TEST: ${{ needs.test.result }}
Expand All @@ -411,7 +323,7 @@ jobs:
runs-on: *runner
environment:
name: pypi
url: https://pypi.org/project/spanmark/
url: ${{ format('https://pypi.org/project/{0}/', needs.build.outputs.distribution_name) }}
timeout-minutes: *job_timeout
needs: build
permissions:
Expand All @@ -432,7 +344,7 @@ jobs:
if: github.ref_type == 'tag'
runs-on: *runner
timeout-minutes: *job_timeout
needs: pypi
needs: [build, pypi]
permissions:
contents: write
steps:
Expand All @@ -452,6 +364,7 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
DISTRIBUTION_NAME: ${{ needs.build.outputs.distribution_name }}
run: |
gh release create "$GITHUB_REF_NAME" dist/* \
--title "$DISTRIBUTION_NAME $GITHUB_REF_NAME" \
Expand Down
Loading
Loading