diff --git a/.actions/assistant.py b/.actions/assistant.py index 6d1e50e26f587..a278b1dfcd3b3 100644 --- a/.actions/assistant.py +++ b/.actions/assistant.py @@ -46,14 +46,14 @@ class _RequirementWithComment(Requirement): - strict_string = "# strict" + strict_cmd = "strict" def __init__(self, *args: Any, comment: str = "", pip_argument: Optional[str] = None, **kwargs: Any) -> None: super().__init__(*args, **kwargs) self.comment = comment assert pip_argument is None or pip_argument # sanity check that it's not an empty str self.pip_argument = pip_argument - self.strict = self.strict_string in comment.lower() + self.strict = self.strict_cmd in comment.lower() def adjust(self, unfreeze: str) -> str: """Remove version restrictions unless they are strict. @@ -62,25 +62,26 @@ def adjust(self, unfreeze: str) -> str: 'arrow<=1.2.2,>=1.2.0' >>> _RequirementWithComment("arrow<=1.2.2,>=1.2.0", comment="# strict").adjust("none") 'arrow<=1.2.2,>=1.2.0 # strict' - >>> _RequirementWithComment("arrow<=1.2.2,>=1.2.0", comment="# my name").adjust("all") - 'arrow>=1.2.0' + >>> _RequirementWithComment('arrow<=1.2.2,>=1.2.0; python_version >= "3.10"', comment="# my name").adjust("all") + 'arrow>=1.2.0; python_version >= "3.10"' >>> _RequirementWithComment("arrow>=1.2.0, <=1.2.2", comment="# strict").adjust("all") 'arrow<=1.2.2,>=1.2.0 # strict' - >>> _RequirementWithComment("arrow").adjust("all") - 'arrow' + >>> _RequirementWithComment('arrow; python_version >= "3.10"').adjust("all") + 'arrow; python_version >= "3.10"' >>> _RequirementWithComment("arrow>=1.2.0, <=1.2.2", comment="# cool").adjust("major") 'arrow<2.0,>=1.2.0' >>> _RequirementWithComment("arrow>=1.2.0, <=1.2.2", comment="# strict").adjust("major") 'arrow<=1.2.2,>=1.2.0 # strict' - >>> _RequirementWithComment("arrow>=1.2.0").adjust("major") - 'arrow>=1.2.0' + >>> _RequirementWithComment('arrow>=1.2.0; python_version >= "3.10"').adjust("major") + 'arrow>=1.2.0; python_version >= "3.10"' >>> _RequirementWithComment("arrow").adjust("major") 'arrow' """ out = str(self) if self.strict: - return f"{out} {self.strict_string}" + return f"{out} # {self.strict_cmd}" + specs = [(spec.operator, spec.version) for spec in self.specifier] if unfreeze == "major": for operator, version in specs: