3838from airflow_breeze .utils .console import Output , console_print
3939from airflow_breeze .utils .docker_command_utils import execute_command_in_shell
4040from airflow_breeze .utils .github import download_constraints_file
41+ from airflow_breeze .utils .packages import load_pyproject_toml
4142from airflow_breeze .utils .parallel import get_temp_file_name
4243from airflow_breeze .utils .path_utils import AIRFLOW_ROOT_PATH
4344from airflow_breeze .utils .shared_options import get_verbose
@@ -86,6 +87,15 @@ def is_valid_version(version_str: str, latest_version: Version) -> bool:
8687 return False
8788
8889
90+ def is_newer_version (candidate : str , reference : str ) -> bool :
91+ from packaging import version
92+
93+ try :
94+ return version .parse (candidate ) > version .parse (reference )
95+ except version .InvalidVersion :
96+ return False
97+
98+
8999def count_versions_between (releases : dict [str , Any ], current_version : str , latest_version : str ):
90100 from packaging import version
91101
@@ -185,14 +195,13 @@ def should_show_package(releases, latest_version, constraints_date, mode, is_lat
185195 return True
186196
187197
188- def get_latest_version_with_cooldown (releases : dict [str , Any ], cooldown_days : int ) -> str | None :
189- """Find the latest non-prerelease version whose release date is outside the cooldown period .
198+ def get_latest_version_with_cooldown (releases : dict [str , Any ], cutoff : datetime | None ) -> str | None :
199+ """Find the latest non-prerelease version uploaded no later than ``cutoff`` (any time if None) .
190200
191201 Returns the version string, or None if no version qualifies.
192202 """
193203 from packaging import version
194204
195- cutoff = datetime .now () - timedelta (days = cooldown_days )
196205 candidates : list [tuple [version .Version , str ]] = []
197206 for v , release_files in releases .items ():
198207 if not release_files :
@@ -211,14 +220,54 @@ def get_latest_version_with_cooldown(releases: dict[str, Any], cooldown_days: in
211220 ).replace (tzinfo = None )
212221 except (KeyError , IndexError , ValueError ):
213222 continue
214- if upload_time <= cutoff :
223+ if cutoff is None or upload_time <= cutoff :
215224 candidates .append ((parsed_v , v ))
216225 if not candidates :
217226 return None
218227 candidates .sort (key = lambda x : x [0 ], reverse = True )
219228 return candidates [0 ][1 ]
220229
221230
231+ def load_cooldown_overrides () -> dict [str , bool | str ]:
232+ """Per-package ``exclude-newer-package`` entries of the root pyproject.toml, by canonical name.
233+
234+ The constraints are resolved under these rules (Airflow's own distributions are exempt from
235+ the cooldown, a few packages have a moved cutoff), so "latest" has to be read under the same
236+ rules or the check flags pins that resolved exactly as configured.
237+ """
238+ from packaging .utils import canonicalize_name
239+
240+ tool_uv = load_pyproject_toml (AIRFLOW_ROOT_PATH / "pyproject.toml" ).get ("tool" , {}).get ("uv" , {})
241+ return {
242+ canonicalize_name (name ): value for name , value in tool_uv .get ("exclude-newer-package" , {}).items ()
243+ }
244+
245+
246+ _DURATION_RE = re .compile (r"^\s*(\d+(?:\.\d+)?)\s*(minute|hour|day)s?\s*$" )
247+
248+
249+ def get_release_cutoff (pkg : str , cooldown_days : int , overrides : dict [str , bool | str ]) -> datetime | None :
250+ """Return the newest upload time still eligible as ``latest`` for ``pkg``, None for no limit.
251+
252+ Mirrors the ``exclude-newer-package`` values uv accepts: ``false`` lifts the cooldown, a
253+ timestamp fixes the cutoff, a duration such as ``"12 hours"`` replaces the window.
254+ """
255+ from packaging .utils import canonicalize_name
256+
257+ override = overrides .get (canonicalize_name (pkg ))
258+ if override is False :
259+ return None
260+ if isinstance (override , str ):
261+ if match := _DURATION_RE .match (override ):
262+ amount , unit = float (match .group (1 )), match .group (2 )
263+ return datetime .now () - timedelta (** {f"{ unit } s" : amount })
264+ try :
265+ return datetime .fromisoformat (override .replace ("Z" , "+00:00" )).replace (tzinfo = None )
266+ except ValueError :
267+ console_print (f"[yellow]Ignoring unparsable exclude-newer-package value for { pkg } : { override } [/]" )
268+ return datetime .now () - timedelta (days = cooldown_days )
269+
270+
222271def get_first_newer_release_date_str (releases , current_version ):
223272 from packaging import version
224273
@@ -265,7 +314,12 @@ def constraints_version_check(
265314):
266315 console_print (f"[bold cyan]Python version:[/] [white]{ python } [/]" )
267316 console_print (f"[bold cyan]Constraints mode:[/] [white]{ airflow_constraints_mode } [/]" )
268- console_print (f"[bold cyan]Cooldown period:[/] [white]{ cooldown_days } days[/]\n " )
317+ cooldown_overrides = load_cooldown_overrides ()
318+ exempt_count = sum (1 for value in cooldown_overrides .values () if value is False )
319+ console_print (
320+ f"[bold cyan]Cooldown period:[/] [white]{ cooldown_days } days[/] "
321+ f"[white]({ exempt_count } distributions exempt via exclude-newer-package)[/]\n "
322+ )
269323 with tempfile .TemporaryDirectory () as temp_dir :
270324 constraints_file = Path (temp_dir ) / "constraints.txt"
271325 download_constraints_file (
@@ -302,6 +356,7 @@ def constraints_version_check(
302356 airflow_constraints_mode = airflow_constraints_mode ,
303357 github_repository = github_repository ,
304358 cooldown_days = cooldown_days ,
359+ cooldown_overrides = cooldown_overrides ,
305360 )
306361
307362 print_table_footer (
@@ -445,6 +500,7 @@ def process_packages(
445500 airflow_constraints_mode : str ,
446501 github_repository : str | None ,
447502 cooldown_days : int = 4 ,
503+ cooldown_overrides : dict [str , bool | str ] | None = None ,
448504) -> tuple [int , int , list [str ], dict [str , int ]]:
449505 def fetch_pypi_data (pkg : str ) -> dict :
450506 pypi_url = f"https://pypi.org/pypi/{ pkg } /json"
@@ -472,8 +528,13 @@ def get_release_dates(releases: dict, version: str) -> str:
472528 try :
473529 data = fetch_pypi_data (pkg )
474530 releases = data ["releases" ]
475- latest_version_with_cooldown = get_latest_version_with_cooldown (releases , cooldown_days )
531+ cutoff = get_release_cutoff (pkg , cooldown_days , cooldown_overrides or {})
532+ latest_version_with_cooldown = get_latest_version_with_cooldown (releases , cutoff )
476533 latest_version = latest_version_with_cooldown or data ["info" ]["version" ]
534+ if is_newer_version (pinned_version , latest_version ):
535+ # The pin can still be ahead of `latest` (an override dropped after the constraints
536+ # resolved with it): nothing to upgrade to, so nothing to explain.
537+ latest_version = pinned_version
477538 latest_release_date = get_release_dates (releases , latest_version )
478539 constraint_release_date = get_release_dates (releases , pinned_version )
479540 is_latest_version = pinned_version == latest_version
@@ -491,7 +552,7 @@ def get_release_dates(releases: dict, version: str) -> str:
491552 format_str = format_str ,
492553 is_latest_version = is_latest_version ,
493554 versions_behind_str = versions_behind_str ,
494- cooldown_days = cooldown_days ,
555+ cooldown_days = 0 if cutoff is None else cooldown_days ,
495556 )
496557 status_counts [status_category ] += 1
497558 if not is_latest_version :
0 commit comments