Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 45 additions & 4 deletions tools/find_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import ast
from datetime import datetime
import sys
import argparse
import requests


Expand Down Expand Up @@ -60,6 +61,7 @@ def __init__(
self.decorator_node = decorator_node
self.func_node = func_node
self._since: str | None = None
self._pending: bool | None = None

@property
def since(self) -> str | None:
Expand All @@ -70,6 +72,16 @@ def since(self) -> str | None:
self._since = ".".join(cast(ast.Constant, kwarg.value).value.split(".")[:2])
return self._since

@property
def pending(self) -> bool | None:
"""If it is a pending deprecation."""
if not self._pending:
self._pending = False
for kwarg in self.decorator_node.keywords:
if kwarg.arg == "pending":
self._pending = kwarg.value.value
Comment thread
1ucian0 marked this conversation as resolved.
Outdated
return self._pending

@property
def lineno(self) -> int:
"""Line number of the decorator."""
Expand Down Expand Up @@ -207,8 +219,9 @@ def find_deprecations(file_name: Path) -> list[Deprecation]:
return decorator_visitor.deprecations


if __name__ == "__main__":
collection = DeprecationCollection(Path(__file__).joinpath("..", "..", "qiskit").resolve())
def print_main(directory, pending):
Comment thread
1ucian0 marked this conversation as resolved.
Outdated
"""Prints output"""
collection = DeprecationCollection(Path(directory))
collection.group_by("since")

DATA_JSON = LAST_TIME_MINOR = DETAILS = None
Expand Down Expand Up @@ -236,6 +249,34 @@ def find_deprecations(file_name: Path) -> list[Deprecation]:
DETAILS += f" (wrt last minor release, {round(diff_days / 30.4)} month old)"
except KeyError:
DETAILS = "Future release"
print(f"\n{since_version}: {DETAILS}")
lines = []
for deprecation in deprecations:
print(f" - {deprecation.location_str} ({deprecation.target})")
is_pending = " - PENDING" if deprecation.pending else ""
if pending == "include":
lines.append(f" - {deprecation.location_str} ({deprecation.target}){is_pending}")
if pending == "only" and deprecation.pending:
lines.append(f" - {deprecation.location_str} ({deprecation.target}){is_pending}")
if pending == "exclude" and not deprecation.pending:
lines.append(f" - {deprecation.location_str} ({deprecation.target})")
Comment thread
1ucian0 marked this conversation as resolved.
Outdated
if lines:
print(f"\n{since_version}: {DETAILS}")
print("\n".join(lines))


if __name__ == "__main__":
default_directory = Path(__file__).joinpath("..", "..", "qiskit").resolve()
parser = argparse.ArgumentParser(
Comment thread
Eric-Arellano marked this conversation as resolved.
prog="find_deprecated",
description="Finds the deprecation decorators in a path",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument("-d", "--directory", default=default_directory, help="directory to search")
parser.add_argument(
"-p",
"--pending",
choices=["only", "include", "exclude"],
default="exclude",
help="show pending deprecations",
)
args = parser.parse_args()
print_main(args.directory, args.pending)