Python site 模块,getusersitepackages() 实例源码

我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用site.getusersitepackages()

项目:container-service-extension    作者:vmware    | 项目源码 | 文件源码
def get_data_file(file_name):
    path = None
    if os.path.isfile('pv/%s' % file_name):
        path = 'pv/%s' % file_name
    elif os.path.isfile(site.getusersitepackages()+'/cse/'+file_name):
        path = site.getusersitepackages()+'/cse/'+file_name
    else:
        sp = site.getsitepackages()
        if isinstance(sp, list):
            for item in sp:
                if os.path.isfile(item+'/cse/'+file_name):
                    path = item+'/cse/'+file_name
                    break
        elif os.path.isfile(sp+'/cse/'+file_name):
            path = sp+'/cse/'+file_name
    content = ''
    if path is not None:
        with open(path) as f:
            content = f.read()
    return content
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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)
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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)
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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)
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
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)
项目:pyasp    作者:sthiele    | 项目源码 | 文件源码
def binaries_directory():
    """Return the installation directory, or None"""
    if '--user' in sys.argv:
        paths = (site.getusersitepackages(),)
    else:
        py_version = '%s.%s' % (sys.version_info[0], sys.version_info[1])
        paths = (s % (py_version) for s in (
            sys.prefix + '/lib/python%s/dist-packages/',
            sys.prefix + '/lib/python%s/site-packages/',
            sys.prefix + '/local/lib/python%s/dist-packages/',
            sys.prefix + '/local/lib/python%s/site-packages/',
            '/Library/Python/%s/site-packages/',
        ))

    # yield the first valid path
    for path in paths:
        # add the package and bin subdir and, if exists, return it
        path = os.path.join(path, '%s/%s' % (info.__pkg_name__, constant.REL_DIR_BIN))
        if os.path.exists(path):
            return path
    logging.getLogger().error(
        'pyasp binaries path not found. You need to download and'
        ' put in place the binaries for gringo3, gringo4 and clasp'
        ' in order to start using pyasp.'
        ' You can find binaries from ' + BINARIES_BASE_URL +
        ' or https://sourceforge.net/projects/potassco/files/,'
        ' or compile them yourself.'
    )
    exit()
    return None
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
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)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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)
项目:ndk-python    作者:gittor    | 项目源码 | 文件源码
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)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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)
项目:fishnet    作者:niklasf    | 项目源码 | 文件源码
def is_user_site_package():
    try:
        user_site = site.getusersitepackages()
    except AttributeError:
        return False

    return os.path.abspath(__file__).startswith(os.path.join(user_site, ""))
项目:cmany    作者:biojppm    | 项目源码 | 文件源码
def get_binaries_directory():
    """Return the installation directory, or None
    http://stackoverflow.com/questions/36187264"""
    if '--user' in sys.argv:
        paths = (site.getusersitepackages(),)
    else:
        if hasattr(site, 'getsitepackages'):
            print("cmany setup: site-packages", site.getsitepackages())
            print("cmany setup: site-user-packages", site.getusersitepackages())
            print("cmany setup: site-prefix", os.path.dirname(sys.executable))
            paths = site.getsitepackages()
        else:
            print("cmany setup: no site.getsitepackages()...")
            py_prefix = os.path.dirname(sys.executable)
            paths = [
                py_prefix + '/lib/site-packages',
                py_prefix + '/lib/site-packages',
                py_prefix + '/lib',
            ]
        py_version = '{}.{}'.format(sys.version_info[0], sys.version_info[1])
        paths += (s.format(py_version) for s in (
            sys.prefix + '/lib/python{}/site-packages/',
            sys.prefix + '/lib/python{}/dist-packages/',
            sys.prefix + '/local/lib/python{}/site-packages/',
            sys.prefix + '/local/lib/python{}/dist-packages/',
            '/Library/Python/{}/site-packages/',
        ))
    for path in paths:
        if os.path.exists(path):
            print('cmany setup: installation path:', path)
            return path
    raise Exception('cmany setup: no installation path found', file=sys.stderr)
    return None
项目:gst-build    作者:GStreamer    | 项目源码 | 文件源码
def python_env(options, unset_env=False):
    """
    Setup our overrides_hack.py as sitecustomize.py script in user
    site-packages if unset_env=False, else unset, previously set
    env.
    """
    subprojects_path = os.path.join(options.builddir, "subprojects")
    gst_python_path = os.path.join(SCRIPTDIR, "subprojects", "gst-python")
    if not os.path.exists(os.path.join(subprojects_path, "gst-python")) or \
            not os.path.exists(gst_python_path):
        return False

    sitepackages = site.getusersitepackages()
    if not sitepackages:
        return False

    sitecustomize = os.path.join(sitepackages, "sitecustomize.py")
    overrides_hack = os.path.join(gst_python_path, "testsuite", "overrides_hack.py")

    if not unset_env:
        if os.path.exists(sitecustomize):
            if os.path.realpath(sitecustomize) == overrides_hack:
                print("Customize user site script already linked to the GStreamer one")
                return False

            old_sitecustomize = os.path.join(sitepackages,
                                            "old.sitecustomize.gstuninstalled.py")
            shutil.move(sitecustomize, old_sitecustomize)
        elif not os.path.exists(sitepackages):
            os.makedirs(sitepackages)

        os.symlink(overrides_hack, sitecustomize)
        return os.path.realpath(sitecustomize) == overrides_hack
    else:
        if not os.path.realpath(sitecustomize) == overrides_hack:
            return False

        os.remove(sitecustomize)
        old_sitecustomize = os.path.join(sitepackages,
                                            "old.sitecustomize.gstuninstalled.py")

        if os.path.exists(old_sitecustomize):
            shutil.move(old_sitecustomize, sitecustomize)

        return True