Skip to content

Commit e5040ae

Browse files
committed
Fix linting
Signed-off-by: Filipe Laíns <lains@riseup.net>
1 parent d8e0b2d commit e5040ae

2 files changed

Lines changed: 37 additions & 23 deletions

File tree

‎Lib/sysconfig/_build_details.py‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,10 +282,14 @@ def from_interpreter(cls) -> BuildDetailsV1:
282282
LIBRARY = sysconfig.get_config_var('LIBRARY')
283283
PY3LIBRARY = sysconfig.get_config_var('PY3LIBRARY')
284284
LIBPYTHON = sysconfig.get_config_var('LIBPYTHON')
285+
STATIC_LIBPYTHON = sysconfig.get_config_var('STATIC_LIBPYTHON')
286+
PYTHONFRAMEWORK = sysconfig.get_config_var('PYTHONFRAMEWORK')
285287

286288
LIBDIR = pathlib.Path(sysconfig.get_config_var('LIBDIR'))
287289
LIBPC = pathlib.Path(sysconfig.get_config_var('LIBPC'))
290+
LIBPL = pathlib.Path(sysconfig.get_config_var('LIBPL'))
288291
INCLUDEPY = pathlib.Path(sysconfig.get_config_var('INCLUDEPY'))
292+
PYTHONFRAMEWORKPREFIX = pathlib.Path(sysconfig.get_config_var('PYTHONFRAMEWORKPREFIX'))
289293

290294
interpreter_name = 'python' + sysconfig.get_config_var('LDVERSION') + sysconfig.get_config_var('EXE')
291295

@@ -314,19 +318,31 @@ def from_interpreter(cls) -> BuildDetailsV1:
314318
headers=INCLUDEPY,
315319
)
316320

321+
print(f'{PYTHONFRAMEWORK=!r}')
322+
317323
if os.name == 'posix':
318324
# On POSIX, LIBRARY is always the static library, while LDLIBRARY is the
319325
# dynamic library if enabled, otherwise it's the static library.
320326
# If LIBRARY != LDLIBRARY, support for the dynamic library is enabled.
321327
has_dynamic_library = LDLIBRARY != LIBRARY
322-
has_static_library = sysconfig.get_config_var('STATIC_LIBPYTHON')
328+
# macOS framework builds don't install the static library (see libainstall).
329+
has_static_library = STATIC_LIBPYTHON and not PYTHONFRAMEWORK
330+
# The static library is only installed into LIBDIR when it is also
331+
# LDLIBRARY; otherwise it is only installed into LIBPL.
332+
static_library_dir = LIBPL if has_dynamic_library else LIBDIR
333+
# In framework builds, LDLIBRARY is the path of the framework library
334+
# relative to PYTHONFRAMEWORKPREFIX (e.g.
335+
# Python.framework/Versions/3.X/Python), not a file in LIBDIR.
336+
dynamic_library_dir = PYTHONFRAMEWORKPREFIX if PYTHONFRAMEWORK else LIBDIR
323337
elif os.name == 'nt':
324338
# Windows can only use a dynamic library or a static library.
325339
# If it's using a dynamic library, sys.dllhandle will be set.
326340
# Static builds on Windows are not really well supported, though.
327341
# More context: https://github.com/python/cpython/issues/110234
328342
has_dynamic_library = hasattr(sys, 'dllhandle')
329343
has_static_library = not has_dynamic_library
344+
static_library_dir = LIBDIR
345+
dynamic_library_dir = LIBDIR
330346
else:
331347
raise NotADirectoryError(f'Unknown platform: {os.name}')
332348

@@ -347,18 +363,18 @@ def from_interpreter(cls) -> BuildDetailsV1:
347363
data.abi.stable_abi_suffix = suffix
348364
break
349365

350-
data.libpython.dynamic = LIBDIR / LDLIBRARY
366+
data.libpython.dynamic = dynamic_library_dir / LDLIBRARY
351367
# FIXME: Not sure if windows has a different dll for the stable ABI, and
352368
# even if it does, currently we don't have a way to get its name.
353369
if PY3LIBRARY:
354-
data.libpython.dynamic_stableabi = LIBDIR / PY3LIBRARY
370+
data.libpython.dynamic_stableabi = dynamic_library_dir / PY3LIBRARY
355371

