diff --git a/.devcontainer/on_create_command.sh b/.devcontainer/on_create_command.sh index ddc1c92..8562b17 100755 --- a/.devcontainer/on_create_command.sh +++ b/.devcontainer/on_create_command.sh @@ -3,8 +3,10 @@ set -ex -pip install -U pip setuptools wheel setuptools_scm -pip install -r requirements-dev.txt +curl -LsSf https://astral.sh/uv/install.sh | sh +. $HOME/.cargo/env +uv tool install -U ruff +uv tool install -U tox --with tox-uv # Install Transifex CLI tool into /usr/local/bin # refer to Installation instructions https://github.com/transifex/cli#installation diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ac05fd0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,137 @@ +name: Test +on: + push: + paths-ignore: + - 'doc/**' + pull_request: + paths-ignore: + - 'doc/**' + release: + types: [released] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + fail-fast: false + max-parallel: 5 + matrix: + python-version: [3.9, '3.10', '3.11', '3.12', '3.13'] + + steps: + - name: Print github context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo $GITHUB_CONTEXT + + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Set up Python ${{ matrix.python-version }} + uses: astral-sh/setup-uv@v3 + with: + enable-cache: true + cache-dependency-glob: "pyproject.toml" + cache-suffix: ${{ matrix.python-version }} + + - name: Install Python + run: uv python install ${{ matrix.python-version }} + env: + UV_PYTHON_PREFERENCE: only-managed + + - name: Install Transifex CLI + run: | + curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash + mv tx /usr/local/bin/tx + + - name: Tox tests + run: uv run --only-dev tox -- -v --durations=25 + + build: + name: build distribution + if: github.repository_owner == 'sphinx-doc' && github.ref == 'refs/heads/master' + needs: + - tests + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Set up Python + uses: astral-sh/setup-uv@v3 + + - name: build package + run: uv build + + - name: upload artifact + uses: actions/upload-artifact@v4 + with: + name: distributions + path: dist/ + + pypi-publish: + name: Upload release to PyPI + if: github.repository_owner == 'sphinx-doc' && startsWith(github.ref, 'refs/tags/') + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/sphinx-intl + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: distributions + path: dist/ + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + verbose: true + + # for test + password: ${{ secrets.TESTPYPI_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + + # for production + # password: ${{ secrets.PYPI_TOKEN }} + + github-release: + name: GitHub release + if: github.repository_owner == 'sphinx-doc' + runs-on: ubuntu-latest + needs: + - pypi-publish + environment: release + permissions: + contents: write # for softprops/action-gh-release to create GitHub release + + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Get release version + id: get_version + uses: actions/github-script@v7 + with: + script: core.setOutput('version', context.ref.replace("refs/tags/", "")) + + - name: Create GitHub release + uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + name: "sphinx-intl ${{ steps.get_version.outputs.version }}" + body: "Changelog: https://sphinx-intl.readthedocs.io/en/master/changes.html" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 1cc9dbd..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,80 +0,0 @@ -name: Test -on: - push: - paths-ignore: - - 'doc/**' - pull_request: - paths-ignore: - - 'doc/**' - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} - cancel-in-progress: true - -jobs: - tests: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - python-version: [3.9, '3.10', '3.11', '3.12', '3.13'] - max-parallel: 1 - - steps: - - name: Print github context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo $GITHUB_CONTEXT - - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - - name: Setup python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - allow-prereleases: true - cache: 'pip' - - - name: Install tox and test related - run: | - python -m pip install --upgrade pip - pip install tox tox-gh-actions - - - name: Install Transifex CLI - run: | - curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash - mv tx /usr/local/bin/tx - - - name: Run tox - run: | - python -V - tox -- -v --durations=25 - - lint: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - env: [lint, mypy] - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 1 - - - name: Setup python - uses: actions/setup-python@v5 - with: - python-version: 3.9 - - - name: Install tox and any other dependencies for test - run: | - python -m pip install --upgrade pip - pip install tox tox-gh-actions - - - name: Run tox - run: tox -e ${{ matrix.env }} diff --git a/.gitignore b/.gitignore index c1f2627..ac2022e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +uv.lock + # Created by https://www.toptal.com/developers/gitignore/api/python # Edit at https://www.toptal.com/developers/gitignore?templates=python diff --git a/MANIFEST.in b/MANIFEST.in index e90b104..a9047bf 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,4 @@ include *.rst -include requirements-*.txt include tox.ini recursive-include tests * prune tests/__pycache__ diff --git a/checklist.rst b/checklist.rst index 488f137..629c5b5 100644 --- a/checklist.rst +++ b/checklist.rst @@ -2,12 +2,8 @@ Procedure: -1. check GitHub Actions test results: https://github.com/sphinx-doc/sphinx-intl/actions -2. update release version/date in ``CHANGES.rst`` -3. ``python -m build``, see details: setup.cfg -4. ``twine upload dist/`` -5. check PyPI page: https://pypi.org/p/sphinx-intl -6. tagging with version name that MUST following semver. e.g.: ``git tag 1.0.1`` -7. ``git push --tags`` to push tag -8. bump version in ``sphinx_intl/__init__.py`` and ``CHANGES.rst`` then commit/push - them onto GitHub +1. update release version/date in ``CHANGES.rst`` +2. create GitHub Release with new version tag, it will create a release on PyPI. + tag MUST following semver. e.g.: ``2.3.1`` +3. check PyPI page: https://pypi.org/p/sphinx-intl +4. bump version in ``CHANGES.rst`` then commit/push it onto GitHub diff --git a/doc/dev.rst b/doc/dev.rst index cf94e24..62c6945 100644 --- a/doc/dev.rst +++ b/doc/dev.rst @@ -18,8 +18,8 @@ Setup development environment * Requires supported Python version * Do setup under sphinx-intl.git repository root as:: - $ pip install -U pip setuptools wheel setuptools_scm - $ pip install -r requirements-dev.txt + $ pip install -U uv + $ uv sync * Install Transifex CLI tool (refer to `Installation instructions `_):: diff --git a/pyproject.toml b/pyproject.toml index b937b8b..ca4b851 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,14 @@ test = [ "pytest", ] +[dependency-groups] +dev = [ + "pytest", + "ruff>=0.8.0", + "tox-gh-actions>=3.2.0", + "tox-uv>=1.16.0", +] + [project.urls] Homepage = "https://github.com/sphinx-doc/sphinx-intl" Documentation = "https://sphinx-intl.readthedocs.io" @@ -46,16 +54,19 @@ Documentation = "https://sphinx-intl.readthedocs.io" [project.scripts] sphinx-intl = "sphinx_intl.commands:main" +[build-system] +requires = ["setuptools>=64", "setuptools_scm>=8"] +build-backend = "setuptools.build_meta" + [tool.setuptools] include-package-data = true -[tool.setuptools.dynamic] -version = {attr = "sphinx_intl.__version__"} - -[build-system] -requires = ["setuptools", "wheel"] -build-backend = "setuptools.build_meta" +[tool.setuptools_scm] +# this empty section means: use_scm_version=True [tool.mypy] ignore_missing_imports = true strict_optional = false + +[tool.uv.sources] +sphinx-intl = { workspace = true } diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 5b80acd..0000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,6 +0,0 @@ --e.[test] -build -twine -wheel -tox-uv -ruff diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 6f4d040..0000000 --- a/setup.cfg +++ /dev/null @@ -1,17 +0,0 @@ -# 1. initialize -# $ pip install -U build twine - -# 2. TEST build & release: -# $ rm -Rf build/ -# $ python -m build -# $ twine upload --repository-url https://test.pypi.org/legacy/ dist/* - -# 3. PRODUCTION build & release: -# $ rm -Rf build/ -# $ rm setup.cfg -# $ python -m build -# $ twine upload dist/* - -[egg_info] -tag_build = dev -tag_date = true diff --git a/sphinx_intl/__init__.py b/sphinx_intl/__init__.py index 55e4709..d4f135e 100644 --- a/sphinx_intl/__init__.py +++ b/sphinx_intl/__init__.py @@ -1 +1,7 @@ -__version__ = "2.3.0" +from importlib.metadata import version, PackageNotFoundError + +try: + __version__ = version("sphinx_intl") +except PackageNotFoundError: + # package is not installed + pass diff --git a/tox.ini b/tox.ini index 3d76503..70736b0 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,7 @@ envlist = python = 3.9: py39 3.10: py310 - 3.11: py311 + 3.11: py311, lint, check 3.12: py312 3.13: py313 @@ -41,22 +41,9 @@ commands=mypy sphinx_intl [testenv:dist] usedevelop=True -deps= - build - twine +deps=twine commands= - {envpython} -m build - twine check dist/* - -[testenv:release] -deps= - build - twine -allowlist_externals=mv -commands= - -mv setup.cfg setup.cfg_ - {envpython} -m build - -mv setup.cfg_ setup.cfg + uv build twine check dist/* [flake8]