diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index d9a5f7fe..9de23c96 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -1,25 +1,48 @@ -name: Publish Python 🐍 distributions 📦 to PyPI +name: Release to PyPI on: push: - tags: - - "*" + tags: ["*"] + +env: + dists-artifact-name: python-package-distributions + jobs: - build-n-publish: - name: Build and publish Python 🐍 distributions 📦 to PyPI - runs-on: ubuntu-20.04 + build: + runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up Python 3.9 - uses: actions/setup-python@v5 + - uses: actions/checkout@v4 with: - python-version: 3.9 - - name: Install dependencies - run: pip install -r requirements/build-requirements.txt + fetch-depth: 0 + - name: Install the latest version of uv + uses: astral-sh/setup-uv@v3 + with: + enable-cache: true + cache-dependency-glob: "pyproject.toml" + github-token: ${{ secrets.GITHUB_TOKEN }} - name: Build package - run: hatch build - - name: Publish distribution 📦 to PyPI - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') - uses: pypa/gh-action-pypi-publish@v1.10.1 + run: uv build --python 3.13 --python-preference only-managed --sdist --wheel . --out-dir dist + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: ${{ env.dists-artifact-name }} + path: dist/* + + release: + needs: + - build + runs-on: ubuntu-latest + environment: + name: release + url: https://pypi.org/project/tox-uv/${{ github.ref_name }} + permissions: + id-token: write + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: ${{ env.dists-artifact-name }} + path: dist/ + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@v1.12.2 with: - password: ${{ secrets.pypi_password }} + password: ${{ secrets.pypi_password }} \ No newline at end of file diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 279dac97..82f8f979 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,43 +1,80 @@ name: Test iso-codes, build and publish to TestPypi on: [pull_request] jobs: - pytest: + test: name: Run tests runs-on: ubuntu-20.04 strategy: matrix: - python: ["3.8", "3.9", "3.10", "3.11", "3.12"] + env: + - "3.13" + - "3.12" + - "3.11" + - "3.10" + - "3.9" + - type + - dev + - pkg_meta steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 + - uses: actions/checkout@v4 with: - python-version: ${{ matrix.python }} - - name: Install test dependencies - run: pip install -r requirements/test-requirements.txt - - name: Run Tox - run: tox -e py - build-n-publish-testpypi: - name: Build and publish Python 🐍 distributions 📦 to TestPyPI - runs-on: ubuntu-20.04 + fetch-depth: 0 + - name: Install the latest version of uv + uses: astral-sh/setup-uv@v3 + with: + enable-cache: true + cache-dependency-glob: "pyproject.toml" + - name: Install tox + run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv + - name: Install Python + if: startsWith(matrix.env, '3.') && matrix.env != '3.13' + run: uv python install --python-preference only-managed ${{ matrix.env }} + - name: Setup test suite + run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.env }} + - name: Run test suite + run: tox run --skip-pkg-install -e ${{ matrix.env }} + env: + PYTEST_ADDOPTS: "-vv --durations=20" + DIFF_AGAINST: HEAD + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install the latest version of uv + uses: astral-sh/setup-uv@v3 + with: + enable-cache: true + cache-dependency-glob: "pyproject.toml" + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Build package + run: uv build --python 3.13 --python-preference only-managed --sdist --wheel . --out-dir dist + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: ${{ env.dists-artifact-name }} + path: dist/* + + release: + needs: + - build + runs-on: ubuntu-latest + environment: + name: release + url: https://pypi.org/project/tox-uv/${{ github.ref_name }} permissions: - contents: read id-token: write steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set up Python 3.9 - uses: actions/setup-python@v5 + - name: Download all the dists + uses: actions/download-artifact@v4 with: - python-version: 3.9 - - name: Install build dependencies - run: pip install -r requirements/build-requirements.txt - - name: Build package - run: hatch build - - name: Publish distribution 📦 to Test PyPI - uses: pypa/gh-action-pypi-publish@v1.10.1 + name: ${{ env.dists-artifact-name }} + path: dist/ + - name: Publish to Test PyPI + uses: pypa/gh-action-pypi-publish@v1.12.2 with: password: ${{ secrets.test_pypi_password }} repository-url: https://test.pypi.org/legacy/ - skip-existing: true + skip-existing: true \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3289dd09..9dff76e3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,25 +1,40 @@ -# See https://pre-commit.com for more information -# See https://pre-commit.com/hooks.html for more hooks -default_language_version: - python: python3.10 repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 - hooks: - - id: check-added-large-files - - id: check-toml - - id: check-yaml - args: - - --unsafe - - id: end-of-file-fixer - - id: trailing-whitespace -- repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.0 - hooks: - - id: ruff - args: - - --fix - - id: ruff-format -ci: - autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks - autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.29.4 + hooks: + - id: check-github-workflows + args: ["--verbose"] + - repo: https://github.com/codespell-project/codespell + rev: v2.3.0 + hooks: + - id: codespell + additional_dependencies: ["tomli>=2.0.2"] + - repo: https://github.com/tox-dev/tox-ini-fmt + rev: "1.4.1" + hooks: + - id: tox-ini-fmt + args: ["-p", "fix"] + - repo: https://github.com/tox-dev/pyproject-fmt + rev: "v2.5.0" + hooks: + - id: pyproject-fmt + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.7.4" + hooks: + - id: ruff-format + - id: ruff + args: ["--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"] + - repo: https://github.com/rbubley/mirrors-prettier + rev: "v3.3.3" + hooks: + - id: prettier + args: ["--print-width=120", "--prose-wrap=always"] + - repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 636d81a3..90ddd728 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,29 +15,36 @@ keywords = ["iso"] classifiers = [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ] +requires-python = ">=3.9" dependencies = [] [project.optional-dependencies] - -dev = ["pre-commit == 3.7.1", "ruff == 0.6.3", "mypy == 1.10.1"] - -doc = ["mkdocs == 1.6.0", "mkdocs-material == 9.5.30", "mkdocstrings == 0.25.2"] - +dev = [ + "pre-commit==3.7.1", + "ruff==0.6.3", + "mypy==1.10.1", +] +doc = [ + "mkdocs==1.6.0", + "mkdocs-material==9.5.30", + "mkdocstrings==0.25.2", +] test = [ - "pytest == 8.2.2", - "tox == 4.18.0", - "pyinstaller[hook_testing] == 6.10.0", - "psutil == 6.0.0", + "pytest==8.2.2", + "tox==4.18.0", + "pyinstaller[hook-testing]==6.10.0", + "psutil==6.0.0", +] +build = [ + "hatch==1.12.0", ] - -build = ["hatch == 1.12.0"] [project.entry-points.pyinstaller40] hook-dirs = "isocodes.__pyinstaller:get_hook_dirs" -tests = "isocodes.__pyinstaller:get_hook_dirs" +tests = "isocodes.__pyinstaller:get_hook_dirs" \ No newline at end of file diff --git a/tests/test_general.py b/tests/test_general.py index 6be33c82..27a8cf15 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -1,5 +1,99 @@ -from isocodes import languages +import pytest +from isocodes import ( + Countries, + Languages, + Currencies, + SubdivisionsCountries, + FormerCountries, + ExtendedLanguages, + LanguageFamilies, + ScriptNames, +) -def test_languages(): - assert languages.get(name="Spanish") +@pytest.fixture +def countries(): + return Countries("3166-1") + + +@pytest.fixture +def languages(): + return Languages("639-2") + + +@pytest.fixture +def currencies(): + return Currencies("4217") + + +@pytest.fixture +def subdivisions_countries(): + return SubdivisionsCountries("3166-2") + + +@pytest.fixture +def former_countries(): + return FormerCountries("3166-3") + + +@pytest.fixture +def extended_languages(): + return ExtendedLanguages("639-3") + + +@pytest.fixture +def language_families(): + return LanguageFamilies("639-5") + + +@pytest.fixture +def script_names(): + return ScriptNames("15924") + + +def test_countries_by_alpha_2(countries): + result = countries.by_alpha_2 + assert isinstance(result, list) + assert all(isinstance(item, tuple) for item in result) + + +def test_languages_by_alpha_3(languages): + result = languages.by_alpha_3 + assert isinstance(result, list) + assert all(isinstance(item, tuple) for item in result) + + +def test_currencies_by_alpha_3(currencies): + result = currencies.by_alpha_3 + assert isinstance(result, list) + assert all(isinstance(item, tuple) for item in result) + + +def test_subdivisions_countries_by_code(subdivisions_countries): + result = subdivisions_countries.by_code + assert isinstance(result, list) + assert all(isinstance(item, tuple) for item in result) + + +def test_former_countries_by_alpha_2(former_countries): + result = former_countries.by_alpha_2 + assert isinstance(result, list) + assert all(isinstance(item, tuple) for item in result) + + +def test_extended_languages_by_alpha_3(extended_languages): + result = extended_languages.by_alpha_3 + assert isinstance(result, list) + assert all(isinstance(item, tuple) for item in result) + + +def test_language_families_by_alpha_3(language_families): + result = language_families.by_alpha_3 + assert isinstance(result, list) + assert all(isinstance(item, tuple) for item in result) + + +def test_script_names_by_alpha_4(script_names): + result = script_names.by_alpha_4 + assert isinstance(result, list) + assert all(isinstance(item, tuple) for item in result) diff --git a/tox.ini b/tox.ini index 9eb34c8b..11b54510 100644 --- a/tox.ini +++ b/tox.ini @@ -2,6 +2,4 @@ envlist = py38, py39, py310, py311, py312 [testenv] -commands = - pip install -r requirements/test-requirements.txt - pytest +commands = pytest