本文整理汇总了Python中setuptools.package_index.PackageIndex.obtain方法的典型用法代码示例。如果您正苦于以下问题:Python PackageIndex.obtain方法的具体用法?Python PackageIndex.obtain怎么用?Python PackageIndex.obtain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类setuptools.package_index.PackageIndex
的用法示例。
在下文中一共展示了PackageIndex.obtain方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_upgrade
# 需要导入模块: from setuptools.package_index import PackageIndex [as 别名]
# 或者: from setuptools.package_index.PackageIndex import obtain [as 别名]
def _do_upgrade(self, dist):
# Build up a requirement for a higher bugfix release but a lower minor
# release (so API compatibility is guaranteed)
next_version = _next_version(dist.parsed_version)
req = pkg_resources.Requirement.parse(
'{0}>{1},<{2}'.format(DIST_NAME, dist.version, next_version))
package_index = PackageIndex(index_url=self.index_url)
upgrade = package_index.obtain(req)
if upgrade is not None:
return self._do_download(version=upgrade.version)
示例2: _do_upgrade
# 需要导入模块: from setuptools.package_index import PackageIndex [as 别名]
# 或者: from setuptools.package_index.PackageIndex import obtain [as 别名]
def _do_upgrade(dist, index_url):
# Build up a requirement for a higher bugfix release but a lower minor
# release (so API compatibility is guaranteed)
# sketchy version parsing--maybe come up with something a bit more
# robust for this
major, minor = (int(part) for part in dist.parsed_version[:2])
next_minor = '.'.join([str(major), str(minor + 1), '0'])
req = pkg_resources.Requirement.parse(
'{0}>{1},<{2}'.format(DIST_NAME, dist.version, next_minor))
package_index = PackageIndex(index_url=index_url)
upgrade = package_index.obtain(req)
if upgrade is not None:
return _do_download(version=upgrade.version, index_url=index_url)
示例3: bdist_pkg
# 需要导入模块: from setuptools.package_index import PackageIndex [as 别名]
# 或者: from setuptools.package_index.PackageIndex import obtain [as 别名]
#.........这里部分代码省略.........
mapping = self.requirements_mapping or {}
self.deps = self.deps or {}
seen_deps = set([])
for python_dep, spec in mapping.items():
if not isinstance(python_dep, str):
raise DistutilsOptionError('Invalid Python dependency: {}'
''.format(python_dep))
if python_dep not in install_requires:
raise DistutilsOptionError('{} is not in install requires list'
''.format(python_dep))
if not isinstance(spec, dict):
raise DistutilsOptionError('requirements_mapping items must be'
' dict, got {}'.format(repr(spec)))
if set(spec) != {'origin', 'version', 'name'}:
raise DistutilsOptionError('requirements_mapping items must'
' have "origin" and "version" keys,'
' got {}'.format(set(spec)))
for key in {'origin', 'version', 'name'}:
if not isinstance(spec[key], str):
raise DistutilsOptionError('"{}" value must be string, got'
' {}'.format(key, spec[key]))
self.deps[spec['name']] = {'origin': spec['origin'],
'version': spec['version']}
seen_deps.add(python_dep)
missing = seen_deps ^ install_requires
if missing and self.use_pypi_deps:
for item in missing:
requirement = Requirement.parse(item)
distribution = self.package_index.obtain(requirement)
key = 'py{1}{2}-{0}'.format(distribution.key,
*sys.version_info[:2])
self.deps[key] = {
'origin': 'pypi/py-{}'.format(distribution.key),
'version': distribution.version
}
elif missing:
raise DistutilsOptionError('These packages are listed in install'
' requirements, but not in bdist_pkg'
' requirements mapping: {}'
''.format(', '.join(missing)))
def ensure_desc(self, project):
desc = project.get_long_description()
desc = desc if desc != 'UKNOWN' else project.get_description()
desc = self.cut_changelog(desc)
self.ensure_string('desc', desc)
def ensure_name(self, project):
name = project.get_name()
if self.with_py_prefix:
name = 'py{}{}-{}'.format(
sys.version_info[0], sys.version_info[1], name
)
self.ensure_string('name', name)
def ensure_options(self):
provided_options = set(self.distribution.extras_require or {})
self.selected_options = set(self.selected_options or [])
unknown_options = self.selected_options - provided_options
if not unknown_options:
self.options = {option: option in self.selected_options
示例4: runit
# 需要导入模块: from setuptools.package_index import PackageIndex [as 别名]
# 或者: from setuptools.package_index.PackageIndex import obtain [as 别名]
def runit():
# process command-line options
bool_opts = map(translate_longopt, stdeb_cmd_bool_opts)
bool_opts.append("process-dependencies")
parser = FancyGetopt(stdeb_cmdline_opts + [("help", "h", "show detailed help message")] + EXTRA_OPTS)
optobj = OptObj()
args = parser.getopt(object=optobj)
idx = PackageIndex()
for option in optobj.__dict__:
value = getattr(optobj, option)
is_string = type(value) == str
if option in bool_opts and is_string:
setattr(optobj, option, strtobool(value))
if hasattr(optobj, "help"):
print USAGE
parser.set_option_table(stdeb_cmdline_opts + EXTRA_OPTS)
parser.print_help("Options:")
return 0
if len(args) != 1:
log.error("not given single argument (distfile), args=%r", args)
print USAGE
return 1
sdist_file = args[0]
package = None
final_dist_dir = optobj.__dict__.get("dist_dir", "deb_dist")
tmp_dist_dir = os.path.join(final_dist_dir, "tmp_py2dsc")
if os.path.exists(tmp_dist_dir):
shutil.rmtree(tmp_dist_dir)
os.makedirs(tmp_dist_dir)
if not os.path.isfile(sdist_file):
for ext in EXTENSIONS:
if sdist_file.endswith(ext):
raise IOError, "File not found"
package = Requirement.parse(sdist_file)
log.info("Package %s not found, trying PyPI..." % sdist_file)
dist = idx.fetch_distribution(package, final_dist_dir, force_scan=True, source=True)
if hasattr(dist, "location"):
sdist_file = dist.location
else:
raise Exception, "Distribution not found on PyPi"
log.info("Got %s", sdist_file)
dist = list(distros_for_filename(sdist_file))[0]
idx.scan_egg_links(dist.location)
package = idx.obtain(Requirement.parse(dist.project_name))
if hasattr(optobj, "process_dependencies"):
if bool(int(getattr(optobj, "process_dependencies"))):
backup_argv = sys.argv[:]
oldargv = sys.argv[:]
oldargv.pop(-1)
if package.requires():
log.info("Processing package dependencies for %s", package)
for req in package.requires():
# print >> sys.stderr
new_argv = oldargv + ["%s" % req]
log.info("Bulding dependency package %s", req)
log.info(" running '%s'", " ".join(new_argv))
sys.argv = new_argv
runit()
# print >> sys.stderr
if package.requires():
log.info("Completed building dependencies " "for %s, continuing...", package)
sys.argv = backup_argv
if package is not None and hasattr(optobj, "extra_cfg_file"):
# Allow one to have patch-files setup on config file for example
local_parser = SafeConfigParser()
local_parser.readfp(open(optobj.__dict__.get("extra_cfg_file")))
if local_parser.has_section(package.project_name):
for opt in local_parser.options(package.project_name):
_opt = opt.replace("_", "-")
if parser.has_option(_opt) or parser.has_option(_opt + "="):
setattr(optobj, opt, local_parser.get(package.project_name, opt))
patch_file = optobj.__dict__.get("patch_file", None)
patch_level = int(optobj.__dict__.get("patch_level", 0))
patch_posix = int(optobj.__dict__.get("patch_posix", 0))
expand_dir = os.path.join(tmp_dist_dir, "stdeb_tmp")
if os.path.exists(expand_dir):
shutil.rmtree(expand_dir)
if not os.path.exists(tmp_dist_dir):
os.mkdir(tmp_dist_dir)
os.mkdir(expand_dir)
expand_sdist_file(os.path.abspath(sdist_file), cwd=expand_dir)
# now the sdist package is expanded in expand_dir
expanded_root_files = os.listdir(expand_dir)
assert len(expanded_root_files) == 1
repackaged_dirname = expanded_root_files[0]
fullpath_repackaged_dirname = os.path.join(tmp_dist_dir, repackaged_dirname)
#.........这里部分代码省略.........