当前位置: 首页>>代码示例>>Python>>正文


Python pkg_resources.resource_exists方法代码示例

本文整理汇总了Python中pkg_resources.resource_exists方法的典型用法代码示例。如果您正苦于以下问题:Python pkg_resources.resource_exists方法的具体用法?Python pkg_resources.resource_exists怎么用?Python pkg_resources.resource_exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pkg_resources的用法示例。


在下文中一共展示了pkg_resources.resource_exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: scan_subpackages

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def scan_subpackages(cls, package: str) -> Sequence[str]:
        """Return a list of sub-packages defined under a named package."""
        # FIXME use importlib.resources in python 3.7
        if "." in package:
            package, sub_pkg = package.split(".", 1)
        else:
            sub_pkg = "."
        if not pkg_resources.resource_isdir(package, sub_pkg):
            raise ModuleLoadError(f"Undefined package {package}")
        found = []
        joiner = "" if sub_pkg == "." else f"{sub_pkg}."
        for sub_path in pkg_resources.resource_listdir(package, sub_pkg):
            if pkg_resources.resource_exists(
                package, f"{sub_pkg}/{sub_path}/__init__.py"
            ):
                found.append(f"{package}.{joiner}{sub_path}")
        return found 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:19,代码来源:classloader.py

示例2: default

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def default(cls) -> 'PrecalculatedTextMeasurer':
        """Returns a reasonable default PrecalculatedTextMeasurer."""
        if cls._default_cache is not None:
            return cls._default_cache

        if pkg_resources.resource_exists(__name__, 'default-widths.json.xz'):
            import lzma
            with pkg_resources.resource_stream(__name__,
                                               'default-widths.json.xz') as f:
                with lzma.open(f, "rt") as g:
                    cls._default_cache = PrecalculatedTextMeasurer.from_json(
                        cast(TextIO, g))
                    return cls._default_cache
        elif pkg_resources.resource_exists(__name__, 'default-widths.json'):
            with pkg_resources.resource_stream(__name__,
                                               'default-widths.json') as f:
                cls._default_cache = PrecalculatedTextMeasurer.from_json(
                    io.TextIOWrapper(f, encoding='utf-8'))
                return cls._default_cache
        else:
            raise ValueError('could not load default-widths.json') 
开发者ID:google,项目名称:pybadges,代码行数:23,代码来源:precalculated_text_measurer.py

示例3: resource_to_data

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def resource_to_data(path_to_data):
    """
    This is an auxiliar function to read data from a given resource.
    """

    resource_package = 'investpy'
    resource_path = '/'.join(('resources', path_to_data))
    if pkg_resources.resource_exists(resource_package, resource_path):
        data = pd.read_csv(pkg_resources.resource_filename(resource_package, resource_path))
    else:
        raise FileNotFoundError("ERR#0115: data file not found or errored.")

    if data is None:
        raise IOError("ERR#0115: data file not found or errored.")

    return data 
开发者ID:alvarobartt,项目名称:investpy,代码行数:18,代码来源:auxiliar.py

示例4: _is_scan_dir

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def _is_scan_dir(package, src_dir, dst_dir):
    """Check if working on a scan dir.
    """
    if os.path.exists(os.path.join(dst_dir, _CONTROL_DIR_NAME)):
        return True

    package_name = package.__name__
    if pkg_resources.resource_isdir(package_name,
                                    os.path.join(src_dir, _CONTROL_DIR_NAME)):
        return True

    if pkg_resources.resource_exists(package_name,
                                     os.path.join(src_dir, _CONTROL_DIR_FILE)):
        return True

    return False 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:18,代码来源:install.py

示例5: __init__

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def __init__(self, mats, definition_file):
        self._mats = mats
        self.block_map = {}
        self.blockstates = {}

        for b in self._mats:
            if b.ID == 0:
                b.stringID = "air"
            self.block_map[b.ID] = "minecraft:" + b.stringID

        # When running from a bundled app on Linux (and possibly on OSX) pkg_resource can't find the needed files.
        if pkg_resources.resource_exists(__name__, definition_file):
            # We're running from source or on Windows using the executable (<<== Not sure...)
            with pkg_resources.resource_stream(__name__, definition_file) as def_file:
                self.blockstates = json.load(def_file)
        else:
            # In all other cases, retrieve the file directly from the file system.
            with open(os.path.join("pymclevel", definition_file)) as def_file:
                self.blockstates = json.load(def_file)

        self.material_map[self._mats] = self 
