Skip to content
Open
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
19 changes: 10 additions & 9 deletions .actions/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down
Loading