Skip to content

Commit cf93e55

Browse files
committed
Remove deprecated pkg_resources.parse_version
1 parent 63996c6 commit cf93e55

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

tools/build.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# /// script
22
# dependencies = [
33
# "auditwheel < 5",
4+
# "packaging",
45
# "pefile",
56
# "pyelftools", # elftools
67
# "setuptools < 74",
@@ -15,27 +16,12 @@
1516
import sys
1617
from datetime import datetime
1718

19+
import packaging.version
1820
import setuptools.msvc
19-
from pkg_resources import parse_version
2021

2122
os.chdir(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
2223

2324

24-
# Python 3.7 workaround:
25-
def parse_version_wrapper(txt):
26-
version = parse_version(txt)
27-
28-
try:
29-
version.major # noqa
30-
version.minor # noqa
31-
except AttributeError:
32-
# Python 3.7 doesn't have these so we patch them in
33-
version.major = version._version.release[0]
34-
version.minor = version._version.release[1]
35-
36-
return version
37-
38-
3925
def _run(cmd, **kwargs):
4026
# For some reason, when combined with wsl calls, Python thinks the directory we're in has been deleted
4127
# so os.getcwd() fails
@@ -75,7 +61,7 @@ def del_rw(action, name, exc):
7561

7662

7763
def create_interpreters(version, dest):
78-
version = parse_version_wrapper(version)
64+
version = packaging.version.Version(version)
7965
print(f'Creating Python {version} interpreters in "{dest}" directory...', flush=True)
8066
_run([sys.executable, os.path.join('tools', 'create_embedded_python.py'), '--version', str(version), dest], check=True)
8167

@@ -95,7 +81,7 @@ def _get_embed(version, system, arch):
9581

9682

9783
def build_binaries(version, arch, system, run_tests=True):
98-
version = parse_version_wrapper(version)
84+
version = packaging.version.Version(version)
9985
print(f'Building {arch} binaries for {system}...', flush=True)
10086

10187
if system == 'linux':
@@ -128,7 +114,7 @@ def build_binaries(version, arch, system, run_tests=True):
128114

129115

130116
def run_tests(version, arch, system):
131-
version = parse_version_wrapper(version)
117+
version = packaging.version.Version(version)
132118
print(f'Running tests for {arch} {system}...', flush=True)
133119

134120
_verbose_run([_get_embed(version, system, arch), os.path.join('tests', 'tests.py')], check=True)
@@ -140,7 +126,7 @@ def build_pbos():
140126

141127

142128
def copy_templates(version):
143-
version = parse_version_wrapper(version)
129+
version = packaging.version.Version(version)
144130
print('Copying files to @Pythia folder...', flush=True)
145131

146132
for f in os.listdir('templates'):
@@ -157,7 +143,7 @@ def copy_templates(version):
157143

158144

159145
def safety_checks(version):
160-
version = parse_version_wrapper(version)
146+
version = packaging.version.Version(version)
161147
print('Running safety checks...', flush=True)
162148
_run([sys.executable, os.path.join('tools', 'safety_checks.py'), str(version)], check=True)
163149

tools/rebuild_all.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# /// script
22
# dependencies = [
33
# "auditwheel < 5",
4+
# "packaging",
45
# "pefile",
5-
# "pyelftools",
6+
# "pyelftools", # elftools
67
# "setuptools < 74",
78
# ]
89
# ///

tools/safety_checks.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# /// script
22
# dependencies = [
33
# "auditwheel < 5",
4+
# "packaging",
45
# "pefile",
56
# "pyelftools", # elftools
67
# "setuptools < 74",
@@ -12,7 +13,7 @@
1213
import sys
1314
from typing import List
1415

15-
from pkg_resources import parse_version
16+
import packaging.version
1617

1718

1819
def check_dll_architecture(path: str, x86=False):
@@ -117,10 +118,10 @@ def check_so_is_manylinux2014(path: str, allowed_imports: List = None):
117118
}
118119

119120
allowed_symbol_versions = {
120-
'GLIBC': parse_version('2.17'),
121-
'CXXABI': parse_version('1.3.7'),
122-
'GLIBCXX': parse_version('3.4.19'),
123-
'GCC': parse_version('4.8.0'),
121+
'GLIBC': packaging.version.Version('2.17'),
122+
'CXXABI': packaging.version.Version('1.3.7'),
123+
'GLIBCXX': packaging.version.Version('3.4.19'),
124+
'GCC': packaging.version.Version('4.8.0'),
124125
}
125126

126127
allowed_imports_lower = {'ld-linux.so.2', 'ld-linux-x86-64.so.2'}
@@ -157,7 +158,7 @@ def check_so_is_manylinux2014(path: str, allowed_imports: List = None):
157158
elffile = ELFFile(file)
158159
for filename, symbol in elf_find_versioned_symbols(elffile):
159160
symbol_name, _, version = symbol.partition('_')
160-
if parse_version(version) > allowed_symbol_versions[symbol_name]:
161+
if packaging.version.Version(version) > allowed_symbol_versions[symbol_name]:
161162
print(f'There is a call to {symbol_name} at version {version} which is not allowed for manylinux2014. '
162163
'Rebuild the code using the manylinux2014 docker image!')
163164
sys.exit(1)

0 commit comments

Comments
 (0)