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

Enforce constraints during install_package_deps #2888

Merged
merged 4 commits into from
Jan 25, 2023
Merged
Changes from 2 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
10 changes: 3 additions & 7 deletions src/tox/tox_env/python/pip/pip_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,14 @@ def _install_requirement_file(self, arguments: PythonDeps, section: str, of_type
raise Recreate(f"requirements removed: {' '.join(missing_requirement)}")
if old.get("constraint_options") != constraint_options:
raise Recreate(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msg =  f"constraint options changed: old={old.get('constraint_options')} new={constraint_options}"
raise Recreate(msg)

would save you a line here 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought so too, but black disagreed

diff --git a/src/tox/tox_env/python/pip/pip_install.py b/src/tox/tox_env/python/pip/pip_install.py
index 640c1356..e608c2b7 100644
--- a/src/tox/tox_env/python/pip/pip_install.py
+++ b/src/tox/tox_env/python/pip/pip_install.py
@@ -134,7 +134,9 @@ class Pip(Installer[Python]):
                     if missing_requirement:
                         raise Recreate(f"requirements removed: {' '.join(missing_requirement)}")
                     if old.get("constraint_options") != constraint_options:
-                        msg = f"constraint options changed: old={old.get('constraint_options')} new={constraint_options}"
+                        msg = (
+                            f"constraint options changed: old={old.get('constraint_options')} new={constraint_options}"
+                        )
                         raise Recreate(msg)
                 args = arguments.as_root_args
                 if args:  # pragma: no branch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i ended up making it a little cleaner by assigning old_constraint_options = old.get("constraint_options")

"constraint options changed: old={} new={}".format(
old.get("constraint_options"),
constraint_options,
),
f"constraint options changed: old={old.get('constraint_options')} new={constraint_options}",
)
args = arguments.as_root_args
if args: # pragma: no branch
self._execute_installer(args, of_type)
if self.constrain_package_deps and not self.use_frozen_constraints:
self.constraints_file().write_text(
"\n".join(new_requirements + [c.lstrip("-c ") for c in new_constraints]),
)
combined_constraints = new_requirements + [c.lstrip("-c ") for c in new_constraints]
self.constraints_file().write_text("\n".join(combined_constraints))

@staticmethod
def _recreate_if_diff(of_type: str, new_opts: list[str], old_opts: list[str], fmt: Callable[[str], str]) -> None:
Expand Down