potiuk commented on code in PR #52265:
URL: https://github.com/apache/airflow/pull/52265#discussion_r2186906211


##########
scripts/ci/pre_commit/update_installers_and_pre_commit.py:
##########
@@ -65,6 +66,31 @@ def get_latest_pypi_version(package_name: str) -> str:
     return latest_version
 
 
+def get_latest_python_version(python_major_minor: str) -> str | None:
+    latest_version = None
+    version_match = re.compile(rf"^v{python_major_minor}.*\.\d+$")
+    for i in range(5):
+        response = requests.get(
+            
f"https://api.github.com/repos/python/cpython/tags?per_page=100&page={i + 1}",
+            headers={"User-Agent": "Python requests"},
+        )
+        response.raise_for_status()  # Ensure we got a successful response
+        data = response.json()
+        versions = [str(tag["name"]) for tag in data if 
version_match.match(tag.get("name", ""))]
+        if versions:
+            latest_version = sorted(versions, key=Version, reverse=True)[0]

Review Comment:
   > They're also using a regex internally, just a more complex one 🙃 
   
   He he. But it's THEM to manage it .... :). and they're canonical. Also it's 
a bit far from the original filter to that place. How about:
   
   ``python
   def is_valid_version(v):
       try:
           Version(v)
           return True
       except InvalidVersion:
           return False
   
   valid_versions = list(filter(is_valid_version, versions))
   ```
   



##########
scripts/ci/pre_commit/update_installers_and_pre_commit.py:
##########
@@ -65,6 +66,31 @@ def get_latest_pypi_version(package_name: str) -> str:
     return latest_version
 
 
+def get_latest_python_version(python_major_minor: str) -> str | None:
+    latest_version = None
+    version_match = re.compile(rf"^v{python_major_minor}.*\.\d+$")
+    for i in range(5):
+        response = requests.get(
+            
f"https://api.github.com/repos/python/cpython/tags?per_page=100&page={i + 1}",
+            headers={"User-Agent": "Python requests"},
+        )
+        response.raise_for_status()  # Ensure we got a successful response
+        data = response.json()
+        versions = [str(tag["name"]) for tag in data if 
version_match.match(tag.get("name", ""))]
+        if versions:
+            latest_version = sorted(versions, key=Version, reverse=True)[0]

Review Comment:
   > They're also using a regex internally, just a more complex one 🙃 
   
   He he. But it's THEM to manage it .... :). and they're canonical. Also it's 
a bit far from the original filter to that place. How about:
   
   ```python
   def is_valid_version(v):
       try:
           Version(v)
           return True
       except InvalidVersion:
           return False
   
   valid_versions = list(filter(is_valid_version, versions))
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to