本文整理匯總了Python中pkg_resources.find_distributions方法的典型用法代碼示例。如果您正苦於以下問題:Python pkg_resources.find_distributions方法的具體用法?Python pkg_resources.find_distributions怎麽用?Python pkg_resources.find_distributions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pkg_resources
的用法示例。
在下文中一共展示了pkg_resources.find_distributions方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_odoo_addon1
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def test_odoo_addon1(self):
addon1_dir = os.path.join(DATA_DIR, "setup_reusable_addons", "addon1")
subprocess.check_call([sys.executable, "setup.py", "egg_info"], cwd=addon1_dir)
egg_info_dir = os.path.join(addon1_dir, "odoo8_addon_addon1.egg-info")
assert os.path.isdir(egg_info_dir)
try:
dist = next(pkg_resources.find_distributions(addon1_dir))
self.assertEqual(dist.key, "odoo8-addon-addon1")
self.assertEqual(
dist.requires(),
[pkg_resources.Requirement.parse(r) for r in ["odoo>=8.0a,<9.0a"]],
)
self.assertTrue(dist.has_metadata("not-zip-safe"))
self.assertEqual(dist.version, "8.0.1.0.0.99.dev4")
finally:
shutil.rmtree(egg_info_dir)
示例2: test_odoo_addon2
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def test_odoo_addon2(self):
addon2_dir = os.path.join(DATA_DIR, "setup_reusable_addons", "addon2")
subprocess.check_call([sys.executable, "setup.py", "egg_info"], cwd=addon2_dir)
egg_info_dir = os.path.join(addon2_dir, "odoo8_addon_addon2.egg-info")
assert os.path.isdir(egg_info_dir)
try:
dist = next(pkg_resources.find_distributions(addon2_dir))
self.assertEqual(dist.key, "odoo8-addon-addon2")
self.assertEqual(
dist.requires(),
[
pkg_resources.Requirement.parse(r)
for r in [
"odoo8-addon-addon1",
"odoo>=8.0a,<9.0a",
"python-dateutil",
]
],
)
self.assertTrue(dist.has_metadata("not-zip-safe"))
self.assertEqual(dist.version, "8.0.1.0.1")
finally:
shutil.rmtree(egg_info_dir)
示例3: test_odoo_addon4
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def test_odoo_addon4(self):
addon4_dir = os.path.join(DATA_DIR, "setup_reusable_addons", "addon4")
subprocess.check_call([sys.executable, "setup.py", "egg_info"], cwd=addon4_dir)
egg_info_dir = os.path.join(addon4_dir, "odoo8_addon_addon4.egg-info")
assert os.path.isdir(egg_info_dir)
try:
dist = next(pkg_resources.find_distributions(addon4_dir))
self.assertEqual(dist.key, "odoo8-addon-addon4")
self.assertEqual(
dist.requires(),
[
pkg_resources.Requirement.parse(r)
for r in [
"astropy>=1.0",
"odoo8-addon-addon1>=8.0.3.0.0",
"odoo>=8.0a,<9.0a",
"python-dateutil",
]
],
)
self.assertTrue(dist.has_metadata("not-zip-safe"))
self.assertEqual(dist.version, "8.0.2.0.0")
finally:
shutil.rmtree(egg_info_dir)
示例4: parse_directory
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def parse_directory(self):
if not op.exists(self.directory):
return {}
dists = [
# this magic takes first element or None
next(iter(
pkg_resources.find_distributions(op.join(self.directory, item), True)
), None)
for item in os.listdir(self.directory) if '-' in item
]
dists.extend(
VCSDist(op.join(self.directory, item))
for item in os.listdir(self.directory) if '+' in item
)
dists = filter(None, dists)
result = defaultdict(list)
for dist in dists:
result[dist.key].append(dist)
return result
示例5: check_package_exists
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def check_package_exists(package, lib_dir):
"""Check if a package is installed globally or in lib_dir.
Returns True when the requirement is met.
Returns False when the package is not installed or doesn't meet req.
"""
try:
req = pkg_resources.Requirement.parse(package)
except ValueError:
# This is a zip file
req = pkg_resources.Requirement.parse(urlparse(package).fragment)
# Check packages from lib dir
if lib_dir is not None:
if any(dist in req for dist in
pkg_resources.find_distributions(lib_dir)):
return True
# Check packages from global + virtual environment
# pylint: disable=not-an-iterable
return any(dist in req for dist in pkg_resources.working_set)
示例6: test_distinfo
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def test_distinfo(self):
dists = {}
for d in pkg_resources.find_distributions(self.tmpdir):
dists[d.project_name] = d
assert len(dists) == 2, dists
unversioned = dists['UnversionedDistribution']
versioned = dists['VersionedDistribution']
assert versioned.version == '2.718' # from filename
assert unversioned.version == '0.3' # from METADATA
示例7: test_conditional_dependencies
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def test_conditional_dependencies(self):
requires = [pkg_resources.Requirement.parse('splort==4'),
pkg_resources.Requirement.parse('quux>=1.1')]
for d in pkg_resources.find_distributions(self.tmpdir):
self.assertEqual(d.requires(), requires[:1])
self.assertEqual(d.requires(extras=('baz',)), requires)
self.assertEqual(d.extras, ['baz'])
示例8: test_odoo_addon5
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def test_odoo_addon5(self):
addon5_dir = os.path.join(DATA_DIR, "setup_reusable_addons", "addon5")
subprocess.check_call([sys.executable, "setup.py", "egg_info"], cwd=addon5_dir)
egg_info_dir = os.path.join(addon5_dir, "odoo8_addon_addon5.egg-info")
assert os.path.isdir(egg_info_dir)
try:
dist = next(pkg_resources.find_distributions(addon5_dir))
self.assertEqual(dist.key, "odoo8-addon-addon5")
finally:
shutil.rmtree(egg_info_dir)
示例9: test_custom_project
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def test_custom_project(self):
project_dir = os.path.join(DATA_DIR, "setup_custom_project")
subprocess.check_call([sys.executable, "setup.py", "egg_info"], cwd=project_dir)
egg_info_dir = os.path.join(project_dir, "test_custom_project.egg-info")
assert os.path.isdir(egg_info_dir)
dist = next(pkg_resources.find_distributions(project_dir))
self.assertEqual(
dist.requires(),
[
pkg_resources.Requirement.parse(r)
for r in ["pyflakes", "odoo>=8.0a,<9.0a", "python-dateutil"]
],
)
self.assertFalse(dist.has_metadata("not-zip-safe"))
shutil.rmtree(egg_info_dir)
示例10: test_non_egg_dir_named_egg
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def test_non_egg_dir_named_egg(self, target_dir):
dists = pkg_resources.find_distributions(target_dir)
assert not list(dists)
示例11: test_standalone_egg_directory
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def test_standalone_egg_directory(self, project_dir, target_dir):
# install this distro as an unpacked egg:
args = [
sys.executable,
'-c', 'from setuptools.command.easy_install import main; main()',
'-mNx',
'-d', target_dir,
'--always-unzip',
project_dir,
]
subprocess.check_call(args)
dists = pkg_resources.find_distributions(target_dir)
assert [dist.project_name for dist in dists] == ['my-test-package']
dists = pkg_resources.find_distributions(target_dir, only=True)
assert not list(dists)
示例12: test_zipped_egg
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def test_zipped_egg(self, project_dir, target_dir):
# install this distro as an unpacked egg:
args = [
sys.executable,
'-c', 'from setuptools.command.easy_install import main; main()',
'-mNx',
'-d', target_dir,
'--zip-ok',
project_dir,
]
subprocess.check_call(args)
dists = pkg_resources.find_distributions(target_dir)
assert [dist.project_name for dist in dists] == ['my-test-package']
dists = pkg_resources.find_distributions(target_dir, only=True)
assert not list(dists)
示例13: __init__
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def __init__(self, directory):
self.dir = directory
name = op.split(directory)[-1]
key, encoded = name.split('+', 1)
self.key = key.lower()
self.line = b64decode(encoded).decode('utf-8')
egg, req, version = parse_vcs_requirement(self.line)
version = version or '0.0.0'
self.hashcmp = (pkg_resources_parse_version(version), -1, egg, self.dir)
self.version = self.line
self.pkg_resource = next(iter(pkg_resources.find_distributions(self.dir, True)), None)
self.location = self.pkg_resource.location
示例14: create_package_from_setup_py
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def create_package_from_setup_py(self, path_to_setup_py, custom_package_name):
"""
Creates a package from Setup.py specified in the the given path
:param path_to_setup_py:
:return: Package Information: Contains package name, version and path
"""
if os.path.isfile(path_to_setup_py):
path_to_setup_py = os.path.abspath(path_to_setup_py)
setup_py_directory = os.path.dirname(path_to_setup_py)
elif os.path.isdir(path_to_setup_py):
setup_py_directory = os.path.abspath(path_to_setup_py)
path_to_setup_py = setup_py_directory + '/setup.py'
else:
raise Exception("Given path/file: " + path_to_setup_py + " doesn't exist")
if not os.path.exists(path_to_setup_py):
raise Exception("setup.py doesn't exist in the given path: " + path_to_setup_py)
sandbox.run_setup(path_to_setup_py, ['sdist'])
eggs = find_distributions(setup_py_directory)
version = None
for egg in eggs:
if custom_package_name in egg.egg_name():
version = egg.version
if not version:
raise Exception("{package_name} not found".format(package_name=custom_package_name))
package_info = dict()
package_info['path'] = setup_py_directory + "/dist/" + custom_package_name + "-" + version + ".tar.gz"
package_info['version'] = version
package_info['name'] = custom_package_name
return package_info
示例15: get_distributions
# 需要導入模塊: import pkg_resources [as 別名]
# 或者: from pkg_resources import find_distributions [as 別名]
def get_distributions(self):
# type: () -> Generator[pkg_resources.Distribution, None, None]
"""
Retrives the distributions installed on the library path of the environment
:return: A set of distributions found on the library path
:rtype: iterator
"""
pkg_resources = self.safe_import("pkg_resources")
libdirs = self.base_paths["libdirs"].split(os.pathsep)
dists = (pkg_resources.find_distributions(libdir) for libdir in libdirs)
for dist in itertools.chain.from_iterable(dists):
yield dist