Skip to content

bpo-29585: optimize site.py startup time #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More elaborate comments about copied functions.
  • Loading branch information
methane committed Jun 28, 2017
commit 33c420ac292a365ed06ea5105cc4298bccf9d4d9
34 changes: 20 additions & 14 deletions Lib/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,14 @@ def check_enableusersite():
return True


# NOTE: sysconfig and it's dependencies are relatively large but site module
# needs very limited part of them.
# To speedup startup time, we have copy of them.
#
# See https://bugs.python.org/issue29585

# Copy of sysconfig._getuserbase()
def _getuserbase():
# Stripped version of sysconfig._getuserbase()
env_base = os.environ.get("PYTHONUSERBASE", None)
if env_base:
return env_base
Expand All @@ -255,6 +261,19 @@ def joinuser(*args):
return joinuser("~", ".local")


# Same to sysconfig.get_path('purelib', os.name+'_user')
def _get_path(userbase):
version = sys.version_info

if os.name == 'nt':
return f'{userbase}/Python{version[0]}{version[1]}/site-packages'

if sys.platform == 'darwin' and sys._framework:
return f'{userbase}/lib/python/site-packages'

return f'{userbase}/lib/python{version[0]}.{version[1]}/site-packages'


def getuserbase():
"""Returns the `user base` directory path.

Expand All @@ -268,19 +287,6 @@ def getuserbase():
return USER_BASE


def _get_path(userbase):
# stripped version of sysconfig.get_path('purelib', os.name + '_user')
version = sys.version_info[:2]

if os.name == 'nt':
return f'{userbase}/Python{version[0]}{version[1]}/site-packages'

if sys.platform == 'darwin' and sys._framework:
return f'{userbase}/lib/python/site-packages'

return f'{userbase}/lib/python{version[0]}.{version[1]}/site-packages'


def getusersitepackages():
"""Returns the user-specific site-packages directory path.

Expand Down
27 changes: 9 additions & 18 deletions Lib/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,34 +178,25 @@ def _get_default_scheme():
return os.name


# NOTE: site.py has stripped copy of this function.
# Update it too when modify this function.
# NOTE: site.py has copy of this function.
# Sync it when modify this function.
def _getuserbase():
env_base = os.environ.get("PYTHONUSERBASE", None)
if env_base:
return env_base

def joinuser(*args):
return os.path.expanduser(os.path.join(*args))

if os.name == "nt":
base = os.environ.get("APPDATA") or "~"
if env_base:
return env_base
else:
return joinuser(base, "Python")
return joinuser(base, "Python")

if sys.platform == "darwin":
framework = get_config_var("PYTHONFRAMEWORK")
if framework:
if env_base:
return env_base
else:
return joinuser("~", "Library", framework, "%d.%d" %
sys.version_info[:2])
if sys.platform == "darwin" and sys._framework:
return joinuser("~", "Library", sys._framework,
"%d.%d" % sys.version_info[:2])

if env_base:
return env_base
else:
return joinuser("~", ".local")
return joinuser("~", ".local")


def _parse_makefile(filename, vars=None):
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy