本文整理汇总了Python中pkg_resources.Distribution方法的典型用法代码示例。如果您正苦于以下问题:Python pkg_resources.Distribution方法的具体用法?Python pkg_resources.Distribution怎么用?Python pkg_resources.Distribution使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pkg_resources
的用法示例。
在下文中一共展示了pkg_resources.Distribution方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_simple_record
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def test_simple_record(self):
working_set = mocks.WorkingSet({__name__: [
'dummy/whatever/module.js = module',
'dummy/whatever/module-slim.js = module',
]}, dist=Distribution(project_name='calmjs.testing'))
registry = base.BaseExternalModuleRegistry(
__name__, _working_set=working_set)
self.assertEqual(len(registry.raw_entry_points), 2)
self.assertEqual(registry.get_record('module'), {
'dummy/whatever/module.js',
'dummy/whatever/module-slim.js',
})
self.assertEqual(list(registry.iter_records()), [('module', {
'dummy/whatever/module.js',
'dummy/whatever/module-slim.js',
})])
self.assertEqual(registry.get_records_for_package('calmjs.testing'), [
'dummy/whatever/module.js',
'dummy/whatever/module-slim.js',
])
示例2: test_pkg_manager_view_requires
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def test_pkg_manager_view_requires(self):
working_set = self.setup_requirements_json()
working_set.add(pkg_resources.Distribution(
metadata=MockProvider({
'requires.txt': 'calmpy.pip',
}),
project_name='site',
version='0.0.0',
))
driver = cli.PackageManagerDriver(
pkg_manager_bin='mgr', pkgdef_filename='requirements.json',
dep_keys=('require',),
)
result = driver.pkg_manager_view('site')
self.assertEqual(result, {
"require": {"setuptools": "25.1.6"},
"name": "site",
})
# try explicit
result = driver.pkg_manager_view('site', explicit=True)
self.assertEqual(result, {
"require": {},
"name": "site",
})
示例3: test_pkg_manager_view_extras_requires
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def test_pkg_manager_view_extras_requires(self):
working_set = self.setup_requirements_json()
working_set.add(pkg_resources.Distribution(
metadata=MockProvider({
'requires.txt': '[dev]\ncalmpy.pip',
}),
project_name='site',
version='0.0.0',
))
driver = cli.PackageManagerDriver(
pkg_manager_bin='mgr', pkgdef_filename='requirements.json',
dep_keys=('require',),
)
result = driver.pkg_manager_view('site')
self.assertEqual(result, {
"require": {},
"name": "site",
})
result = driver.pkg_manager_view('site[dev]')
self.assertEqual(result, {
"require": {"setuptools": "25.1.6"},
# should be "site[dev]", but npm fails on that.
"name": "site",
})
示例4: test_get_dist_package_decoding_error
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def test_get_dist_package_decoding_error(self):
# Quiet stdout from distutils logs
stub_stdouts(self)
# trailing comma
package_json = '{"dependencies": {"left-pad": "~1.1.1"},}'
# bad data could be created by a competiting package.
mock_provider = MockProvider({
self.pkgname: package_json,
})
mock_dist = pkg_resources.Distribution(
metadata=mock_provider, project_name='dummydist', version='0.0.0')
results = calmjs_dist.read_dist_egginfo_json(mock_dist)
# Should still not fail.
self.assertIsNone(results)
示例5: test_build_calmjs_artifacts_standard
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def test_build_calmjs_artifacts_standard(self):
dist = distutils_dist.Distribution()
build_cmd = dist.get_command_obj('build')
original_subcmds = list(build_cmd.sub_commands)
calmjs_dist.build_calmjs_artifacts(dist, 'build_artifact', False)
self.assertEqual(original_subcmds, build_cmd.sub_commands)
# keys are named after the build step.
calmjs_dist.build_calmjs_artifacts(dist, 'build_artifact', True)
self.assertEqual(
('build_artifact', calmjs_dist.has_calmjs_artifact_declarations),
build_cmd.sub_commands[-1],
)
calmjs_dist.build_calmjs_artifacts(dist, 'calmjs_artifact', True)
self.assertEqual(
('calmjs_artifact', calmjs_dist.has_calmjs_artifact_declarations),
build_cmd.sub_commands[-1],
)
示例6: make_dummy_dist
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def make_dummy_dist(testcase_inst, metadata_map=(),
pkgname='dummydist', version='0.0', working_dir=None):
"""
Test case helper function for creating a distribution dummy that
uses PathMetadata for the foundation for integration level testing.
"""
if working_dir is None:
working_dir = mkdtemp_singleton(testcase_inst)
egg_info = '%s-%s.egg-info' % (pkgname, version)
egg_info_dir = join(working_dir, egg_info)
if not exists(egg_info_dir):
makedirs(egg_info_dir)
metadata = PathMetadata(working_dir, egg_info_dir)
for fn, data in metadata_map:
with open(join(egg_info_dir, fn), 'w') as fd:
fd.write(data)
return Distribution(
working_dir, project_name=pkgname, metadata=metadata, version=version)
示例7: finalize_options
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def finalize_options(self):
ei_cmd = self.ei_cmd = self.get_finalized_command("egg_info")
self.egg_info = ei_cmd.egg_info
if self.bdist_dir is None:
bdist_base = self.get_finalized_command('bdist').bdist_base
self.bdist_dir = os.path.join(bdist_base, 'egg')
if self.plat_name is None:
self.plat_name = get_build_platform()
self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))
if self.egg_output is None:
# Compute filename of the output egg
basename = Distribution(
None, None, ei_cmd.egg_name, ei_cmd.egg_version,
get_python_version(),
self.distribution.has_ext_modules() and self.plat_name
).egg_name()
self.egg_output = os.path.join(self.dist_dir, basename + '.egg')
示例8: matches_requirement
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def matches_requirement(req, wheels):
"""List of wheels matching a requirement.
:param req: The requirement to satisfy
:param wheels: List of wheels to search.
"""
try:
from pkg_resources import Distribution, Requirement
except ImportError:
raise RuntimeError("Cannot use requirements without pkg_resources")
req = Requirement.parse(req)
selected = []
for wf in wheels:
f = wf.parsed_filename
dist = Distribution(project_name=f.group("name"), version=f.group("ver"))
if dist in req:
selected.append(wf)
return selected
示例9: finalize_options
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def finalize_options(self):
self.set_undefined_options('install_lib',
('install_dir', 'install_dir'))
self.set_undefined_options('install',('install_layout','install_layout'))
if sys.hexversion > 0x2060000:
self.set_undefined_options('install',('prefix_option','prefix_option'))
ei_cmd = self.get_finalized_command("egg_info")
basename = pkg_resources.Distribution(
None, None, ei_cmd.egg_name, ei_cmd.egg_version
).egg_name() + '.egg-info'
if self.install_layout:
if not self.install_layout.lower() in ['deb']:
raise DistutilsOptionError("unknown value for --install-layout")
self.install_layout = self.install_layout.lower()
basename = basename.replace('-py%s' % pkg_resources.PY_MAJOR, '')
elif self.prefix_option or 'real_prefix' in sys.__dict__:
# don't modify for virtualenv
pass
else:
basename = basename.replace('-py%s' % pkg_resources.PY_MAJOR, '')
self.source = ei_cmd.egg_info
self.target = os.path.join(self.install_dir, basename)
self.outputs = []
示例10: finalize_options
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def finalize_options(self):
ei_cmd = self.ei_cmd = self.get_finalized_command("egg_info")
self.egg_info = ei_cmd.egg_info
if self.bdist_dir is None:
bdist_base = self.get_finalized_command('bdist').bdist_base
self.bdist_dir = os.path.join(bdist_base, 'egg')
if self.plat_name is None:
self.plat_name = get_build_platform()
self.set_undefined_options('bdist',('dist_dir', 'dist_dir'))
if self.egg_output is None:
# Compute filename of the output egg
basename = Distribution(
None, None, ei_cmd.egg_name, ei_cmd.egg_version,
get_python_version(),
self.distribution.has_ext_modules() and self.plat_name
).egg_name()
self.egg_output = os.path.join(self.dist_dir, basename+'.egg')
示例11: run
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def run(self):
from setuptools.command.easy_install import get_script_args
from setuptools.command.easy_install import sys_executable
self.run_command("egg_info")
if self.distribution.scripts:
orig.install_scripts.run(self) # run first to set up self.outfiles
else:
self.outfiles = []
if self.no_ep:
# don't install entry point scripts into .egg file!
return
ei_cmd = self.get_finalized_command("egg_info")
dist = Distribution(
ei_cmd.egg_base, PathMetadata(ei_cmd.egg_base, ei_cmd.egg_info),
ei_cmd.egg_name, ei_cmd.egg_version,
)
bs_cmd = self.get_finalized_command('build_scripts')
executable = getattr(bs_cmd, 'executable', sys_executable)
is_wininst = getattr(
self.get_finalized_command("bdist_wininst"), '_is_running', False
)
for args in get_script_args(dist, executable, is_wininst):
self.write_script(*args)
示例12: __setitem__
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def __setitem__(self, key, value):
if isinstance(key, Distribution):
self.__map[key.project_name] = value
else:
self.__map[self.normalize(key)] = value
示例13: test_conflict_registration
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def test_conflict_registration(self):
# create an empty working set for a clean-slate test.
cwd = utils.mkdtemp(self)
mock_ws = WorkingSet([])
registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
# using named case for case sensitivity test.
st = join(cwd, 'calmjs_artifacts', 'Simple.js')
dist_ = Distribution(cwd, project_name='pkg', version='1.0')
dist_.egg_info = cwd # just lazy
s1 = EntryPoint.parse('Simple.js = dummy_builder:builder1')
s1.dist = dist_
s2 = EntryPoint.parse('Simple.js = dummy_builder:builder2')
s2.dist = dist_
with pretty_logging(stream=mocks.StringIO()) as stream:
registry.register_entry_point(s1)
# normal registry usage shouldn't be able to do this.
registry.register_entry_point(s2)
log = stream.getvalue()
self.assertIn(
"entry point 'Simple.js = dummy_builder:builder2' from package "
"'pkg 1.0' resolves to the path '%s' which was already "
"registered to entry point 'Simple.js = dummy_builder:builder1'; "
"conflicting entry point registration will be ignored." % st,
log
)
示例14: test_normcase_registration
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def test_normcase_registration(self):
# create an empty working set for a clean-slate test.
cwd = utils.mkdtemp(self)
mock_ws = WorkingSet([])
dist_ = Distribution(cwd, project_name='pkg', version='1.0')
dist_.egg_info = cwd # just lazy
registry = ArtifactRegistry('calmjs.artifacts', _working_set=mock_ws)
# case sensitive test; have to patch the normcase at artifact
# module with the nt version
from ntpath import normcase as nt_normcase
utils.stub_item_attr_value(self, artifact, 'normcase', nt_normcase)
# using named case for case sensitivity test.
c1 = EntryPoint.parse('case.js = dummy_builder:builder1')
c1.dist = dist_
c2 = EntryPoint.parse('Case.js = dummy_builder:builder2')
c2.dist = dist_
# use the error one
ct = join(cwd, 'calmjs_artifacts', 'Case.js')
with pretty_logging(stream=mocks.StringIO()) as stream:
registry.register_entry_point(c1)
registry.register_entry_point(c2)
log = stream.getvalue()
self.assertIn(
"entry point 'Case.js = dummy_builder:builder2' from package "
"'pkg 1.0' resolves to the path '%s' which was already "
"registered to entry point 'case.js = dummy_builder:builder1'; "
"conflicting entry point registration will be ignored." % ct,
log
)
self.assertIn(
"the file mapping error is caused by this platform's case-"
"insensitive filename", log
)
示例15: test_distribution_as_key
# 需要导入模块: import pkg_resources [as 别名]
# 或者: from pkg_resources import Distribution [as 别名]
def test_distribution_as_key(self):
mapping = base.PackageKeyMapping()
mapping[Distribution(project_name='not_normalized')] = 1
self.assertEqual(1, mapping['not_normalized'])
self.assertEqual(1, mapping[safe_name('not_normalized')])