Skip to content

Commit 89abe7e

Browse files
oschwaldclaude
andcommitted
Modernize setup.py for Python 3.10+
- Replace sys.exc_info() with modern exception handling using 'from' clause - Use text mode when opening files instead of binary mode with manual decode - Update BuildFailed to accept exception parameter for proper chaining These are internal improvements with no user-visible changes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 29b4f3c commit 89abe7e

1 file changed

Lines changed: 14 additions & 13 deletions

File tree

setup.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@
6565

6666

6767
class BuildFailed(Exception):
68-
def __init__(self) -> None:
69-
self.cause = sys.exc_info()[1]
68+
def __init__(self, cause: Exception) -> None:
69+
super().__init__()
70+
self.cause = cause
7071

7172

7273
class ve_build_ext(build_ext):
@@ -75,18 +76,18 @@ class ve_build_ext(build_ext):
7576
def run(self) -> None:
7677
try:
7778
build_ext.run(self)
78-
except PlatformError:
79-
raise BuildFailed
79+
except PlatformError as ex:
80+
raise BuildFailed(ex) from ex
8081

8182
def build_extension(self, ext) -> None:
8283
try:
8384
build_ext.build_extension(self, ext)
84-
except ext_errors:
85-
raise BuildFailed
86-
except ValueError:
85+
except ext_errors as ex:
86+
raise BuildFailed(ex) from ex
87+
except ValueError as ex:
8788
# this can happen on Windows 64 bit, see Python issue 7511
88-
if "'path'" in str(sys.exc_info()[1]):
89-
raise BuildFailed
89+
if "'path'" in str(ex):
90+
raise BuildFailed(ex) from ex
9091
raise
9192

9293

@@ -95,11 +96,11 @@ def build_extension(self, ext) -> None:
9596

9697
ROOT = os.path.dirname(__file__)
9798

98-
with open(os.path.join(ROOT, "README.rst"), "rb") as fd:
99-
README = fd.read().decode("utf8")
99+
with open(os.path.join(ROOT, "README.rst"), encoding="utf-8") as fd:
100+
README = fd.read()
100101

101-
with open(os.path.join(ROOT, "maxminddb", "__init__.py"), "rb") as fd:
102-
maxminddb_text = fd.read().decode("utf8")
102+
with open(os.path.join(ROOT, "maxminddb", "__init__.py"), encoding="utf-8") as fd:
103+
maxminddb_text = fd.read()
103104
VERSION = (
104105
re.compile(r".*__version__ = \"(.*?)\"", re.DOTALL)
105106
.match(maxminddb_text)

0 commit comments

Comments
 (0)