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
64 changes: 48 additions & 16 deletions .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ name: Release
on:
push:
branches: [main]
# Version bumps typically touch these; pyproject is the gate.
paths:
- "pyproject.toml"
- "sinonym/**"
workflow_dispatch: # Allow manual triggering
workflow_dispatch:

# Avoid overlapping publishes on rapid pushes
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
Expand All @@ -23,17 +27,22 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history for version comparison
fetch-depth: 0 # need history for version comparison

- uses: actions/setup-python@v5
with:
python-version: "3.11"

- uses: astral-sh/setup-uv@v6

- name: Detect version change (pyproject.toml)
id: decide
shell: bash
run: |
BEFORE_SHA="${{ github.event.before }}"
echo "BEFORE_SHA=$BEFORE_SHA"
# Use Python's stdlib tomllib to read versions
python - <<'PY'
import os, subprocess, tomllib, sys
import os, subprocess, tomllib
out = open(os.environ["GITHUB_OUTPUT"], "a")
with open("pyproject.toml","rb") as f:
new_version = tomllib.load(f)["project"]["version"]
Expand All @@ -54,25 +63,47 @@ jobs:
out.write(f"should_publish={should}\n")
PY

- uses: actions/setup-python@v5
- name: Install dev deps
if: steps.decide.outputs.should_publish == 'true'
with:
python-version: "3.11"
run: uv sync --group dev

- uses: astral-sh/setup-uv@v6
- name: Run tests
if: steps.decide.outputs.should_publish == 'true'
run: uv run pytest -q

- name: Install dependencies
- name: Build sdist + wheel
if: steps.decide.outputs.should_publish == 'true'
run: uv sync --dev
run: uv build

- name: Run tests
- name: Validate metadata (twine check)
if: steps.decide.outputs.should_publish == 'true'
run: uv run pytest tests/ -v
run: uvx twine check dist/*

- name: Build sdist+wheel (uv)
- name: Smoke test import from sdist
if: steps.decide.outputs.should_publish == 'true'
run: uv build
run: |
uv pip install --system dist/*.tar.gz --force-reinstall
cd /tmp
python -c "import sinonym; print('✓ sdist import OK:', sinonym.__file__)"

- name: Smoke test import from wheel + resources
if: steps.decide.outputs.should_publish == 'true'
run: |
uv pip install --system dist/*.whl --force-reinstall
cd /tmp
python - <<'PY'
import sys, sinonym
print("✓ Wheel import OK")
print("PY:", sys.executable)
print("sinonym from:", sinonym.__file__)
try:
import importlib.resources as ir
files = list((ir.files("sinonym.data")).iterdir())
print("✓ data files present:", [f.name for f in files][:8], "…")
except Exception as e:
print("! data access failed:", e)
raise
PY

- uses: actions/upload-artifact@v4
if: steps.decide.outputs.should_publish == 'true'
Expand All @@ -84,6 +115,7 @@ jobs:
needs: build
if: needs.build.outputs.should_publish == 'true'
runs-on: ubuntu-latest
environment: pypi # optional, matches a protected env if you use one
permissions:
id-token: write
contents: read
Expand All @@ -96,4 +128,4 @@ jobs:
- name: Publish to PyPI (Trusted Publishing)
uses: pypa/gh-action-pypi-publish@release/v1
with:
print-hash: true
print-hash: true
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "sinonym"
version = "0.1.0"
version = "0.1.1"
description = "Chinese Name Detection and Normalization Module"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
5 changes: 4 additions & 1 deletion sinonym/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
romanization systems with robust filtering capabilities.
"""

__version__ = "0.1.0"
import importlib.metadata

__version__ = importlib.metadata.version("sinonym")
__all__ = ["ChineseNameDetector"]


def __getattr__(name):
"""Lazy import to avoid eager loading of heavy dependencies."""
if name == "ChineseNameDetector":
from .detector import ChineseNameDetector

return ChineseNameDetector
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.