本文整理汇总了Python中pip._internal.index.PackageFinder类的典型用法代码示例。如果您正苦于以下问题:Python PackageFinder类的具体用法?Python PackageFinder怎么用?Python PackageFinder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PackageFinder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_partial_name_match
def test_no_partial_name_match(data):
"""Finder requires the full project name to match, not just beginning."""
finder = PackageFinder([data.find_links], [], session=PipSession())
req = InstallRequirement.from_line("gmpy")
found = finder.find_requirement(req, False)
assert found.url.endswith("gmpy-1.15.tar.gz"), found
示例2: pip_package_versions
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_no_mpkg
def test_no_mpkg(data):
"""Finder skips zipfiles with "macosx10" in the name."""
finder = PackageFinder([data.find_links], [], session=PipSession())
req = InstallRequirement.from_line("pkgwithmpkg")
found = finder.find_requirement(req, False)
assert found.url.endswith("pkgwithmpkg-1.0.tar.gz"), found
示例4: test_tilde
def test_tilde():
"""Finder can accept a path with ~ in it and will normalize it."""
session = PipSession()
with patch('pip._internal.index.os.path.exists', return_value=True):
finder = PackageFinder(['~/python-pkgs'], [], session=session)
req = InstallRequirement.from_line("gmpy")
with pytest.raises(DistributionNotFound):
finder.find_requirement(req, False)
示例5: test_get_index_urls_locations
def test_get_index_urls_locations():
"""Check that the canonical name is on all indexes"""
finder = PackageFinder(
[], ['file://index1/', 'file://index2'], session=PipSession())
locations = finder._get_index_urls_locations(
InstallRequirement.from_line('Complex_Name').name)
assert locations == ['file://index1/complex-name/',
'file://index2/complex-name/']
示例6: test_sort_locations_file_not_find_link
def test_sort_locations_file_not_find_link(data):
"""
Test that a file:// url dir that's not a find-link, doesn't get a listdir
run
"""
finder = PackageFinder([], [], session=PipSession())
files, urls = finder._sort_locations([data.index_url("empty_with_pkg")])
assert urls and not files, "urls, but not files should have been found"
示例7: test_sort_locations_non_existing_path
def test_sort_locations_non_existing_path():
"""
Test that a non-existing path is ignored.
"""
finder = PackageFinder([], [], session=PipSession())
files, urls = finder._sort_locations(
[os.path.join('this', 'doesnt', 'exist')])
assert not urls and not files, "nothing should have been found"
示例8: test_sort_locations_file_expand_dir
def test_sort_locations_file_expand_dir(data):
"""
Test that a file:// dir gets listdir run with expand_dir
"""
finder = PackageFinder([data.find_links], [], session=PipSession())
files, urls = finder._sort_locations([data.find_links], expand_dir=True)
assert files and not urls, (
"files and not urls should have been found at find-links url: %s" %
data.find_links
)
示例9: TestLinkPackageVersions
class TestLinkPackageVersions(object):
# patch this for travis which has distribute in its base env for now
@patch(
'pip._internal.wheel.pkg_resources.get_distribution',
lambda x: Distribution(project_name='setuptools', version='0.9')
)
def setup(self):
self.version = '1.0'
self.search_name = 'pytest'
self.canonical_name = 'pytest'
self.finder = PackageFinder(
[],
[],
session=PipSession(),
)
@pytest.mark.parametrize(
'url',
[
'http:/yo/pytest-1.0.tar.gz',
'http:/yo/pytest-1.0-py2.py3-none-any.whl',
],
)
def test_link_package_versions_match(self, url):
"""Test that 'pytest' archives match for 'pytest'"""
link = Link(url)
search = Search(
supplied=self.search_name,
canonical=self.canonical_name,
formats=['source', 'binary'],
)
result = self.finder._link_package_versions(link, search)
expected = InstallationCandidate(self.search_name, self.version, link)
assert result == expected, result
@pytest.mark.parametrize(
'url',
[
# TODO: Uncomment this test case when #1217 is fixed.
# 'http:/yo/pytest-xdist-1.0.tar.gz',
'http:/yo/pytest2-1.0.tar.gz',
'http:/yo/pytest_xdist-1.0-py2.py3-none-any.whl',
],
)
def est_link_package_versions_substring_fails(self, url):
"""Test that 'pytest<something> archives won't match for 'pytest'."""
link = Link(url)
search = Search(
supplied=self.search_name,
canonical=self.canonical_name,
formats=['source', 'binary'],
)
result = self.finder._link_package_versions(link, search)
assert result is None, result
示例10: test_duplicates_sort_ok
def test_duplicates_sort_ok(data):
"""Finder successfully finds one of a set of duplicates in different
locations"""
finder = PackageFinder(
[data.find_links, data.find_links2],
[],
session=PipSession(),
)
req = InstallRequirement.from_line("duplicate")
found = finder.find_requirement(req, False)
assert found.url.endswith("duplicate-1.0.tar.gz"), found
示例11: test_wheel_over_sdist_priority
def test_wheel_over_sdist_priority(self, data):
"""
Test wheels have priority over sdists.
`test_link_sorting` also covers this at lower level
"""
req = InstallRequirement.from_line("priority")
finder = PackageFinder(
[data.find_links],
[],
session=PipSession(),
)
found = finder.find_requirement(req, True)
assert found.url.endswith("priority-1.0-py2.py3-none-any.whl"), found
示例12: test_get_formatted_locations_basic_auth
def test_get_formatted_locations_basic_auth():
"""
Test that basic authentication credentials defined in URL
is not included in formatted output.
"""
index_urls = [
'https://pypi.org/simple',
'https://user:[email protected]',
]
finder = PackageFinder([], index_urls, session=[])
result = finder.get_formatted_locations()
assert 'user' not in result and 'pass' not in result
示例13: test_finder_installs_dev_releases
def test_finder_installs_dev_releases(data):
"""
Test PackageFinder finds dev releases if asked to.
"""
req = InstallRequirement.from_line("bar", None)
# using a local index (that has dev releases)
finder = PackageFinder(
[], [data.index_url("dev")],
allow_all_prereleases=True,
session=PipSession(),
)
link = finder.find_requirement(req, False)
assert link.url.endswith("bar-2.0.dev1.tar.gz"), link.url
示例14: test_finder_detects_latest_already_satisfied_find_links
def test_finder_detects_latest_already_satisfied_find_links(data):
"""Test PackageFinder detects latest already satisfied using find-links"""
req = InstallRequirement.from_line('simple', None)
# the latest simple in local pkgs is 3.0
latest_version = "3.0"
satisfied_by = Mock(
location="/path",
parsed_version=parse_version(latest_version),
version=latest_version
)
req.satisfied_by = satisfied_by
finder = PackageFinder([data.find_links], [], session=PipSession())
with pytest.raises(BestVersionAlreadyInstalled):
finder.find_requirement(req, True)
示例15: test_finder_deplink
def test_finder_deplink():
"""
Test PackageFinder with dependency links only
"""
req = InstallRequirement.from_line('gmpy==1.15', None)
finder = PackageFinder(
[],
[],
process_dependency_links=True,
session=PipSession(),
)
finder.add_dependency_links(
['https://pypi.python.org/packages/source/g/gmpy/gmpy-1.15.zip'])
link = finder.find_requirement(req, False)
assert link.url.startswith("https://pypi"), link