本文整理汇总了Python中site.getuserbase函数的典型用法代码示例。如果您正苦于以下问题:Python getuserbase函数的具体用法?Python getuserbase怎么用?Python getuserbase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getuserbase函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_app_dir
def get_app_dir():
"""Get the configured JupyterLab app directory.
"""
# Default to the override environment variable.
if os.environ.get('JUPYTERLAB_DIR'):
return osp.realpath(os.environ['JUPYTERLAB_DIR'])
# Use the default locations for data_files.
app_dir = pjoin(sys.prefix, 'share', 'jupyter', 'lab')
# Check for a user level install.
# Ensure that USER_BASE is defined
if hasattr(site, 'getuserbase'):
site.getuserbase()
userbase = getattr(site, 'USER_BASE', None)
if HERE.startswith(userbase) and not app_dir.startswith(userbase):
app_dir = pjoin(userbase, 'share', 'jupyter', 'lab')
# Check for a system install in '/usr/local/share'.
elif (sys.prefix.startswith('/usr') and not
osp.exists(app_dir) and
osp.exists('/usr/local/share/jupyter/lab')):
app_dir = '/usr/local/share/jupyter/lab'
return osp.realpath(app_dir)
示例2: run
def run(self):
# Workaround that install_data doesn't respect --prefix
#
# If prefix is given (via --user or via --prefix), then
# extract it and add it to the paths in self.data_files;
# otherwise, default to /usr/local.
install = self.distribution.command_options.get('install', {})
if 'user' in install:
# this means --user was given
self.prefix = site.getuserbase()
sysconfigdir = os.path.join(self.prefix, "etc")
elif 'prefix' in install:
# this means --prefix was given
self.prefix = install.get('prefix', (None, None))[1]
sysconfigdir = os.path.join(self.prefix, 'etc')
else:
self.prefix = 'usr'
sysconfigdir = '/etc'
new_data_files = []
for entry in self.data_files:
dest_path = entry[0].replace('@[email protected]', self.prefix)
dest_path = entry[0].replace('@[email protected]', sysconfigdir)
new_data_files.append((dest_path,) + entry[1:])
self.data_files = new_data_files
distutils.command.install_data.install_data.run(self)
示例3: excenturyrc_str
def excenturyrc_str():
"""Create the excenturyrc file contents. """
userbase = site.getuserbase()
content = append_variable('PATH', '%s/bin' % sys.prefix)
content += append_variable('PATH', '%s/bin' % userbase)
# include
path = pth.abspath(pth.dirname(__file__)+'/../extern/include')
content += append_variable('C_INCLUDE_PATH', path)
content += append_variable('CPLUS_INCLUDE_PATH', path)
# matlab
path = pth.abspath(pth.dirname(__file__)+'/../extern/matlab')
content += append_variable('MATLABPATH', path)
# excentury/bin
content += append_variable('PATH',
'%s/lib/excentury/bin' % userbase)
# excentury/lib
content += append_variable('LD_LIBRARY_PATH',
'%s/lib/excentury/lib' % userbase)
# excentury/matlab
content += append_variable('MATLABPATH',
'%s/lib/excentury/matlab' % userbase)
# excentury/python
content += append_variable('PYTHONPATH',
'%s/lib/excentury/python' % userbase)
return content
示例4: test_create_site_dir
def test_create_site_dir():
site_utils.create_site_dir("test")
tdir = os.path.join(site.getuserbase(), "test")
#print "tdir: %s" % str(tdir)
assert os.path.exists(tdir)
site_utils._remove_site_dir("test")
assert not site_utils.site_dir_exists("test")
示例5: test_no_home_directory
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
with EnvironmentVarGuard() as environ, \
mock.patch('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)
with mock.patch('os.path.isdir', return_value=False) as mock_isdir, \
mock.patch.object(site, 'addsitedir') as mock_addsitedir, \
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)
mock_isdir.assert_called_once_with(user_site)
mock_addsitedir.assert_not_called()
self.assertFalse(known_paths)
示例6: test_getuserbase
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())
示例7: test_getusersitepackages
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())
示例8: find_script
def find_script(name):
user_base = site.getuserbase()
script_path = find_subdirectory("bin", user_base)
if script_path is None:
script_path = find_subdirectory("Scripts", user_base)
script_path = os.path.join(script_path, name)
if os.path.isfile(script_path):
return script_path
return None
示例9: do_get_install_prefix
def do_get_install_prefix():
#special case for "user" installations, ie:
#$HOME/.local/lib/python2.7/site-packages/xpra/platform/paths.py
try:
base = site.getuserbase()
except:
base = site.USER_BASE
if __file__.startswith(base):
return base
return sys.prefix
示例10: build_cpp
def build_cpp(name, debug=None):
"""Compile a file and place it in bin. """
root = site.getuserbase()
if debug is None:
out = "-o %s/lib/excentury/bin/%s.run" % (root, name)
else:
out = "-DDEBUG=%s -o %s/lib/excentury/bin/%s.run%s" % (debug, root, name, debug)
root = pth.abspath(pth.dirname(__file__) + "/cpp")
cmd = "g++ -O3 %s %s/%s.cpp" % (out, root, name)
out, err, _ = exec_cmd(cmd)
eq_(err, "", "Build Error -->\n%s\n%s" % (cmd, err))
示例11: make_dirs
def make_dirs():
"""Creates standard directories to place binaries and libraries
created by excentury. """
root = site.getuserbase()
make_dir(root+'/lib')
make_dir(root+'/lib/excentury')
make_dir(root+'/lib/excentury/bin')
make_dir(root+'/lib/excentury/lib')
make_dir(root+'/lib/excentury/cpp')
make_dir(root+'/lib/excentury/matlab')
make_dir(root+'/lib/excentury/python')
make_dir(root+'/lib/excentury/tmp')
示例12: find_db
def find_db(self):
name = "library.sqlite"
dir = os.path.join(site.getuserbase(), "rayopt")
main = os.path.join(dir, name)
if not os.path.exists(main):
base = resource_filename(Requirement.parse("rayopt"), name)
if not os.path.exists(base):
base = os.path.join(os.path.split(__file__)[0], name)
if not os.path.exists(dir):
os.makedirs(dir)
shutil.copy(base, main)
return main
示例13: get_installation_prefix
def get_installation_prefix():
"Get installation prefix"
prefix = sys.prefix
for arg in sys.argv[1:]:
if "--user" in arg:
import site
prefix = site.getuserbase()
break
elif arg in ("--prefix", "--home", "--install-base"):
prefix = sys.argv[sys.argv.index(arg) + 1]
break
elif "--prefix=" in arg or "--home=" in arg or "--install-base=" in arg:
prefix = arg.split("=")[1]
break
return os.path.abspath(os.path.expanduser(prefix))
示例14: __get_scripts_directory
def __get_scripts_directory():
import sys
import platform
import site
"""Return directory where W3D scripts have been installed
:warn: This assumes a default installation with user scheme
:todo: Add fallbacks for alternate installations"""
if platform.system() in ("Windows",):
scripts_dir = os.path.join("Python{}{}".format(*(sys.version_info[:2])), "Scripts")
else:
scripts_dir = "bin"
scripts_dir = os.path.join(site.getuserbase(), scripts_dir)
return scripts_dir
示例15: run
def run():
"""Run the command. """
arg = config.CONFIG['arg']
if arg.path:
install_dir = arg.path
elif arg.user:
install_dir = '%s/lib/lexor' % site.getuserbase()
else:
install_dir = '%s/lib/lexor' % sys.prefix
style_file = arg.style
if '.py' not in style_file:
style_file = '%s.py' % style_file
if os.path.exists(style_file):
install_style(style_file, install_dir)
return
matches = []
url = 'http://jmlopez-rod.github.io/lexor-lang/lexor-lang.url'
print '-> Searching in %s' % url
response = urllib2.urlopen(url)
for line in response.readlines():
name, url = line.split(':', 1)
if arg.style in name:
matches.append([name.strip(), url.strip()])
for match in matches:
doc = urllib2.urlopen(match[1]).read()
links = re.finditer(r' href="?([^\s^"]+)', doc)
links = [link.group(1) for link in links if '.zip' in link.group(1)]
for link in links:
if 'master' in link:
path = urllib2.urlparse.urlsplit(match[1])
style_url = '%s://%s%s' % (path[0], path[1], link)
local_name = download_file(style_url, '.')
dirname = unzip_file(local_name)
# Assuming there is only one python file
os.chdir(dirname)
for path in iglob('*.py'):
install_style(path, install_dir)
os.chdir('..')
os.remove(local_name)
shutil.rmtree(dirname)