-
Notifications
You must be signed in to change notification settings - Fork 17
add script to retrieve supported Python versions, optionally from package source metadata #326
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -203,3 +203,6 @@ $RECYCLE.BIN/ | |
| ### Pycharm | ||
| .idea | ||
| .history | ||
|
|
||
| # packaging | ||
| uv.lock | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # /// script | ||
| # requires-python = ">=3.12" | ||
| # dependencies = [ | ||
| # "click==8.2.1", | ||
| # "peppyproject==1.0.2", | ||
| # "requests==2.32.5", | ||
| # "packaging==25.0", | ||
| # ] | ||
| # /// | ||
| import os | ||
| import warnings | ||
| from pathlib import Path | ||
|
|
||
| import click | ||
| import requests | ||
| from packaging.specifiers import SpecifierSet | ||
| from packaging.version import Version | ||
| from peppyproject import PyProjectConfiguration | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.option("--source", default=None) | ||
| @click.option("--factors", default=None) | ||
| @click.option("--no-eoas", is_flag=True, default=False) | ||
| @click.option("--platforms", default=None) | ||
| def supported_python_envs_block( | ||
| source: Path = None, | ||
| factors: list[str] = None, | ||
| no_eoas: bool = False, | ||
| platforms: list[str] = None, | ||
| ): | ||
| """enumerate toxenvs Python from a package source""" | ||
|
|
||
| if platforms is None: | ||
| platforms = ["linux"] | ||
| elif isinstance(platforms, str): | ||
| platforms = platforms.split(",") | ||
|
|
||
| toxenvs = supported_python_toxenvs(source, factors, no_eoas) | ||
| envs_block = "\\n".join( | ||
|
Contributor
Author
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. escaping the |
||
| f"- {platform}: {toxenv}" for platform in platforms for toxenv in toxenvs | ||
| ) | ||
|
|
||
| print(envs_block) | ||
| with open(os.environ["GITHUB_OUTPUT"], "a") as f: | ||
| f.write(f"envs={envs_block}\n") | ||
|
|
||
|
|
||
| def supported_python_toxenvs( | ||
| source: Path = None, | ||
| factors: list[str] = None, | ||
| no_eoas: bool = False, | ||
| ) -> list[str]: | ||
| if isinstance(factors, str): | ||
| factors = factors.split(",") | ||
|
|
||
| current_pythons = current_python_versions(no_eoas=no_eoas) | ||
|
|
||
| if source is None or source == "": | ||
| supported_pythons = current_pythons | ||
| else: | ||
| configuration = PyProjectConfiguration.from_directory(source) | ||
| try: | ||
| python_requirements = SpecifierSet(configuration["project"]["requires-python"]) | ||
|
|
||
| supported_pythons = [ | ||
| python for python in current_pythons if python in python_requirements | ||
| ] | ||
| except (KeyError, TypeError): | ||
| warnings.warn( | ||
| "could not find `requires-python` in metadata; falling back to current Python versions..." | ||
| ) | ||
| supported_pythons = current_pythons | ||
|
|
||
| return [ | ||
| f"py{str(python).replace('.', '')}{'-' + '-'.join(factors) if factors is not None and len(factors) > 0 else ''}" | ||
| for python in supported_pythons | ||
| ] | ||
|
|
||
|
|
||
| def current_python_versions(no_eoas: bool = False) -> list[Version]: | ||
| url = "https://endoflife.date/api/v1/products/python" | ||
| response = requests.get("https://endoflife.date/api/v1/products/python") | ||
| if response.status_code == 200: | ||
| return [ | ||
| Version(python["name"]) | ||
| for python in response.json()["result"]["releases"] | ||
| if not python["isEoas" if no_eoas else "isEol"] | ||
| ] | ||
| else: | ||
| raise ValueError(f"request returned status code {response.status_code} [{url}]") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| supported_python_envs_block() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,7 +37,7 @@ def load_tox_targets(envs, libraries, posargs, toxdeps, toxargs, pytest, pytest_ | |
| cache_restore_keys, artifact_path, runs_on, default_python, timeout_minutes): | ||
| """Script to load tox targets for GitHub Actions workflow.""" | ||
| # Load envs config | ||
| envs = yaml.load(envs, Loader=yaml.BaseLoader) | ||
| envs = yaml.load(envs.replace("\\n", "\n"), Loader=yaml.BaseLoader) | ||
|
Contributor
Author
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. here's where the aforementioned |
||
| print(json.dumps(envs, indent=2)) | ||
|
|
||
| # Load global libraries config | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.