From fb09f9116c18e8da40ac2c0783b720d075c682e4 Mon Sep 17 00:00:00 2001 From: Sergey Feldman Date: Sun, 31 Aug 2025 17:22:35 -0700 Subject: [PATCH] pypi??? --- .github/workflows/workflow.yaml | 64 ++++++++++++++++++++++++--------- pyproject.toml | 2 +- sinonym/__init__.py | 5 ++- uv.lock | 2 +- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 979b751..32e7e52 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -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 @@ -23,7 +27,13 @@ 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 @@ -31,9 +41,8 @@ jobs: 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"] @@ -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' @@ -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 @@ -96,4 +128,4 @@ jobs: - name: Publish to PyPI (Trusted Publishing) uses: pypa/gh-action-pypi-publish@release/v1 with: - print-hash: true \ No newline at end of file + print-hash: true diff --git a/pyproject.toml b/pyproject.toml index 0a82bf1..dce9fe6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/sinonym/__init__.py b/sinonym/__init__.py index 77b78a2..4138bde 100644 --- a/sinonym/__init__.py +++ b/sinonym/__init__.py @@ -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}'") diff --git a/uv.lock b/uv.lock index 2354b7c..3e9dac3 100644 --- a/uv.lock +++ b/uv.lock @@ -641,7 +641,7 @@ wheels = [ [[package]] name = "sinonym" -version = "0.1.0" +version = "0.1.1" source = { editable = "." } dependencies = [ { name = "joblib" },