本文整理汇总了Python中site.getuserbase方法的典型用法代码示例。如果您正苦于以下问题:Python site.getuserbase方法的具体用法?Python site.getuserbase怎么用?Python site.getuserbase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类site
的用法示例。
在下文中一共展示了site.getuserbase方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getuserbase
# 需要导入模块: import site [as 别名]
# 或者: from site import getuserbase [as 别名]
def test_getuserbase(self):
site.USER_BASE = None
user_base = site.getuserbase()
# the call sets site.USER_BASE
self.assertEqual(site.USER_BASE, user_base)
# let's set PYTHONUSERBASE and see if it uses it
site.USER_BASE = None
import sysconfig
sysconfig._CONFIG_VARS = None
with EnvironmentVarGuard() as environ:
environ['PYTHONUSERBASE'] = 'xoxo'
self.assertTrue(site.getuserbase().startswith('xoxo'),
site.getuserbase())
示例2: get_exe_dirs
# 需要导入模块: import site [as 别名]
# 或者: from site import getuserbase [as 别名]
def get_exe_dirs():
result = []
if site.ENABLE_USER_SITE:
if platform.system() == "Windows":
if site.getusersitepackages():
result.append(site.getusersitepackages().replace("site-packages", "Scripts"))
else:
if site.getuserbase():
result.append(site.getuserbase() + "/bin")
main_scripts = os.path.join(sys.prefix, "Scripts")
if os.path.isdir(main_scripts) and main_scripts not in result:
result.append(main_scripts)
if os.path.dirname(sys.executable) not in result:
result.append(os.path.dirname(sys.executable))
return result
示例3: _find_install_path
# 需要导入模块: import site [as 别名]
# 或者: from site import getuserbase [as 别名]
def _find_install_path():
if "--user" in sys.argv:
inst = site.getusersitepackages()
prefix = site.getuserbase()
else:
inst = site.getsitepackages()[0]
prefix = sys.prefix
return inst, prefix
示例4: test_getusersitepackages
# 需要导入模块: import site [as 别名]
# 或者: from site import getuserbase [as 别名]
def test_getusersitepackages(self):
site.USER_SITE = None
site.USER_BASE = None
user_site = site.getusersitepackages()
# the call sets USER_BASE *and* USER_SITE
self.assertEqual(site.USER_SITE, user_site)
self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
self.assertEqual(site.USER_BASE, site.getuserbase())
示例5: test_no_home_directory
# 需要导入模块: import site [as 别名]
# 或者: from site import getuserbase [as 别名]
def test_no_home_directory(self):
# bpo-10496: getuserbase() and getusersitepackages() must not fail if
# the current user has no home directory (if expanduser() returns the
# path unchanged).
site.USER_SITE = None
site.USER_BASE = None
sysconfig._CONFIG_VARS = None
with EnvironmentVarGuard() as environ, \
support.swap_attr(os.path, 'expanduser', lambda path: path):
del environ['PYTHONUSERBASE']
del environ['APPDATA']
user_base = site.getuserbase()
self.assertTrue(user_base.startswith('~' + os.sep),
user_base)
user_site = site.getusersitepackages()
self.assertTrue(user_site.startswith(user_base), user_site)
def fake_isdir(path):
fake_isdir.arg = path
return False
fake_isdir.arg = None
def must_not_be_called(*args):
raise AssertionError
with support.swap_attr(os.path, 'isdir', fake_isdir), \
support.swap_attr(site, 'addsitedir', must_not_be_called), \
support.swap_attr(site, 'ENABLE_USER_SITE', True):
# addusersitepackages() must not add user_site to sys.path
# if it is not an existing directory
known_paths = set()
site.addusersitepackages(known_paths)
self.assertEqual(fake_isdir.arg, user_site)
self.assertFalse(known_paths)