-
Notifications
You must be signed in to change notification settings - Fork 40
SDK: Bump required Python version to >= 3.9, Add version CI check #332
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
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| """ | ||
| This helper script checks if the Python versions defined in a `pyproject.toml` coincide with the given `min_version` | ||
| and `max_version` and returns an error if they don't. | ||
| """ | ||
| import re | ||
| import argparse | ||
| import sys | ||
| from packaging.version import Version, InvalidVersion | ||
|
|
||
| def main(pyproject_toml_path: str, min_version: str, max_version: str) -> None: | ||
| # Load and check `requires-python` version from `pyproject.toml` | ||
| try: | ||
| with open(pyproject_toml_path, "r") as f: | ||
| pyproject_content = f.read() | ||
|
|
||
| match = re.search(r'requires-python\s*=\s*">=([\d.]+)"', pyproject_content) | ||
| if not match: | ||
| print(f"Error: `requires-python` field not found or invalid format in `{pyproject_toml_path}`") | ||
| sys.exit(1) | ||
|
|
||
| pyproject_version = match.group(1) | ||
| if Version(pyproject_version) < Version(min_version): | ||
| print(f"Error: Python version in `{pyproject_toml_path}` `requires-python` ({pyproject_version}) " | ||
| f"is smaller than `min_version` ({min_version}).") | ||
| sys.exit(1) | ||
|
|
||
| except FileNotFoundError: | ||
| print(f"Error: File not found: `{pyproject_toml_path}`.") | ||
| sys.exit(1) | ||
|
|
||
| print(f"Success: Version in pyproject.toml `requires-python` (>={pyproject_version}) " | ||
| f"matches expected versions ([{min_version} to {max_version}]).") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser(description="Check Python version support and alignment with pyproject.toml.") | ||
| parser.add_argument("pyproject_toml_path", help="Path to the `pyproject.toml` file to check.") | ||
| parser.add_argument("min_version", help="The minimum Python version.") | ||
| parser.add_argument("max_version", help="The maximum Python version.") | ||
| args = parser.parse_args() | ||
|
|
||
| try: | ||
| main(args.pyproject_toml_path, args.min_version, args.max_version) | ||
| except InvalidVersion: | ||
| print("Error: Invalid version format provided.") | ||
| sys.exit(1) |
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| requests>=2.23 | ||
| packaging>=24.2 |
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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| """ | ||
| This helper script checks that the provided `min_version` and `max_version` are supported and released, respectively, | ||
| using the API from the great https://github.com/endoflife-date/endoflife.date project. | ||
| """ | ||
| import argparse | ||
| import sys | ||
| import requests | ||
| from packaging.version import InvalidVersion | ||
| from datetime import datetime | ||
|
|
||
| def main(min_version: str, max_version: str) -> None: | ||
| # Fetch supported Python versions and check min/max versions | ||
| try: | ||
| response = requests.get("https://endoflife.date/api/python.json") | ||
| response.raise_for_status() | ||
| eol_data = response.json() | ||
| eol_versions = {entry["cycle"]: {"eol": entry["eol"], "releaseDate": entry["releaseDate"]} for entry in eol_data} | ||
|
|
||
| # Get current date to compare with EoL and release dates | ||
| current_date = datetime.now().date() | ||
|
|
||
| # Check min_version EoL status | ||
| min_eol_date = eol_versions.get(min_version, {}).get("eol") | ||
| if min_eol_date and datetime.strptime(min_eol_date, "%Y-%m-%d").date() <= current_date: | ||
| print(f"Error: min_version {min_version} has reached End-of-Life.") | ||
| sys.exit(1) | ||
|
|
||
| # Check max_version EoL and release status | ||
| max_info = eol_versions.get(max_version) | ||
| if max_info: | ||
| max_eol_date = max_info["eol"] | ||
| max_release_date = max_info["releaseDate"] | ||
|
|
||
| # Check if max_version has a release date in the future | ||
| if max_release_date and datetime.strptime(max_release_date, "%Y-%m-%d").date() > current_date: | ||
| print(f"Error: max_version {max_version} has not been officially released yet.") | ||
| sys.exit(1) | ||
|
|
||
| # Check if max_version has reached EoL | ||
| if max_eol_date and datetime.strptime(max_eol_date, "%Y-%m-%d").date() <= current_date: | ||
| print(f"Error: max_version {max_version} has reached End-of-Life.") | ||
| sys.exit(1) | ||
|
|
||
| except requests.RequestException: | ||
| print("Error: Failed to fetch Python version support data.") | ||
| sys.exit(1) | ||
|
|
||
| print(f"Version check passed: min_version [{min_version}] is supported " | ||
| f"and max_version [{max_version}] is released.") | ||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser(description="Check Python version support and alignment with pyproject.toml.") | ||
| parser.add_argument("min_version", help="The minimum Python version.") | ||
| parser.add_argument("max_version", help="The maximum Python version.") | ||
| args = parser.parse_args() | ||
|
|
||
| try: | ||
| main(args.min_version, args.max_version) | ||
| except InvalidVersion: | ||
| print("Error: Invalid version format provided.") | ||
| sys.exit(1) |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.