-
Notifications
You must be signed in to change notification settings - Fork 518
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
Script for checking if our instrumented libs are python 3.13 compatible #3425
Merged
antonpirker
merged 2 commits into
master
from
antonpirker/script-to-check-python-compatibility
Dec 5, 2024
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 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,124 @@ | ||
import time | ||
import re | ||
import sys | ||
|
||
import requests | ||
|
||
from collections import defaultdict | ||
|
||
from pathlib import Path | ||
|
||
from tox.config.cli.parse import get_options | ||
from tox.session.state import State | ||
from tox.config.sets import CoreConfigSet | ||
from tox.config.source.tox_ini import ToxIni | ||
|
||
PYTHON_VERSION = "3.13" | ||
|
||
MATCH_LIB_SENTRY_REGEX = r"py[\d\.]*-(.*)-.*" | ||
|
||
PYPI_PROJECT_URL = "https://pypi.python.org/pypi/{project}/json" | ||
PYPI_VERSION_URL = "https://pypi.python.org/pypi/{project}/{version}/json" | ||
|
||
|
||
def get_tox_envs(tox_ini_path: Path) -> list: | ||
tox_ini = ToxIni(tox_ini_path) | ||
conf = State(get_options(), []).conf | ||
tox_section = next(tox_ini.sections()) | ||
core_config_set = CoreConfigSet( | ||
conf, tox_section, tox_ini_path.parent, tox_ini_path | ||
) | ||
( | ||
core_config_set.loaders.extend( | ||
tox_ini.get_loaders( | ||
tox_section, | ||
base=[], | ||
override_map=defaultdict(list, {}), | ||
conf=core_config_set, | ||
) | ||
) | ||
) | ||
return core_config_set.load("env_list") | ||
|
||
|
||
def get_libs(tox_ini: Path, regex: str) -> set: | ||
libs = set() | ||
for env in get_tox_envs(tox_ini): | ||
match = re.match(regex, env) | ||
if match: | ||
libs.add(match.group(1)) | ||
|
||
return sorted(libs) | ||
|
||
|
||
def main(): | ||
""" | ||
Check if libraries in our tox.ini are ready for Python version defined in `PYTHON_VERSION`. | ||
""" | ||
print(f"Checking libs from tox.ini for Python {PYTHON_VERSION} compatibility:") | ||
|
||
ready = set() | ||
not_ready = set() | ||
not_found = set() | ||
|
||
tox_ini = Path(__file__).parent.parent.parent.joinpath("tox.ini") | ||
|
||
libs = get_libs(tox_ini, MATCH_LIB_SENTRY_REGEX) | ||
|
||
for lib in libs: | ||
print(".", end="") | ||
sys.stdout.flush() | ||
|
||
# Get latest version of lib | ||
url = PYPI_PROJECT_URL.format(project=lib) | ||
pypi_data = requests.get(url) | ||
|
||
if pypi_data.status_code != 200: | ||
not_found.add(lib) | ||
continue | ||
|
||
latest_version = pypi_data.json()["info"]["version"] | ||
|
||
# Get supported Python version of latest version of lib | ||
url = PYPI_PROJECT_URL.format(project=lib, version=latest_version) | ||
pypi_data = requests.get(url) | ||
|
||
if pypi_data.status_code != 200: | ||
continue | ||
|
||
classifiers = pypi_data.json()["info"]["classifiers"] | ||
|
||
if f"Programming Language :: Python :: {PYTHON_VERSION}" in classifiers: | ||
ready.add(lib) | ||
else: | ||
not_ready.add(lib) | ||
|
||
# cut pypi some slack | ||
time.sleep(0.1) | ||
|
||
# Print report | ||
print("\n") | ||
print(f"\nReady for Python {PYTHON_VERSION}:") | ||
if len(ready) == 0: | ||
print("- None ") | ||
|
||
for x in sorted(ready): | ||
print(f"- {x}") | ||
|
||
print(f"\nNOT ready for Python {PYTHON_VERSION}:") | ||
if len(not_ready) == 0: | ||
print("- None ") | ||
|
||
for x in sorted(not_ready): | ||
print(f"- {x}") | ||
|
||
print("\nNot found on PyPI:") | ||
if len(not_found) == 0: | ||
print("- None ") | ||
|
||
for x in sorted(not_found): | ||
print(f"- {x}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains 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,3 @@ | ||
requests | ||
pathlib | ||
tox |
This file contains 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,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
# exit on first error | ||
set -xe | ||
|
||
reset | ||
|
||
# create and activate virtual environment | ||
python -m venv .venv | ||
source .venv/bin/activate | ||
|
||
# Install (or update) requirements | ||
python -m pip install -r requirements.txt | ||
|
||
# Run the script | ||
python main.py |
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.
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.
pathlib has been part of the standard library since Python 3.4: https://docs.python.org/3/library/pathlib.html.
I don't think you want to install this dependency, as it hasn't been updated since 2014: https://pypi.org/project/pathlib/.
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.
Thanks for catching this! #3863