356372
# Os POSIX, this is defined by the LIBPYTHON Makefile variable not being
357373
# empty. On Windows, don't link extensions — LIBPYTHON won't be defined,
358374
data.libpython.link_extensions = bool(LIBPYTHON)
359375

360376
if has_static_library:
361-
data.libpython.static = LIBDIR / LIBRARY
377+
data.libpython.static = static_library_dir / LIBRARY
362378

363379
if LIBPC:
364380
data.c_api.pkgconfig_path = LIBPC

‎Lib/test/test_build_details.py‎

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
import sysconfig
66
import string
77
import unittest
8+
import unittest.mock
89
import sysconfig._build_details as build_details
9-
from pathlib import Path
10-
from unittest import mock
10+
import tempfile
1111

1212
from test.support import is_android, is_apple_mobile, is_wasm32
13+
from unittest import mock
1314

1415

1516
class FormatTestsBase:
@@ -215,20 +216,21 @@ def test_round_trip(self):
215216

216217
self.check_relative_paths(data_abs_path, data_rel_path)
217218

218-
def test_round_trip_with_config_file_path(self):
219+
def test_round_trip_with_config_file_path(self, mock_open):
219220
data_abs_path = self.build_details_absolute_paths
220221
base_prefix = data_abs_path['base_prefix']
221-
config_dir = os.path.join(base_prefix, 'lib', 'python3.X')
222-
data_rel_path = self.build_details_absolute_paths
223-
generate_build_details.make_paths_relative(
224-
data_rel_path,
225-
config_path=os.path.join(config_dir, 'build-details.json'),
226-
)
227222

228-
# base_prefix is relative to the config file's directory...
229-
self.assertEqual(data_rel_path['base_prefix'], os.path.join('..', '..'))
230-
# ...while the other paths are still relative to base_prefix.
231-
self.check_relative_paths(data_abs_path, data_rel_path)
223+
with tempfile.TemporaryDirectory() as config_dir:
224+
out_file = os.path.join(config_dir, 'build-details.json')
225+
build_details.generate(out_file)
226+
227+
with open(data_rel_path) as f:
228+
data_rel_path = json.loads(f.read())
229+
230+
# base_prefix is relative to the config file's directory...
231+
self.assertEqual(data_rel_path['base_prefix'], os.path.relpath(out_file, base_prefix))
232+
# ...while the other paths are still relative to base_prefix.
233+
self.check_relative_paths(data_abs_path, data_rel_path)
232234

233235
def check_relative_paths(self, data_abs_path, data_rel_path):
234236
base_prefix = data_abs_path['base_prefix']
@@ -265,10 +267,6 @@ def check_relative_paths(self, data_abs_path, data_rel_path):
265267
self.assertEqual(data_abs_path[part][key], abs_rel_path)
266268

267269

268-
@unittest.skipIf(
269-
generate_build_details is None,
270-
"Failed to import generate-build-details"
271-
)
272270
@unittest.skipIf(os.name != 'posix', 'Feature only implemented on POSIX')
273271
@unittest.skipIf(is_wasm32, 'Feature not available on WebAssembly builds')
274272
class BuildDetailsLibpythonTests(unittest.TestCase):
@@ -285,8 +283,8 @@ def patched_get_config_var(name):
285283
return config_vars[name]
286284
return get_config_var(name)
287285
with mock.patch('sysconfig.get_config_var', patched_get_config_var):
288-
data = generate_build_details.generate_data(schema_version='1.0')
289-
return json.loads(json.dumps(data)).get('libpython', {})
286+
data = build_details.BuildDetails.from_interpreter().as_json()
287+
return json.loads(data).get('libpython', {})
290288

291289
def test_static_only(self):
292290
libpython = self.generate_libpython(

0 commit comments

Comments
 (0)