Skip to content

Commit

Permalink
test: simplify python lib folder guessing implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mbdevpl committed Aug 15, 2023
1 parent 8b83243 commit 89b2fdd
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions test/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,19 @@


def python_lib_dir() -> pathlib.Path:
"""Get root folder of currently running Python libraries.
Currently works only for CPython and PyPy.
"""
"""Get root folder of currently running Python libraries."""
lib_dir = pathlib.Path(getattr(sys, 'real_prefix', sys.prefix))
assert lib_dir.is_dir(), lib_dir
if platform.python_implementation() == 'CPython':
lib_dir /= 'lib'
assert lib_dir.is_dir(), lib_dir
if platform.system() != 'Windows':
lib_dir /= f'python{sys.version_info[0]}.{sys.version_info[1]}'
if platform.system() == 'Windows':
lib_dir /= 'Lib'
else:
assert platform.python_implementation() == 'PyPy'
# lib_dir /= 'lib-python'
# currently implemented only for CPython and PyPy
implementation_dir_prefix = {
'CPython': 'python',
'PyPy': 'pypy'}.get(platform.python_implementation())
lib_dir /= 'lib'
assert lib_dir.is_dir(), lib_dir
# lib_dir /= f'{sys.version_info[0]}'
lib_dir /= f'pypy{sys.version_info[0]}.{sys.version_info[1]}'

lib_dir /= f'{implementation_dir_prefix}{sys.version_info[0]}.{sys.version_info[1]}'
assert lib_dir.is_dir(), lib_dir
return lib_dir

Expand Down

0 comments on commit 89b2fdd

Please sign in to comment.