开发者ID:Podshot,项目名称:MCEdit-Unified,代码行数:23,代码来源:materials.py

示例6: find_packaged_regressor

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def find_packaged_regressor(name):
    """ Find location of a regression method packaged with YATSM

    See :data:`packaged_regressions` for a list of
    available pre-packaged regressors

    Args:
        name (str): name of packaged regression object

    Returns:
        str: path to packaged regression method

    Raises:
        KeyError: raise KeyError if user specifies unknown regressor
        IOError: raise IOError if the packaged regressor cannot be found

    """
    if name not in packaged_regressions:
        raise KeyError('Cannot load unknown packaged regressor %s' % name)

    path = pkg_resources.resource_filename(__name__, 'pickles')
    logger.debug('Checking data files in %s for packaged regressors' % path)
    if not pkg_resources.resource_exists(__name__, 'pickles'):
        raise IOError('Cannot find packaged regressors in %s. Did you install '
                      'YATSM via setuptools?' % path)

    resource = os.path.join('pickles', name + '.pkl')
    if not pkg_resources.resource_exists(__name__, resource):
        raise IOError('Cannot find packaged regression method %s, but package '
                      'directory exists. Check the contents of %s if possible'
                      % (resource, path))

    return pkg_resources.resource_filename(__name__, resource) 
开发者ID:ceholden,项目名称:yatsm,代码行数:35,代码来源:packaged.py

示例7: resource_string

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def resource_string(*args):
    if len(args) == 0:
        raise ValueError()

    resource_path = os.path.join('resources', *args)

    if not pkg_resources.resource_exists('designate', resource_path):
        raise exceptions.ResourceNotFound('Could not find the requested '
                                          'resource: %s' % resource_path)

    return pkg_resources.resource_string('designate', resource_path) 
开发者ID:openstack,项目名称:designate,代码行数:13,代码来源:utils.py

示例8: test_resource

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def test_resource(parent, basename, relative_to_module_name=__name__):
    resource_test = lambda file_path: resource_exists(relative_to_module_name, file_path)
    return _test_filelike(parent, basename, resource_test) 
开发者ID:DualSpark,项目名称:cloudformation-environmentbase,代码行数:5,代码来源:resources.py

示例9: _get_version

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def _get_version():
    import pkg_resources, codecs
    if not pkg_resources.resource_exists(__name__, '_version'):
        return '0.0.0'
    with pkg_resources.resource_stream(__name__, '_version') as fp:
        return codecs.getreader('utf-8')(fp).read().strip() 
开发者ID:iRobotCorporation,项目名称:cfn-custom-resource,代码行数:8,代码来源:__init__.py

示例10: has_manifest

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def has_manifest(app, filename='manifest.json'):
    '''Verify the existance of a JSON assets manifest'''
    try:
        return pkg_resources.resource_exists(app, filename)
    except (ImportError, NotImplementedError):
        return os.path.isabs(filename) and os.path.exists(filename) 
开发者ID:opendatateam,项目名称:udata,代码行数:8,代码来源:assets.py

示例11: all

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def all(cls):
        def is_runtime(name):
            return resource_exists("runtimes/{}/runtime.yml".format(name))

        names = resource_listdir(__name__, "runtimes")
        names = [is_runtime(name) for name in names]
        return [cls.load(name) for name in names] 
开发者ID:rorodata,项目名称:rorolite,代码行数:9,代码来源:runtime.py

