Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pdm install from requirements.txt does not consider auto selected python version #3097

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3095.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Consider the auto-selected Python range when installing from requirements.txt.
12 changes: 7 additions & 5 deletions src/pdm/formats/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any, Iterable, Mapping

from pdm.environments import BareEnvironment
from pdm.exceptions import PdmException, PdmUsageError
from pdm.formats.base import make_array
from pdm.models.requirements import FileRequirement, Requirement, parse_requirement
Expand All @@ -16,8 +17,8 @@
from argparse import Namespace
from os import PathLike

from pdm.environments import BaseEnvironment
from pdm.models.candidates import Candidate
from pdm.models.session import PDMPyPIClient
from pdm.project import Project


Expand All @@ -28,7 +29,7 @@ class RequirementParser:

# TODO: support no_binary, only_binary, prefer_binary, pre and no_index

def __init__(self, environment: BaseEnvironment) -> None:
def __init__(self, session: PDMPyPIClient) -> None:
self.requirements: list[Requirement] = []
self.index_url: str | None = None
self.extra_index_urls: list[str] = []
Expand All @@ -44,7 +45,7 @@ def __init__(self, environment: BaseEnvironment) -> None:
parser.add_argument("-e", "--editable", nargs="+")
parser.add_argument("-r", "--requirement")
self._parser = parser
self._env = environment
self._session = session

def _clean_line(self, line: str) -> str:
"""Strip the surrounding whitespaces and comment from the line"""
Expand Down Expand Up @@ -95,7 +96,7 @@ def parse_lines(self, lines: Iterable[str], filename: str = "<temp file>") -> No
def parse_file(self, filename_or_url: str) -> None:
parsed = urllib.parse.urlparse(filename_or_url)
if parsed.scheme in ("http", "https", "file"):
resp = self._env.session.get(filename_or_url)
resp = self._session.get(filename_or_url)
if resp.is_error: # pragma: no cover
raise PdmException(
f"Failed to fetch {filename_or_url}: ({resp.status_code} - {resp.reason_phrase}) {resp.text}"
Expand Down Expand Up @@ -143,7 +144,8 @@ def convert_url_to_source(url: str, name: str | None, trusted_hosts: list[str],


def convert(project: Project, filename: PathLike, options: Namespace) -> tuple[Mapping[str, Any], Mapping[str, Any]]:
parser = RequirementParser(project.environment)
env = BareEnvironment(project)
parser = RequirementParser(env.session)
parser.parse_file(str(filename))
backend = project.backend

Expand Down
2 changes: 1 addition & 1 deletion src/pdm/resolver/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def overrides(self) -> dict[str, Requirement]:
requirements[r.identify()] = r

# Read from --override files
parser = RequirementParser(self.repository.environment)
parser = RequirementParser(self.repository.environment.session)
for override_file in self.repository.environment.project.core.state.overrides:
parser.parse_file(override_file)
for r in parser.requirements:
Expand Down
Loading