Skip to content

Commit 34a31d9

Browse files
oschwaldclaude
andcommitted
Use single source of truth for version from pyproject.toml
Replace hardcoded module metadata in maxminddb/__init__.py with importlib.metadata.version() to get the version from pyproject.toml. This eliminates duplication and makes pyproject.toml the single source of truth for package metadata. Changes: - Remove __title__, __author__, __license__, and __copyright__ from __init__.py (redundant with pyproject.toml) - Replace hardcoded __version__ with importlib.metadata.version() - Remove version reading from setup.py (setuptools gets it from pyproject.toml automatically) - Update dev-bin/release.sh to only update pyproject.toml version 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent bff99c8 commit 34a31d9

File tree

3 files changed

+3
-22
lines changed

3 files changed

+3
-22
lines changed

dev-bin/release.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ if [ -n "$(git status --porcelain)" ]; then
3333
exit 1
3434
fi
3535

36-
perl -pi -e "s/(?<=__version__ = \").+?(?=\")/$version/gsm" maxminddb/__init__.py
3736
perl -pi -e "s/(?<=^version = \").+?(?=\")/$version/gsm" pyproject.toml
3837

3938
echo $"Test results:"

maxminddb/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from importlib.metadata import version
56
from typing import IO, TYPE_CHECKING, AnyStr, cast
67

78
from .const import (
@@ -87,8 +88,4 @@ def open_database(
8788
return cast("Reader", _extension.Reader(database, mode))
8889

8990

90-
__title__ = "maxminddb"
91-
__version__ = "2.8.2"
92-
__author__ = "Gregory Oschwald"
93-
__license__ = "Apache License, Version 2.0"
94-
__copyright__ = "Copyright 2013-2025 MaxMind, Inc."
91+
__version__ = version("maxminddb")

setup.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import re
32
import sys
43

54
from setuptools import Extension, setup
@@ -93,20 +92,6 @@ def build_extension(self, ext) -> None:
9392
cmdclass["build_ext"] = ve_build_ext
9493

9594

96-
ROOT = os.path.dirname(__file__)
97-
98-
with open(os.path.join(ROOT, "README.rst"), encoding="utf-8") as fd:
99-
README = fd.read()
100-
101-
with open(os.path.join(ROOT, "maxminddb", "__init__.py"), encoding="utf-8") as fd:
102-
maxminddb_text = fd.read()
103-
VERSION = (
104-
re.compile(r".*__version__ = \"(.*?)\"", re.DOTALL)
105-
.match(maxminddb_text)
106-
.group(1)
107-
)
108-
109-
11095
def status_msgs(*msgs):
11196
print("*" * 75)
11297
for msg in msgs:
@@ -131,7 +116,7 @@ def run_setup(with_cext) -> None:
131116
kwargs["ext_modules"] = ext_module
132117
loc_cmdclass["bdist_wheel"] = bdist_wheel
133118

134-
setup(version=VERSION, cmdclass=loc_cmdclass, **kwargs)
119+
setup(cmdclass=loc_cmdclass, **kwargs)
135120

136121

137122
try:

0 commit comments

Comments
 (0)