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 dropped leading characters c from constraints' packages #3250

Merged
merged 2 commits into from
Mar 24, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/3247.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issue that the leading character ``c`` was dropped from packages in constraints files - by :user:`jugmac00`.
12 changes: 10 additions & 2 deletions src/tox/tox_env/python/pip/pip_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def constrain_package_deps(self) -> bool:
def use_frozen_constraints(self) -> bool:
return bool(self._env.conf["use_frozen_constraints"])

def _install_requirement_file(self, arguments: PythonDeps, section: str, of_type: str) -> None:
def _install_requirement_file(self, arguments: PythonDeps, section: str, of_type: str) -> None: # noqa: C901
try:
new_options, new_reqs = arguments.unroll()
except ValueError as exception:
Expand Down Expand Up @@ -145,7 +145,15 @@ def _install_requirement_file(self, arguments: PythonDeps, section: str, of_type
if args: # pragma: no branch
self._execute_installer(args, of_type)
if self.constrain_package_deps and not self.use_frozen_constraints:
combined_constraints = new_requirements + [c.lstrip("-c ") for c in new_constraints]
# when we drop Python 3.8 we can use the builtin `.removeprefix`
def remove_prefix(text: str, prefix: str) -> str:
if text.startswith(prefix):
return text[len(prefix) :]
return text

combined_constraints = new_requirements + [
remove_prefix(text=c, prefix="-c ") for c in new_constraints
]
self.constraints_file().write_text("\n".join(combined_constraints))

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions tests/tox_env/python/pip/test_pip_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ def constrained_mock_project(
"build.py": (demo_pkg_inline / "build.py").read_text(),
}
exp_constraints: list[str] = []
requirement = "foo==1.2.3"
constraint = "foo<2"
requirement = "coo==1.2.3"
constraint = "coo<2"
if request.param == "explicit":
deps = requirement
exp_constraints.append(requirement)
Expand Down