本文整理汇总了Python中pip._internal.index.PackageFinder.find_all_candidates方法的典型用法代码示例。如果您正苦于以下问题:Python PackageFinder.find_all_candidates方法的具体用法?Python PackageFinder.find_all_candidates怎么用?Python PackageFinder.find_all_candidates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pip._internal.index.PackageFinder
的用法示例。
在下文中一共展示了PackageFinder.find_all_candidates方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_finder_priority_nonegg_over_eggfragments
# 需要导入模块: from pip._internal.index import PackageFinder [as 别名]
# 或者: from pip._internal.index.PackageFinder import find_all_candidates [as 别名]
def test_finder_priority_nonegg_over_eggfragments():
"""Test PackageFinder prefers non-egg links over "#egg=" links"""
req = InstallRequirement.from_line('bar==1.0', None)
links = ['http://foo/bar.py#egg=bar-1.0', 'http://foo/bar-1.0.tar.gz']
finder = PackageFinder(links, [], session=PipSession())
with patch.object(finder, "_get_pages", lambda x, y: []):
all_versions = finder.find_all_candidates(req.name)
assert all_versions[0].location.url.endswith('tar.gz')
assert all_versions[1].location.url.endswith('#egg=bar-1.0')
link = finder.find_requirement(req, False)
assert link.url.endswith('tar.gz')
links.reverse()
finder = PackageFinder(links, [], session=PipSession())
with patch.object(finder, "_get_pages", lambda x, y: []):
all_versions = finder.find_all_candidates(req.name)
assert all_versions[0].location.url.endswith('tar.gz')
assert all_versions[1].location.url.endswith('#egg=bar-1.0')
link = finder.find_requirement(req, False)
assert link.url.endswith('tar.gz')
示例2: pip_package_versions
# 需要导入模块: from pip._internal.index import PackageFinder [as 别名]
# 或者: from pip._internal.index.PackageFinder import find_all_candidates [as 别名]
def pip_package_versions(index, package):
format_control = FormatControl(no_binary=(':all:',), only_binary=())
session = PipSession()
finder = PackageFinder([], [index], format_control=format_control, session=session,
trusted_hosts=[urlparse(index).netloc.rsplit(':', 1)[0]])
return sorted((PipPackage(str(pv.version), pv.location) for pv in finder.find_all_candidates(package)),
key=lambda pp: (pp.version, {'.tar.gz': 1, '.zip': 2, '.tar.bz2': 3}.get(pp.link.ext, 10000)))
示例3: test_finder_priority_file_over_page
# 需要导入模块: from pip._internal.index import PackageFinder [as 别名]
# 或者: from pip._internal.index.PackageFinder import find_all_candidates [as 别名]
def test_finder_priority_file_over_page(data):
"""Test PackageFinder prefers file links over equivalent page links"""
req = InstallRequirement.from_line('gmpy==1.15', None)
finder = PackageFinder(
[data.find_links],
["http://pypi.python.org/simple"],
session=PipSession(),
)
all_versions = finder.find_all_candidates(req.name)
# 1 file InstallationCandidate followed by all https ones
assert all_versions[0].location.scheme == 'file'
assert all(version.location.scheme == 'https'
for version in all_versions[1:]), all_versions
link = finder.find_requirement(req, False)
assert link.url.startswith("file://")
示例4: test_finder_priority_page_over_deplink
# 需要导入模块: from pip._internal.index import PackageFinder [as 别名]
# 或者: from pip._internal.index.PackageFinder import find_all_candidates [as 别名]
def test_finder_priority_page_over_deplink():
"""
Test PackageFinder prefers page links over equivalent dependency links
"""
req = InstallRequirement.from_line('pip==1.5.6', None)
finder = PackageFinder(
[],
["https://pypi.python.org/simple"],
process_dependency_links=True,
session=PipSession(),
)
finder.add_dependency_links([
'https://warehouse.python.org/packages/source/p/pip/pip-1.5.6.tar.gz'])
all_versions = finder.find_all_candidates(req.name)
# Check that the dependency_link is last
assert all_versions[-1].location.url.startswith('https://warehouse')
link = finder.find_requirement(req, False)
assert link.url.startswith("https://pypi"), link
示例5: test_finder_only_installs_data_require
# 需要导入模块: from pip._internal.index import PackageFinder [as 别名]
# 或者: from pip._internal.index.PackageFinder import find_all_candidates [as 别名]
def test_finder_only_installs_data_require(data):
"""
Test whether the PackageFinder understand data-python-requires
This can optionally be exposed by a simple-repository to tell which
distribution are compatible with which version of Python by adding a
data-python-require to the anchor links.
See pep 503 for more informations.
"""
# using a local index (that has pre & dev releases)
finder = PackageFinder([],
[data.index_url("datarequire")],
session=PipSession())
links = finder.find_all_candidates("fakepackage")
expected = ['1.0.0', '9.9.9']
if (2, 7) < sys.version_info < (3,):
expected.append('2.7.0')
elif sys.version_info > (3, 3):
expected.append('3.3.0')
assert {str(v.version) for v in links} == set(expected)
示例6: pip_version_check
# 需要导入模块: from pip._internal.index import PackageFinder [as 别名]
# 或者: from pip._internal.index.PackageFinder import find_all_candidates [as 别名]
def pip_version_check(session, options):
# type: (PipSession, optparse.Values) -> None
"""Check for an update for pip.
Limit the frequency of checks to once per week. State is stored either in
the active virtualenv or in the user's USER_CACHE_DIR keyed off the prefix
of the pip script path.
"""
installed_version = get_installed_version("pip")
if not installed_version:
return
pip_version = packaging_version.parse(installed_version)
pypi_version = None
try:
state = SelfCheckState(cache_dir=options.cache_dir)
current_time = datetime.datetime.utcnow()
# Determine if we need to refresh the state
if "last_check" in state.state and "pypi_version" in state.state:
last_check = datetime.datetime.strptime(
state.state["last_check"],
SELFCHECK_DATE_FMT
)
if (current_time - last_check).total_seconds() < 7 * 24 * 60 * 60:
pypi_version = state.state["pypi_version"]
# Refresh the version if we need to or just see if we need to warn
if pypi_version is None:
# Lets use PackageFinder to see what the latest pip version is
finder = PackageFinder(
find_links=options.find_links,
index_urls=[options.index_url] + options.extra_index_urls,
allow_all_prereleases=False, # Explicitly set to False
trusted_hosts=options.trusted_hosts,
session=session,
)
all_candidates = finder.find_all_candidates("pip")
if not all_candidates:
return
pypi_version = str(
max(all_candidates, key=lambda c: c.version).version
)
# save that we've performed a check
state.save(pypi_version, current_time)
remote_version = packaging_version.parse(pypi_version)
# Determine if our pypi_version is older
if (pip_version < remote_version and
pip_version.base_version != remote_version.base_version and
was_installed_by_pip('pip')):
# Advise "python -m pip" on Windows to avoid issues
# with overwriting pip.exe.
if WINDOWS:
pip_cmd = "python -m pip"
else:
pip_cmd = "pip"
logger.warning(
"You are using pip version %s, however version %s is "
"available.\nYou should consider upgrading via the "
"'%s install --upgrade pip' command.",
pip_version, pypi_version, pip_cmd
)
except Exception:
logger.debug(
"There was an error checking the latest version of pip",
exc_info=True,
)
示例7: test_find_all_candidates_find_links_and_index
# 需要导入模块: from pip._internal.index import PackageFinder [as 别名]
# 或者: from pip._internal.index.PackageFinder import find_all_candidates [as 别名]
def test_find_all_candidates_find_links_and_index(data):
finder = PackageFinder(
[data.find_links], [data.index_url('simple')], session=PipSession())
versions = finder.find_all_candidates('simple')
# first the find-links versions then the page versions
assert [str(v.version) for v in versions] == ['3.0', '2.0', '1.0', '1.0']
示例8: test_find_all_candidates_index
# 需要导入模块: from pip._internal.index import PackageFinder [as 别名]
# 或者: from pip._internal.index.PackageFinder import find_all_candidates [as 别名]
def test_find_all_candidates_index(data):
finder = PackageFinder(
[], [data.index_url('simple')], session=PipSession())
versions = finder.find_all_candidates('simple')
assert [str(v.version) for v in versions] == ['1.0']
示例9: test_find_all_candidates_find_links
# 需要导入模块: from pip._internal.index import PackageFinder [as 别名]
# 或者: from pip._internal.index.PackageFinder import find_all_candidates [as 别名]
def test_find_all_candidates_find_links(data):
finder = PackageFinder(
[data.find_links], [], session=PipSession())
versions = finder.find_all_candidates('simple')
assert [str(v.version) for v in versions] == ['3.0', '2.0', '1.0']
示例10: test_find_all_candidates_nothing
# 需要导入模块: from pip._internal.index import PackageFinder [as 别名]
# 或者: from pip._internal.index.PackageFinder import find_all_candidates [as 别名]
def test_find_all_candidates_nothing():
"""Find nothing without anything"""
finder = PackageFinder([], [], session=PipSession())
assert not finder.find_all_candidates('pip')