From 5e7da05f0838780a95b9dd8628a7945e19b641fd Mon Sep 17 00:00:00 2001 From: frostming Date: Wed, 22 Jan 2020 16:16:24 +0800 Subject: [PATCH] get pypi source url from pip.conf Fix #3 PS. functools32 is a malformed package that will fail when trying to build a wheel on it. The current solution is to get metadata from pypi json api,but for private registries, it will still fail. --- pdm/cli/actions.py | 1 + pdm/models/repositories.py | 4 ++-- pdm/utils.py | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pdm/cli/actions.py b/pdm/cli/actions.py index 9db848c6..8b54a28b 100644 --- a/pdm/cli/actions.py +++ b/pdm/cli/actions.py @@ -90,6 +90,7 @@ def do_lock( flat_reqs = list( itertools.chain(*[deps.values() for _, deps in requirements.items()]) ) + # TODO: switch reporter at io level. with halo.Halo(text="Resolving dependencies", spinner="dots") as spin: reporter = SpinnerReporter(flat_reqs, spin) mapping, dependencies, summaries = resolve( diff --git a/pdm/models/repositories.py b/pdm/models/repositories.py index 9590812f..24f1b91c 100644 --- a/pdm/models/repositories.py +++ b/pdm/models/repositories.py @@ -14,7 +14,7 @@ from pdm.models.requirements import ( ) from pdm.models.specifiers import PySpecSet, SpecifierSet from pdm._types import CandidateInfo, Source -from pdm.utils import _allow_all_wheels +from pdm.utils import _allow_all_wheels, get_pypi_source if TYPE_CHECKING: from pdm.models.environment import Environment @@ -34,7 +34,7 @@ def cache_result( class BaseRepository: def __init__(self, sources: List[Source], environment: Environment) -> None: - self.sources = sources + self.sources = [get_pypi_source()] + sources self.environment = environment self._candidate_info_cache = context.make_candidate_info_cache() self._hash_cache = context.make_hash_cache() diff --git a/pdm/utils.py b/pdm/utils.py index 376fa2a2..8a4f3e9f 100644 --- a/pdm/utils.py +++ b/pdm/utils.py @@ -209,6 +209,18 @@ def prepare_pip_source_args( return pip_args +def get_pypi_source(): + """Get what is defined in pip.conf as the index-url.""" + install_cmd = InstallCommand() + options, _ = install_cmd.parser.parse_args([]) + index_url = options.index_url + parsed = parse.urlparse(index_url) + verify_ssl = parsed.scheme == "https" + if any(parsed.hostname.startswith(host) for host in options.trusted_hosts): + verify_ssl = False + return {"url": index_url, "name": "pypi", "verify_ssl": verify_ssl} + + def get_finder( sources: List[Source], cache_dir: Optional[str] = None, -- GitLab