@@ -124,7 +124,7 @@ def removeduppaths():
124124 # if they only differ in case); turn relative paths into absolute
125125 # paths.
126126 dir , dircase = makepath (dir )
127- if dircase not in known_paths :
127+ if not dircase in known_paths :
128128 L .append (dir )
129129 known_paths .add (dircase )
130130 sys .path [:] = L
@@ -234,46 +234,6 @@ def check_enableusersite():
234234
235235 return True
236236
237-
238- # NOTE: sysconfig and it's dependencies are relatively large but site module
239- # needs very limited part of them.
240- # To speedup startup time, we have copy of them.
241- #
242- # See https://bugs.python.org/issue29585
243-
244- # Copy of sysconfig._getuserbase()
245- def _getuserbase ():
246- env_base = os .environ .get ("PYTHONUSERBASE" , None )
247- if env_base :
248- return env_base
249-
250- def joinuser (* args ):
251- return os .path .expanduser (os .path .join (* args ))
252-
253- if os .name == "nt" :
254- base = os .environ .get ("APPDATA" ) or "~"
255- return joinuser (base , "Python" )
256-
257- if sys .platform == "darwin" and sys ._framework :
258- return joinuser ("~" , "Library" , sys ._framework ,
259- "%d.%d" % sys .version_info [:2 ])
260-
261- return joinuser ("~" , ".local" )
262-
263-
264- # Same to sysconfig.get_path('purelib', os.name+'_user')
265- def _get_path (userbase ):
266- version = sys .version_info
267-
268- if os .name == 'nt' :
269- return f'{ userbase } /Python{ version [0 ]} { version [1 ]} /site-packages'
270-
271- if sys .platform == 'darwin' and sys ._framework :
272- return f'{ userbase } /lib/python/site-packages'
273-
274- return f'{ userbase } /lib/python{ version [0 ]} .{ version [1 ]} /site-packages'
275-
276-
277237def getuserbase ():
278238 """Returns the `user base` directory path.
279239
@@ -282,23 +242,33 @@ def getuserbase():
282242 it.
283243 """
284244 global USER_BASE
285- if USER_BASE is None :
286- USER_BASE = _getuserbase ()
245+ if USER_BASE is not None :
246+ return USER_BASE
247+ from sysconfig import get_config_var
248+ USER_BASE = get_config_var ('userbase' )
287249 return USER_BASE
288250
289-
290251def getusersitepackages ():
291252 """Returns the user-specific site-packages directory path.
292253
293254 If the global variable ``USER_SITE`` is not initialized yet, this
294255 function will also set it.
295256 """
296257 global USER_SITE
297- userbase = getuserbase () # this will also set USER_BASE
258+ user_base = getuserbase () # this will also set USER_BASE
259+
260+ if USER_SITE is not None :
261+ return USER_SITE
262+
263+ from sysconfig import get_path
298264
299- if USER_SITE is None :
300- USER_SITE = _get_path (userbase )
265+ if sys .platform == 'darwin' :
266+ from sysconfig import get_config_var
267+ if get_config_var ('PYTHONFRAMEWORK' ):
268+ USER_SITE = get_path ('purelib' , 'osx_framework_user' )
269+ return USER_SITE
301270
271+ USER_SITE = get_path ('purelib' , '%s_user' % os .name )
302272 return USER_SITE
303273
304274def addusersitepackages (known_paths ):
@@ -340,11 +310,15 @@ def getsitepackages(prefixes=None):
340310 else :
341311 sitepackages .append (prefix )
342312 sitepackages .append (os .path .join (prefix , "lib" , "site-packages" ))
343- # for framework builds *only* we add the standard Apple locations.
344- if sys .platform == "darwin" and sys ._framework :
345- sitepackages .append (
346- os .path .join ("/Library" , framework ,
347- '%d.%d' % sys .version_info [:2 ], "site-packages" ))
313+ if sys .platform == "darwin" :
314+ # for framework builds *only* we add the standard Apple
315+ # locations.
316+ from sysconfig import get_config_var
317+ framework = get_config_var ("PYTHONFRAMEWORK" )
318+ if framework :
319+ sitepackages .append (
320+ os .path .join ("/Library" , framework ,
321+ '%d.%d' % sys .version_info [:2 ], "site-packages" ))
348322 return sitepackages
349323
350324def addsitepackages (known_paths , prefixes = None ):
0 commit comments