From 0842fcf451183755e35a45b37725d5d74b22657c Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh <39159+jcarbaugh@users.noreply.github.com> Date: Wed, 20 May 2026 09:36:10 -0400 Subject: [PATCH 1/3] Prepare project for first new release in many years - Add build-backend to [build-system] in pyproject.toml (PEP 517) - Move from dynamic to static version in pyproject.toml (4.0.0.dev0) - Switch us/version.py to importlib.metadata with unknown fallback - Replace sed-based version replacement in publish.yml with uv version - Bump astral-sh/setup-uv from v7 to v8 across all CI jobs - Fix README: uv install -> uv add, black -> ruff in dev section - Fix CONTRIBUTING.md: black -> ruff --- .github/CONTRIBUTING.md | 2 +- .github/workflows/publish.yml | 6 ++---- .github/workflows/pythonpackage.yml | 6 +++--- README.md | 7 ++++--- pyproject.toml | 6 ++---- us/version.py | 7 ++++++- uv.lock | 1 + 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 6d24cf1..aca21a9 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -7,7 +7,7 @@ Before spending time working on a pull request, please [open an idea discussion] To speed up the review process, please ensure: * your change has corresponding tests that run with the existing pytest suite and pass. -* the code is formatted with [black](https://black.readthedocs.io/en/stable/index.html), included in the dev dependencies. +* the code is formatted with [ruff](https://docs.astral.sh/ruff/), included in the dev dependencies. * you are open to feedback! Thank you and we look forward to your contribution! ✨ diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0b5055f..df0577d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,12 +18,10 @@ jobs: - uses: actions/checkout@v6 - name: Install uv - uses: astral-sh/setup-uv@v7 + uses: astral-sh/setup-uv@v8 - name: Set version from tag - run: | - VERSION=${GITHUB_REF#refs/tags/v} - sed -i "s/^__version__ = .*/__version__ = \"${VERSION}\"/" us/version.py + run: uv version "${GITHUB_REF#refs/tags/v}" - name: Build package run: uv build diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index abdb75b..f4593ac 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v6 - name: Install uv - uses: astral-sh/setup-uv@v7 + uses: astral-sh/setup-uv@v8 with: enable-cache: true python-version: "3.14" @@ -36,7 +36,7 @@ jobs: - uses: actions/checkout@v6 - name: Install uv - uses: astral-sh/setup-uv@v7 + uses: astral-sh/setup-uv@v8 with: enable-cache: true python-version: ${{ matrix.python-version }} @@ -54,7 +54,7 @@ jobs: - uses: actions/checkout@v6 - name: Install uv - uses: astral-sh/setup-uv@v7 + uses: astral-sh/setup-uv@v8 with: enable-cache: true python-version: "3.14" diff --git a/README.md b/README.md index 67fe598..bd8ffc7 100644 --- a/README.md +++ b/README.md @@ -25,10 +25,10 @@ As per usual: pip install us ``` -or +or ``` -uv install us +uv add us ``` @@ -39,7 +39,8 @@ This project uses [uv](https://docs.astral.sh/uv/) for development. ``` uv sync uv run pytest -uv run black --check us +uv run ruff check us +uv run ruff format --check us ``` diff --git a/pyproject.toml b/pyproject.toml index ce81f71..fe0f609 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,14 +1,15 @@ [build-system] requires = ["setuptools"] +build-backend = "setuptools.build_meta" [project] name = "us" +version = "4.0.0.dev0" description = "US state meta information and other fun stuff" readme = "README.md" urls.Homepage = "https://github.com/unitedstates/python-us/" urls."Issue tracker" = "https://github.com/unitedstates/python-us/issues" requires-python = ">=3.8" -dynamic = ["version"] authors = [{ name = "Jeremy Carbaugh", email = "jeremy@jcarbaugh.com" }] classifiers = [ "Programming Language :: Python", @@ -30,9 +31,6 @@ states = "us.cli.states:main" [dependency-groups] dev = ['ruff', 'pytest', 'pytz'] -[tool.setuptools.dynamic] -version = { attr = "us.version.__version__" } - [tool.ruff] line-length = 120 target-version = "py38" diff --git a/us/version.py b/us/version.py index 4acdd9b..687c14d 100644 --- a/us/version.py +++ b/us/version.py @@ -1 +1,6 @@ -__version__ = "4.0.0.dev" +try: + from importlib.metadata import version + + __version__ = version("us") +except Exception: + __version__ = "unknown" diff --git a/uv.lock b/uv.lock index c68291b..77557fe 100644 --- a/uv.lock +++ b/uv.lock @@ -468,6 +468,7 @@ wheels = [ [[package]] name = "us" +version = "4.0.0.dev0" source = { editable = "." } dependencies = [ { name = "jellyfish", version = "1.1.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.9'" }, From 4293af44e8b65609fd55cbf1ff25cdb464804925 Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh <39159+jcarbaugh@users.noreply.github.com> Date: Wed, 20 May 2026 16:04:07 -0400 Subject: [PATCH 2/3] update version --- CHANGELOG.md | 3 ++- pyproject.toml | 2 +- us/__init__.py | 50 ++++++++++++++++++++++++++++++++++++--------- us/tests/test_us.py | 6 ++++++ us/version.py | 6 ------ 5 files changed, 49 insertions(+), 18 deletions(-) delete mode 100644 us/version.py diff --git a/CHANGELOG.md b/CHANGELOG.md index c2c71f1..60c22c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,8 +3,9 @@ ## 4.0.0 * add counties, thanks to [Ray Kiddy](https://github.com/rkiddy) -* DC has returned to `STATES_AND_TERRITORIES`, thanks to [Kavi Gupta](https://github.com/kavigupta) * add `clean_name()` method and `fallback_func` parameter to `lookup()` to provide customizable matching, thanks to [Max Filenko](https://github.com/mfilenko) and [Charlie Tonneslan](https://github.com/c-tonneslan) +* DC has returned to `STATES_AND_TERRITORIES`, thanks to [Kavi Gupta](https://github.com/kavigupta) +* add `us.__version__` and deprecate `us.version` * fix `py.typed` location, thanks to [johnw-bluemark](https://github.com/johnw-bluemark) * add support for Python 3.13 and 3.14 * switch to [uv](https://docs.astral.sh/uv/) for development and packaging diff --git a/pyproject.toml b/pyproject.toml index fe0f609..287f66e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "us" version = "4.0.0.dev0" -description = "US state meta information and other fun stuff" +description = "US state metadata" readme = "README.md" urls.Homepage = "https://github.com/unitedstates/python-us/" urls."Issue tracker" = "https://github.com/unitedstates/python-us/issues" diff --git a/us/__init__.py b/us/__init__.py index 1fb625c..fb152c7 100644 --- a/us/__init__.py +++ b/us/__init__.py @@ -1,10 +1,40 @@ -from .states import ( # noqa - STATES, # noqa - STATES_CONTIGUOUS, # noqa - STATES_CONTINENTAL, # noqa - TERRITORIES, # noqa - STATES_AND_TERRITORIES, # noqa - OBSOLETE, # noqa -) # noqa -from .unitedstatesofamerica import * # noqa -from .version import __version__ as version # noqa +from .states import ( + STATES, + STATES_CONTIGUOUS, + STATES_CONTINENTAL, + TERRITORIES, + STATES_AND_TERRITORIES, + OBSOLETE, +) +from .unitedstatesofamerica import name, abbr, birthday + +try: + from importlib.metadata import version as _get_version + + __version__ = _get_version("us") +except Exception: + __version__ = "unknown" + + +# Deprecated support for us.version. Remove in the 5.0 release. +def __getattr__(name): + if name == "version": + from warnings import warn + + warn("us.version is deprecated, use us.__version__ instead", DeprecationWarning) + return __version__ + raise AttributeError(f"module '{__name__}' has no attribute '{name}'") + + +__all__ = [ + "STATES", + "STATES_CONTIGUOUS", + "STATES_CONTINENTAL", + "TERRITORIES", + "STATES_AND_TERRITORIES", + "OBSOLETE", + "name", + "abbr", + "birthday", + "__version__", +] diff --git a/us/tests/test_us.py b/us/tests/test_us.py index f156367..2f31e34 100644 --- a/us/tests/test_us.py +++ b/us/tests/test_us.py @@ -16,6 +16,12 @@ def test_attribute(): assert state == getattr(us.states, state.abbr) +def test_version_deprecation(): + with pytest.warns(DeprecationWarning): + version = us.version + assert version == us.__version__ + + def test_valid_timezones(): for state in us.STATES_AND_TERRITORIES: if state.capital: diff --git a/us/version.py b/us/version.py deleted file mode 100644 index 687c14d..0000000 --- a/us/version.py +++ /dev/null @@ -1,6 +0,0 @@ -try: - from importlib.metadata import version - - __version__ = version("us") -except Exception: - __version__ = "unknown" From 3cda9ea92510ba6c40f212a6637155d2fabe70f8 Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh <39159+jcarbaugh@users.noreply.github.com> Date: Wed, 20 May 2026 16:06:45 -0400 Subject: [PATCH 3/3] fix setup-uv versions --- .github/workflows/publish.yml | 2 +- .github/workflows/pythonpackage.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index df0577d..ea1d818 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/checkout@v6 - name: Install uv - uses: astral-sh/setup-uv@v8 + uses: astral-sh/setup-uv@v7 - name: Set version from tag run: uv version "${GITHUB_REF#refs/tags/v}" diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index f4593ac..abdb75b 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -11,7 +11,7 @@ jobs: - uses: actions/checkout@v6 - name: Install uv - uses: astral-sh/setup-uv@v8 + uses: astral-sh/setup-uv@v7 with: enable-cache: true python-version: "3.14" @@ -36,7 +36,7 @@ jobs: - uses: actions/checkout@v6 - name: Install uv - uses: astral-sh/setup-uv@v8 + uses: astral-sh/setup-uv@v7 with: enable-cache: true python-version: ${{ matrix.python-version }} @@ -54,7 +54,7 @@ jobs: - uses: actions/checkout@v6 - name: Install uv - uses: astral-sh/setup-uv@v8 + uses: astral-sh/setup-uv@v7 with: enable-cache: true python-version: "3.14"