Skip to content

Commit 2641f2e

Browse files
authored
Prepare for 4.0.0 release (#98)
* 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 * update version * fix setup-uv versions
1 parent caa9307 commit 2641f2e

9 files changed

Lines changed: 58 additions & 24 deletions

File tree

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Before spending time working on a pull request, please [open an idea discussion]
77
To speed up the review process, please ensure:
88

99
* your change has corresponding tests that run with the existing pytest suite and pass.
10-
* the code is formatted with [black](https://black.readthedocs.io/en/stable/index.html), included in the dev dependencies.
10+
* the code is formatted with [ruff](https://docs.astral.sh/ruff/), included in the dev dependencies.
1111
* you are open to feedback!
1212

1313
Thank you and we look forward to your contribution! ✨

.github/workflows/publish.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ jobs:
2121
uses: astral-sh/setup-uv@v7
2222

2323
- name: Set version from tag
24-
run: |
25-
VERSION=${GITHUB_REF#refs/tags/v}
26-
sed -i "s/^__version__ = .*/__version__ = \"${VERSION}\"/" us/version.py
24+
run: uv version "${GITHUB_REF#refs/tags/v}"
2725

2826
- name: Build package
2927
run: uv build

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
## 4.0.0
44

55
* add counties, thanks to [Ray Kiddy](https://github.com/rkiddy)
6-
* DC has returned to `STATES_AND_TERRITORIES`, thanks to [Kavi Gupta](https://github.com/kavigupta)
76
* 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)
7+
* DC has returned to `STATES_AND_TERRITORIES`, thanks to [Kavi Gupta](https://github.com/kavigupta)
8+
* add `us.__version__` and deprecate `us.version`
89
* fix `py.typed` location, thanks to [johnw-bluemark](https://github.com/johnw-bluemark)
910
* add support for Python 3.13 and 3.14
1011
* switch to [uv](https://docs.astral.sh/uv/) for development and packaging

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ As per usual:
2525
pip install us
2626
```
2727

28-
or
28+
or
2929

3030
```
31-
uv install us
31+
uv add us
3232
```
3333

3434

@@ -39,7 +39,8 @@ This project uses [uv](https://docs.astral.sh/uv/) for development.
3939
```
4040
uv sync
4141
uv run pytest
42-
uv run black --check us
42+
uv run ruff check us
43+
uv run ruff format --check us
4344
```
4445

4546

pyproject.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
[build-system]
22
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
34

45
[project]
56
name = "us"
6-
description = "US state meta information and other fun stuff"
7+
version = "4.0.0.dev0"
8+
description = "US state metadata"
79
readme = "README.md"
810
urls.Homepage = "https://github.com/unitedstates/python-us/"
911
urls."Issue tracker" = "https://github.com/unitedstates/python-us/issues"
1012
requires-python = ">=3.8"
11-
dynamic = ["version"]
1213
authors = [{ name = "Jeremy Carbaugh", email = "jeremy@jcarbaugh.com" }]
1314
classifiers = [
1415
"Programming Language :: Python",
@@ -30,9 +31,6 @@ states = "us.cli.states:main"
3031
[dependency-groups]
3132
dev = ['ruff', 'pytest', 'pytz']
3233

33-
[tool.setuptools.dynamic]
34-
version = { attr = "us.version.__version__" }
35-
3634
[tool.ruff]
3735
line-length = 120
3836
target-version = "py38"

us/__init__.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
1-
from .states import ( # noqa
2-
STATES, # noqa
3-
STATES_CONTIGUOUS, # noqa
4-
STATES_CONTINENTAL, # noqa
5-
TERRITORIES, # noqa
6-
STATES_AND_TERRITORIES, # noqa
7-
OBSOLETE, # noqa
8-
) # noqa
9-
from .unitedstatesofamerica import * # noqa
10-
from .version import __version__ as version # noqa
1+
from .states import (
2+
STATES,
3+
STATES_CONTIGUOUS,
4+
STATES_CONTINENTAL,
5+
TERRITORIES,
6+
STATES_AND_TERRITORIES,
7+
OBSOLETE,
8+
)
9+
from .unitedstatesofamerica import name, abbr, birthday
10+
11+
try:
12+
from importlib.metadata import version as _get_version
13+
14+
__version__ = _get_version("us")
15+
except Exception:
16+
__version__ = "unknown"
17+
18+
19+
# Deprecated support for us.version. Remove in the 5.0 release.
20+
def __getattr__(name):
21+
if name == "version":
22+
from warnings import warn
23+
24+
warn("us.version is deprecated, use us.__version__ instead", DeprecationWarning)
25+
return __version__
26+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
27+
28+
29+
__all__ = [
30+
"STATES",
31+
"STATES_CONTIGUOUS",
32+
"STATES_CONTINENTAL",
33+
"TERRITORIES",
34+
"STATES_AND_TERRITORIES",
35+
"OBSOLETE",
36+
"name",
37+
"abbr",
38+
"birthday",
39+
"__version__",
40+
]

us/tests/test_us.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ def test_attribute():
1616
assert state == getattr(us.states, state.abbr)
1717

1818

19+
def test_version_deprecation():
20+
with pytest.warns(DeprecationWarning):
21+
version = us.version
22+
assert version == us.__version__
23+
24+
1925
def test_valid_timezones():
2026
for state in us.STATES_AND_TERRITORIES:
2127
if state.capital:

us/version.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

uv.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)