示例12: test_pr_resources

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def test_pr_resources(self):
        import pkg_resources as pr

        # App ZIP
        pkg = "android1"
        names = ["subdir", "__init__.py", "a.txt", "b.so", "mod1.py"]
        self.assertCountEqual(names, pr.resource_listdir(pkg, ""))
        for name in names:
            with self.subTest(name=name):
                self.assertTrue(pr.resource_exists(pkg, name))
                self.assertEqual(pr.resource_isdir(pkg, name),
                                 name == "subdir")
        self.assertFalse(pr.resource_exists(pkg, "nonexistent"))
        self.assertFalse(pr.resource_isdir(pkg, "nonexistent"))

        self.assertCountEqual(["c.txt"], pr.resource_listdir(pkg, "subdir"))
        self.assertTrue(pr.resource_exists(pkg, "subdir/c.txt"))
        self.assertFalse(pr.resource_isdir(pkg, "subdir/c.txt"))
        self.assertFalse(pr.resource_exists(pkg, "subdir/nonexistent.txt"))

        self.check_pr_resource(APP_ZIP, pkg, "__init__.py", b"# This package is")
        self.check_pr_resource(APP_ZIP, pkg, "a.txt", b"alpha\n")
        self.check_pr_resource(APP_ZIP, pkg, "b.so", b"bravo\n")
        self.check_pr_resource(APP_ZIP, pkg, "subdir/c.txt", b"charlie\n")

        # Requirements ZIP
        self.reset_package("murmurhash")
        self.assertCountEqual(["include", "tests", "__init__.pxd", "__init__.pyc", "about.pyc",
                               "mrmr.pxd", "mrmr.pyx", "mrmr.so"],
                              pr.resource_listdir("murmurhash", ""))
        self.assertCountEqual(["MurmurHash2.h", "MurmurHash3.h"],
                              pr.resource_listdir("murmurhash", "include/murmurhash"))

        self.check_pr_resource(REQS_COMMON_ZIP, "murmurhash", "__init__.pyc", MAGIC_NUMBER)
        self.check_pr_resource(REQS_COMMON_ZIP, "murmurhash", "mrmr.pxd", b"from libc.stdint")
        self.check_pr_resource(REQS_ABI_ZIP, "murmurhash", "mrmr.so", b"\x7fELF") 
开发者ID:chaquo,项目名称:chaquopy,代码行数:38,代码来源:test_android.py

示例13: _make_player

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def _make_player(file_name):
        try:
            return game.Player(file_name=file_name)
        except IOError as msg:
            if pkg_resources.resource_exists('rgkit', file_name):
                bot_filename = pkg_resources.resource_filename('rgkit',
                                                               file_name)
                return game.Player(file_name=bot_filename)
            raise IOError(msg) 
开发者ID:RobotGame,项目名称:rgkit,代码行数:11,代码来源:run.py

示例14: _readFromBinary

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def _readFromBinary(framework, frameworks_dir, platform, dst):
    script_path = os.path.join("specifications/frameworks",
        framework, platform, "build.sh")
    if not pkg_resources.resource_exists("aibench", script_path):
        raise Exception(
            "cannot find the build script in the binary under {}.".format(script_path))
    raw_build_script = pkg_resources.resource_string("aibench", script_path)
    if not os.path.exists(os.path.dirname(dst)):
        os.makedirs(os.path.dirname(dst))
    with open(os.path.join(os.path.dirname(dst), "build.sh"), "w") as f:
        f.write(raw_build_script.decode("utf-8"))
    build_script = f.name

    return build_script 
开发者ID:facebook,项目名称:FAI-PEP,代码行数:16,代码来源:build_program.py

示例15: getMeta

# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import resource_exists [as 别名]
def getMeta(args, platform):
    meta = None
    if not args.frameworks_dir:
        meta_file = os.path.join(
            "specifications/frameworks", args.framework, platform, "meta.json"
        )
        if "aibench" in sys.modules and pkg_resources.resource_exists(
            "aibench", meta_file
        ):
            meta = json.loads(pkg_resources.resource_string("aibench", meta_file))
            return meta
        else:
            # look for files in the old default place
            old_default = str(
                os.path.dirname(os.path.realpath(__file__))
                + "/../../specifications/frameworks"
            )
            meta_file = os.path.join(old_default, args.framework, platform, "meta.json")
    else:
        meta_file = os.path.join(
            args.frameworks_dir, args.framework, platform, "meta.json"
        )
    if os.path.isfile(meta_file):
        with open(meta_file, "r") as f:
            meta = json.load(f)
    return meta 
开发者ID:facebook,项目名称:FAI-PEP,代码行数:28,代码来源:utilities.py


注:本文中的pkg_resources.resource_exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。