-
Notifications
You must be signed in to change notification settings - Fork 39
Stop upgrading plugins to the latest core branch #957
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,14 +4,13 @@ | |
| import tomlkit | ||
| import yaml | ||
| from packaging.requirements import Requirement | ||
| from packaging.version import parse | ||
| from packaging.version import Version | ||
|
|
||
|
|
||
| core_template_url = "https://raw.githubusercontent.com/pulp/pulpcore/main/template_config.yml" | ||
| CORE_TEMPLATE_URL = "https://raw.githubusercontent.com/pulp/pulpcore/main/template_config.yml" | ||
|
|
||
|
|
||
| def scan_requirement(line, supported_versions): | ||
| updated = False | ||
| def scan_requirement(line: str, supported_versions: set[Version]) -> str | None: | ||
| new_requirement = None | ||
| try: | ||
| requirement = Requirement(line) | ||
|
|
@@ -21,67 +20,69 @@ def scan_requirement(line, supported_versions): | |
| if requirement.name == "pulpcore": | ||
| for spec in requirement.specifier: | ||
| if spec.operator == ">=": | ||
| min_version = parse(spec.version) | ||
| if parse(f"{min_version.major}.{min_version.minor}") not in supported_versions: | ||
| min_version = Version(spec.version) | ||
| if ( | ||
| Version(f"{min_version.major}.{min_version.minor}") | ||
| not in supported_versions | ||
| ): | ||
| # Lowerbound is not a supported branch, modify to next lowest | ||
| valid_lowerbounds = list(requirement.specifier.filter(supported_versions)) | ||
| if valid_lowerbounds: | ||
| new_min_branch = min(valid_lowerbounds) | ||
| new_min_version = f"{new_min_branch.major}.{new_min_branch.minor}.0" | ||
| print(f"Lower bounds updated to >={new_min_version}") | ||
| new_requirement = line.replace(spec.version, new_min_version) | ||
| updated = True | ||
| elif min_version > max(supported_versions): | ||
| print("This requirement is newer than any (yet) supported branches.") | ||
| else: | ||
| print(supported_versions) | ||
| print( | ||
| "No supported lower bounds can satisfy requirement" | ||
| " range, this branch can no longer be supported." | ||
| f"No supported lower bounds {supported_versions} can satisfy" | ||
| " requirement range {requirement.specifier}, this branch can no" | ||
| " longer be supported." | ||
| ) | ||
| exit(1) | ||
| break | ||
| return updated, new_requirement | ||
| return new_requirement | ||
|
|
||
|
|
||
| def scan_pyproject_toml(supported_versions): | ||
| def scan_pyproject_toml(supported_versions: set[Version]) -> None: | ||
| changed = False | ||
| with open("pyproject.toml") as fp: | ||
| pyproject = tomlkit.load(fp) | ||
| requirements = pyproject["project"]["dependencies"] | ||
| requirements: list[str] = pyproject["project"]["dependencies"] | ||
| for i, line in enumerate(requirements): | ||
| updated, new_requirement = scan_requirement(line, supported_versions) | ||
| if updated: | ||
| new_requirement = scan_requirement(line, supported_versions) | ||
| if new_requirement is not None: | ||
| requirements[i] = new_requirement | ||
| changed = True | ||
| if changed: | ||
| with open("pyproject.toml", "w") as fp: | ||
| tomlkit.dump(pyproject, fp) | ||
|
|
||
|
|
||
| def scan_requirements_txt(supported_versions): | ||
| def scan_requirements_txt(supported_versions: set[Version]) -> None: | ||
| changed = False | ||
| with open("requirements.txt") as fp: | ||
| lines = fp.readlines() | ||
| for i, line in enumerate(lines): | ||
| requirement, sep, comment = line.partition(" #") | ||
| updated, new_requirement = scan_requirement(requirement, supported_versions) | ||
| if updated: | ||
| new_requirement = scan_requirement(requirement, supported_versions) | ||
| if new_requirement is not None: | ||
| lines[i] = new_requirement + sep + comment | ||
| changed = True | ||
| if changed: | ||
| with open("requirements.txt", "w") as fp: | ||
| fp.writelines(lines) | ||
|
|
||
|
|
||
| def main(): | ||
| request = requests.get(core_template_url) | ||
| def main() -> None: | ||
| request = requests.get(CORE_TEMPLATE_URL) | ||
| if request.status_code != 200: | ||
| print("Failed to find supported branches, not checking lower bounds") | ||
| exit(0) | ||
|
|
||
| core_template = yaml.safe_load(request.content) | ||
| supported_versions = {parse(v) for v in core_template["supported_release_branches"]} | ||
| latest = core_template["latest_release_branch"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and this is the key that will keep us from updating to latest-released over and over until a new supported is added. got it. |
||
| supported_versions.add(parse(latest)) | ||
| supported_versions = {Version(v) for v in core_template["supported_release_branches"]} | ||
| try: | ||
| scan_pyproject_toml(supported_versions) | ||
| except Exception: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