bpo-29585: optimize site.py startup time (GH-136)

Avoid importing `sysconfig` from `site` by copying minimum code.
Python startup is 5% faster on Linux and 30% faster on macOS
This commit is contained in:
INADA Naoki 2017-06-29 00:31:53 +09:00 committed by GitHub
parent 79d37ae979
commit a8f8d5b4bd
8 changed files with 96 additions and 43 deletions

View file

@ -180,6 +180,13 @@ class HelperFunctionsTests(unittest.TestCase):
finally:
pth_file.cleanup()
def test_getuserbase(self):
self.assertEqual(site._getuserbase(), sysconfig._getuserbase())
def test_get_path(self):
self.assertEqual(site._get_path(site._getuserbase()),
sysconfig.get_path('purelib', os.name + '_user'))
@unittest.skipUnless(site.ENABLE_USER_SITE, "requires access to PEP 370 "
"user-site (site.ENABLE_USER_SITE)")
def test_s_option(self):