-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into consistent-ruff
- Loading branch information
Showing
15 changed files
with
133 additions
and
172 deletions.
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -7,9 +7,6 @@ | |
|
||
import functools | ||
import inspect | ||
import logging | ||
import os | ||
import subprocess | ||
import sys | ||
import warnings | ||
from dataclasses import is_dataclass | ||
|
@@ -19,8 +16,6 @@ | |
if TYPE_CHECKING: | ||
from typing import Callable, Optional, Type | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def deprecated( | ||
replacement: Optional[Callable | str] = None, | ||
|
@@ -35,8 +30,7 @@ def deprecated( | |
replacement (Callable | str): A replacement class or function. | ||
message (str): A warning message to be displayed. | ||
deadline (Optional[tuple[int, int, int]]): Optional deadline for removal | ||
of the old function/class, in format (yyyy, MM, dd). A CI warning would | ||
be raised after this date if is running in code owner' repo. | ||
of the old function/class, in format (yyyy, MM, dd). | ||
category (Warning): Choose the category of the warning to issue. Defaults | ||
to FutureWarning. Another choice can be DeprecationWarning. Note that | ||
FutureWarning is meant for end users and is always shown unless silenced. | ||
|
@@ -45,48 +39,9 @@ def deprecated( | |
the choice accordingly. | ||
Returns: | ||
Original function, but with a warning to use the updated function. | ||
Original function/class, but with a warning to use the replacement. | ||
""" | ||
|
||
def raise_deadline_warning() -> None: | ||
"""Raise CI warning after removal deadline in code owner's repo.""" | ||
|
||
def _is_in_owner_repo() -> bool: | ||
"""Check if is running in code owner's repo. | ||
Only generate reliable check when `git` is installed and remote name | ||
is "origin". | ||
""" | ||
|
||
try: | ||
# Get current running repo | ||
result = subprocess.run( | ||
["git", "config", "--get", "remote.origin.url"], | ||
stdout=subprocess.PIPE, | ||
) | ||
owner_repo = ( | ||
result.stdout.decode("utf-8") | ||
.strip() | ||
.lstrip("https://github.com/") # HTTPS clone | ||
.lstrip("[email protected]:") # SSH clone | ||
.rstrip(".git") # SSH clone | ||
) | ||
|
||
return owner_repo == os.getenv("GITHUB_REPOSITORY") | ||
|
||
except (subprocess.CalledProcessError, FileNotFoundError): | ||
return False | ||
|
||
# Only raise warning in code owner's repo CI | ||
if ( | ||
_deadline is not None | ||
and os.getenv("CI") is not None | ||
and datetime.now() > _deadline | ||
and _is_in_owner_repo() | ||
): | ||
raise DeprecationWarning( | ||
f"This function should have been removed on {_deadline:%Y-%m-%d}." | ||
) | ||
|
||
def craft_message( | ||
old: Callable, | ||
replacement: Callable | str, | ||
|
@@ -150,11 +105,8 @@ def new_init(self, *args, **kwargs): | |
|
||
return cls | ||
|
||
# Convert deadline to datetime type | ||
_deadline = datetime(*deadline) if deadline is not None else None | ||
|
||
# Raise CI warning after removal deadline | ||
raise_deadline_warning() | ||
# Convert deadline to `datetime` type | ||
_deadline: datetime | None = datetime(*deadline) if deadline is not None else None | ||
|
||
def decorator(target: Callable) -> Callable: | ||
if inspect.isfunction(target): | ||
|
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
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
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
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
Oops, something went wrong.