1313 from sysconfig import _PREFIX as PREFIX
1414 from sysconfig import get_python_version
1515
16+ Str = type (
17+ "_Never" ,
18+ tuple (),
19+ {
20+ "__init__" : lambda s = None , n = None , constant_value = None , string = None , col_offset = None , lineno = None : s
21+ or n
22+ },
23+ )
24+
1625 def is_virtual_environment ():
1726 """
1827 Whether one is in a virtual environment
@@ -37,41 +46,49 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
3746 "/usr" ,
3847 "/usr/local" ,
3948 )
40- if prefix is None :
41- if standard_lib :
42- prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
43- else :
44- prefix = plat_specific and EXEC_PREFIX or PREFIX
45-
46- if os .name == "posix" :
47- if plat_specific or standard_lib :
49+ prefix = (
50+ prefix or plat_specific and (BASE_EXEC_PREFIX or BASE_PREFIX )
51+ if standard_lib
52+ else (EXEC_PREFIX or PREFIX )
53+ )
54+
55+ class DistutilsPlatformError (Exception ):
56+ """DistutilsPlatformError"""
57+
58+ assert os .name in frozenset (("posix" , "nt" )), DistutilsPlatformError (
59+ "I don't know where Python installs its library "
60+ "on platform '{}'" .format (os .name )
61+ )
62+ return (
63+ (
64+ # plat_specific or standard_lib:
4865 # Platform-specific modules (any module from a non-pure-Python
4966 # module distribution) or standard Python library modules.
50- libdir = sys .platlibdir
51- else :
67+ # else:
5268 # Pure Python
53- libdir = "lib"
54- libpython = os . path . join ( prefix , libdir , "python" + get_python_version ())
55- if standard_lib :
56- return libpython
57- elif is_default_prefix and not is_virtual_environment ():
58- return os . path . join ( prefix , "lib" , "python3" , "dist-packages" )
59- else :
60- return os . path . join ( libpython , "site-packages" )
61- elif os . name == "nt" :
62- if standard_lib :
63- return os .path .join (prefix , "Lib" )
64- else :
65- return os . path . join ( prefix , "Lib" , "site-packages" )
66- else :
67-
68- class DistutilsPlatformError ( Exception ):
69- """DistutilsPlatformError"" "
70-
71- raise DistutilsPlatformError (
72- "I don't know where Python installs its library "
73- "on platform '%s'" % os . name
69+ lambda libpython : (
70+ libpython
71+ if standard_lib
72+ else (
73+ os . path . join ( prefix , "lib" , "python3" , "dist-packages" )
74+ if is_default_prefix and not is_virtual_environment ( )
75+ else os . path . join ( libpython , "site-packages" )
76+ )
77+ )
78+ )(
79+ os .path .join (
80+ prefix ,
81+ sys . platlibdir if plat_specific or standard_lib else "lib" ,
82+ "python" + get_python_version (),
83+ )
84+ )
85+ if os . name == "posix "
86+ else (
87+ os . path . join ( prefix , "Lib" )
88+ if standard_lib
89+ else os . path . join ( prefix , "Lib" , "site-packages" )
7490 )
91+ )
7592
7693else :
7794 from distutils .sysconfig import get_python_lib
@@ -92,10 +109,8 @@ def relative_filename(filename, remove_hints=tuple()):
92109 """
93110 _filename : str = filename .casefold ()
94111 lib = get_python_lib (), get_python_lib (prefix = "" )
95- for elem in remove_hints + lib :
96- if _filename .startswith (elem .casefold ()):
97- return filename [len (elem ) + 1 :]
98- return filename
112+ return next (map (lambda elem : filename [len (elem ) + 1 :],
113+ filter (lambda elem : _filename .startswith (elem .casefold ()), remove_hints + lib )), filename )
99114
100115
101116__all__ = ["relative_filename" ] # type: list[str]
0 commit comments