maintainers/scripts/remove-old-aliases.py: convert aliases to warnings before throwing or removing; aliases: cleanup (#427017)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#!nix-shell -i python3 -p "python3.withPackages(ps: with ps; [ ])" nix
|
||||
"""
|
||||
A program to remove old aliases or convert old aliases to throws
|
||||
Converts old aliases to warnings, converts old warnings to throws, and removes old throws.
|
||||
Example usage:
|
||||
./maintainers/scripts/remove-old-aliases.py --year 2018 --file ./pkgs/top-level/aliases.nix
|
||||
|
||||
@@ -31,22 +31,42 @@ def process_args() -> argparse.Namespace:
|
||||
arg_parser.add_argument(
|
||||
"--only-throws",
|
||||
action="store_true",
|
||||
help="only operate on throws. e.g remove throws older than $date",
|
||||
help="Deprecated, use --only throws instead",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"--only",
|
||||
choices=["aliases", "warnings", "throws"],
|
||||
help="Only act on the specified types"
|
||||
"(i.e. only act on entries that are 'normal' aliases, warnings, or throws)."
|
||||
"Can be repeated.",
|
||||
action="append",
|
||||
dest="operate_on",
|
||||
)
|
||||
arg_parser.add_argument("--file", required=True, type=Path, help="alias file")
|
||||
arg_parser.add_argument(
|
||||
"--dry-run", action="store_true", help="don't modify files, only print results"
|
||||
)
|
||||
return arg_parser.parse_args()
|
||||
|
||||
parsed = arg_parser.parse_args()
|
||||
|
||||
if parsed.only_throws:
|
||||
parsed.operate_on.append("throws")
|
||||
|
||||
if parsed.operate_on is None:
|
||||
parsed.operate_on = ["aliases", "warnings", "throws"]
|
||||
|
||||
return parsed
|
||||
|
||||
|
||||
def get_date_lists(
|
||||
txt: list[str], cutoffdate: datetimedate, only_throws: bool
|
||||
) -> tuple[list[str], list[str], list[str]]:
|
||||
txt: list[str], cutoffdate: datetimedate
|
||||
) -> tuple[list[str], list[str], list[str], list[str], list[str]]:
|
||||
"""get a list of lines in which the date is older than $cutoffdate"""
|
||||
date_older_list: list[str] = []
|
||||
date_older_throw_list: list[str] = []
|
||||
date_older_warning_list: list[str] = []
|
||||
date_sep_line_list: list[str] = []
|
||||
date_too_complex_list: list[str] = []
|
||||
|
||||
for lineno, line in enumerate(txt, start=1):
|
||||
line = line.rstrip()
|
||||
@@ -69,68 +89,104 @@ def get_date_lists(
|
||||
):
|
||||
continue
|
||||
|
||||
if "=" not in line:
|
||||
date_sep_line_list.append(f"{lineno} {line}")
|
||||
if line.lstrip().startswith("inherit (") and ";" in line:
|
||||
date_older_list.append(line)
|
||||
elif "=" not in line:
|
||||
date_sep_line_list.append(f"{lineno:>5} {line}")
|
||||
# 'if' lines could be complicated
|
||||
elif "if " in line and "if =" not in line:
|
||||
print(f"RESOLVE MANUALLY {line}")
|
||||
elif "throw" in line:
|
||||
date_too_complex_list.append(f"{lineno:>5} {line}")
|
||||
elif "= with " in line:
|
||||
date_too_complex_list.append(f"{lineno:>5} {line}")
|
||||
elif "lib.warnOnInstantiate" in line or "warning" in line:
|
||||
if 'lib.warnOnInstantiate "' in line:
|
||||
date_older_warning_list.append(line)
|
||||
else:
|
||||
date_too_complex_list.append(f"{lineno:>5} {line}")
|
||||
elif " = throw" in line:
|
||||
date_older_throw_list.append(line)
|
||||
elif not only_throws:
|
||||
else:
|
||||
date_older_list.append(line)
|
||||
|
||||
return (
|
||||
date_older_list,
|
||||
date_sep_line_list,
|
||||
date_too_complex_list,
|
||||
date_older_throw_list,
|
||||
date_older_warning_list,
|
||||
)
|
||||
|
||||
|
||||
def convert_to_throw(date_older_list: list[str]) -> list[tuple[str, str]]:
|
||||
"""convert a list of lines to throws"""
|
||||
converted_list = []
|
||||
for line in date_older_list.copy():
|
||||
def convert(lines: list[str], convert_to: str) -> list[tuple[str, str]]:
|
||||
"""convert a list of lines to either "throws" or "warnings"."""
|
||||
converted_lines = {}
|
||||
for line in lines.copy():
|
||||
indent: str = " " * (len(line) - len(line.lstrip()))
|
||||
before_equal = ""
|
||||
after_equal = ""
|
||||
try:
|
||||
before_equal, after_equal = (x.strip() for x in line.split("=", maxsplit=2))
|
||||
except ValueError as err:
|
||||
print(err, line, "\n")
|
||||
date_older_list.remove(line)
|
||||
continue
|
||||
|
||||
alias = before_equal
|
||||
alias_unquoted = before_equal.strip('"')
|
||||
replacement = next(x.strip(";:") for x in after_equal.split())
|
||||
if "=" not in line:
|
||||
assert "inherit (" in line
|
||||
before, sep, after = line.partition("inherit (")
|
||||
inside, sep, after = after.partition(")")
|
||||
if not sep:
|
||||
print(f"FAILED ON {line}")
|
||||
continue
|
||||
alias, *_ = after.strip().split(";")[0].split()
|
||||
replacement = f"{inside.strip()}.{alias}"
|
||||
|
||||
else:
|
||||
before_equal = ""
|
||||
after_equal = ""
|
||||
try:
|
||||
before_equal, after_equal = (
|
||||
x.strip() for x in line.split("=", maxsplit=2)
|
||||
)
|
||||
if after_equal.startswith("lib.warnOnInstantiate"):
|
||||
after_equal = after_equal.split("\"", maxsplit=3)[2].strip()
|
||||
except ValueError as err:
|
||||
print(err, line, "\n")
|
||||
lines.remove(line)
|
||||
continue
|
||||
|
||||
alias = before_equal
|
||||
replacement = next(x.strip(";:") for x in after_equal.split())
|
||||
|
||||
alias_unquoted = alias.strip('"')
|
||||
replacement = replacement.removeprefix("pkgs.")
|
||||
|
||||
converted = (
|
||||
f"{indent}{alias} = throw \"'{alias_unquoted}' has been"
|
||||
f" renamed to/replaced by '{replacement}'\";"
|
||||
f" # Converted to throw {datetime.today().strftime('%Y-%m-%d')}"
|
||||
)
|
||||
converted_list.append((line, converted))
|
||||
if convert_to == "throws":
|
||||
converted = (
|
||||
f"{indent}{alias} = throw \"'{alias_unquoted}' has been"
|
||||
f" renamed to/replaced by '{replacement}'\";"
|
||||
f" # Converted to throw {datetime.today().strftime('%Y-%m-%d')}"
|
||||
)
|
||||
converted_lines[line] = converted
|
||||
elif convert_to == "warnings":
|
||||
converted = (
|
||||
f"{indent}{alias} = lib.warnOnInstantiate \"'{alias_unquoted}' has been"
|
||||
f" renamed to/replaced by '{replacement}'\" {replacement};"
|
||||
f" # Converted to warning {datetime.today().strftime('%Y-%m-%d')}"
|
||||
)
|
||||
converted_lines[line] = converted
|
||||
else:
|
||||
raise ValueError("'convert_to' must be either 'throws' or 'warnings'")
|
||||
|
||||
return converted_list
|
||||
return converted_lines
|
||||
|
||||
|
||||
def generate_text_to_write(
|
||||
txt: list[str],
|
||||
date_older_list: list[str],
|
||||
converted_to_throw: list[tuple[str, str]],
|
||||
date_older_throw_list: list[str],
|
||||
converted_lines: dict[str, str],
|
||||
) -> list[str]:
|
||||
"""generate a list of text to be written to the aliasfile"""
|
||||
text_to_write: list[str] = []
|
||||
for line in txt:
|
||||
text_to_append: str = ""
|
||||
if converted_to_throw:
|
||||
for tupl in converted_to_throw:
|
||||
if line == tupl[0]:
|
||||
text_to_append = f"{tupl[1]}\n"
|
||||
if line not in date_older_list and line not in date_older_throw_list:
|
||||
text_to_append = f"{line}\n"
|
||||
try:
|
||||
new_line = converted_lines[line]
|
||||
if new_line is not None:
|
||||
text_to_write.append(f"{new_line}\n")
|
||||
except KeyError:
|
||||
text_to_write.append(f"{line}\n")
|
||||
if text_to_append:
|
||||
text_to_write.append(text_to_append)
|
||||
|
||||
@@ -171,30 +227,48 @@ def main() -> None:
|
||||
"""main"""
|
||||
args = process_args()
|
||||
|
||||
only_throws = args.only_throws
|
||||
aliasfile = Path(args.file).absolute()
|
||||
cutoffdate = (datetime.strptime(f"{args.year}-{args.month}-01", "%Y-%m-%d")).date()
|
||||
|
||||
txt: list[str] = (aliasfile.read_text(encoding="utf-8")).splitlines()
|
||||
|
||||
date_older_list: list[str] = []
|
||||
date_sep_line_list: list[str] = []
|
||||
date_older_warning_list: list[str] = []
|
||||
date_older_throw_list: list[str] = []
|
||||
date_sep_line_list: list[str] = []
|
||||
date_too_complex_list: list[str] = []
|
||||
|
||||
date_older_list, date_sep_line_list, date_older_throw_list = get_date_lists(
|
||||
txt, cutoffdate, only_throws
|
||||
)
|
||||
(
|
||||
date_older_list,
|
||||
date_sep_line_list,
|
||||
date_too_complex_list,
|
||||
date_older_throw_list,
|
||||
date_older_warning_list,
|
||||
) = get_date_lists(txt, cutoffdate)
|
||||
|
||||
converted_to_throw: list[tuple[str, str]] = []
|
||||
if date_older_list:
|
||||
converted_to_throw = convert_to_throw(date_older_list)
|
||||
print(" Will be converted to throws. ".center(100, "-"))
|
||||
converted_lines: dict[str, str] = {}
|
||||
|
||||
if date_older_list and "aliases" in args.operate_on:
|
||||
converted_lines.update(convert(date_older_list, "warnings"))
|
||||
print(" Will be converted to warnings. ".center(100, "-"))
|
||||
for l_n in date_older_list:
|
||||
print(l_n)
|
||||
|
||||
if date_older_throw_list:
|
||||
if date_older_warning_list and "warnings" in args.operate_on:
|
||||
converted_lines.update(convert(date_older_warning_list, "throws"))
|
||||
print(" Will be converted to throws. ".center(100, "-"))
|
||||
for l_n in date_older_warning_list:
|
||||
print(l_n)
|
||||
|
||||
if date_older_throw_list and "throws" in args.operate_on:
|
||||
print(" Will be removed. ".center(100, "-"))
|
||||
for l_n in date_older_throw_list:
|
||||
converted_lines[l_n] = None
|
||||
print(l_n)
|
||||
|
||||
if date_too_complex_list:
|
||||
print(" Too complex, resolve manually. ".center(100, "-"))
|
||||
for l_n in date_too_complex_list:
|
||||
print(l_n)
|
||||
|
||||
if date_sep_line_list:
|
||||
@@ -203,9 +277,7 @@ def main() -> None:
|
||||
print(l_n)
|
||||
|
||||
if not args.dry_run:
|
||||
text_to_write = generate_text_to_write(
|
||||
txt, date_older_list, converted_to_throw, date_older_throw_list
|
||||
)
|
||||
text_to_write = generate_text_to_write(txt, converted_lines)
|
||||
write_file(aliasfile, text_to_write)
|
||||
|
||||
|
||||
|
||||
@@ -467,7 +467,7 @@ mapAliases {
|
||||
ansible-later = throw "ansible-later has been discontinued. The author recommends switching to ansible-lint"; # Added 2025-08-24
|
||||
ansible_2_14 = throw "Ansible 2.14 goes end of life in 2024/05 and can't be supported throughout the 24.05 release cycle"; # Added 2024-04-11
|
||||
ansible_2_15 = throw "Ansible 2.15 goes end of life in 2024/11 and can't be supported throughout the 24.11 release cycle"; # Added 2024-11-08
|
||||
antennas = throw "antennas has been removed as it only works with tvheadend, which nobody was willing to maintain and was stuck on an unmaintained version that required FFmpeg 4. Please see https://github.com/NixOS/nixpkgs/pull/332259 if you are interested in maintaining a newer version"; # Added 2024-08-21
|
||||
antennas = throw "antennas has been removed as it only works with tvheadend, which nobody was willing to maintain and was stuck on an unmaintained version that required FFmpeg 4. If you are interested in maintaining a newer version, please see https://github.com/NixOS/nixpkgs/pull/332259"; # Added 2024-08-21
|
||||
antic = throw "'antic' has been removed as it has been merged into 'flint3'"; # Added 2025-03-28
|
||||
antimicroX = throw "'antimicroX' has been renamed to/replaced by 'antimicrox'"; # Converted to throw 2024-10-17
|
||||
antlr4_8 = throw "antlr4_8 has been removed. Consider using a more recent version of antlr4"; # Added 2025-10-20
|
||||
@@ -1165,12 +1165,12 @@ mapAliases {
|
||||
grafana_reporter = grafana-reporter; # Added 2024-06-09
|
||||
grapefruit = throw "'grapefruit' was removed due to being blocked by Roblox, rendering the package useless"; # Added 2024-08-23
|
||||
graphite-kde-theme = throw "'graphite-kde-theme' has been removed, as it is only compatible with Plasma 5, which is EOL"; # Added 2025-08-20
|
||||
graylog-3_3 = throw "graylog 3.x is EOL. Please consider downgrading nixpkgs if you need an upgrade from 3.x to latest series."; # Added 2023-10-09
|
||||
graylog-4_0 = throw "graylog 4.x is EOL. Please consider downgrading nixpkgs if you need an upgrade from 4.x to latest series."; # Added 2023-10-09
|
||||
graylog-4_3 = throw "graylog 4.x is EOL. Please consider downgrading nixpkgs if you need an upgrade from 4.x to latest series."; # Added 2023-10-09
|
||||
graylog-5_0 = throw "graylog 5.0.x is EOL. Please consider downgrading nixpkgs if you need an upgrade from 5.0.x to latest series."; # Added 2024-02-15
|
||||
graylog-5_1 = throw "graylog 5.1.x is EOL. Please consider downgrading nixpkgs if you need an upgrade from 5.1.x to latest series."; # Added 2024-10-16
|
||||
graylog-5_2 = throw "graylog 5.2 is EOL. Please consider downgrading nixpkgs if you need an upgrade from 5.2 to latest series."; # Added 2025-03-21
|
||||
graylog-3_3 = throw "graylog 3.x is EOL. If you need an upgrade from 3.x to latest series, please consider downgrading nixpkgs."; # Added 2023-10-09
|
||||
graylog-4_0 = throw "graylog 4.x is EOL. If you need an upgrade from 4.x to latest series, please consider downgrading nixpkgs."; # Added 2023-10-09
|
||||
graylog-4_3 = throw "graylog 4.x is EOL. If you need an upgrade from 4.x to latest series, please consider downgrading nixpkgs."; # Added 2023-10-09
|
||||
graylog-5_0 = throw "graylog 5.0.x is EOL. If you need an upgrade from 5.0.x to latest series, please consider downgrading nixpkgs."; # Added 2024-02-15
|
||||
graylog-5_1 = throw "graylog 5.1.x is EOL. If you need an upgrade from 5.1.x to latest series, please consider downgrading nixpkgs."; # Added 2024-10-16
|
||||
graylog-5_2 = throw "graylog 5.2.x is EOL. If you need an upgrade from 5.2.x to latest series, please consider downgrading nixpkgs."; # Added 2025-03-21
|
||||
green-pdfviewer = throw "'green-pdfviewer' has been removed due to lack of maintenance upstream."; # Added 2024-12-04
|
||||
gringo = clingo; # added 2022-11-27
|
||||
grub2_full = grub2; # Added 2022-11-18
|
||||
@@ -1876,11 +1876,11 @@ mapAliases {
|
||||
nodejs-slim_18 = nodejs_18; # Added 2025-04-23
|
||||
nodejs_18 = throw "Node.js 18.x has reached End-Of-Life and has been removed"; # Added 2025-04-23
|
||||
nomacs-qt6 = nomacs; # Added 2025-08-30
|
||||
nomad_1_4 = throw "nomad_1_4 is no longer supported upstream. You can switch to using a newer version of the nomad package, or revert to older nixpkgs if you cannot upgrade"; # Added 2025-02-02
|
||||
nomad_1_5 = throw "nomad_1_5 is no longer supported upstream. You can switch to using a newer version of the nomad package, or revert to older nixpkgs if you cannot upgrade"; # Added 2025-02-02
|
||||
nomad_1_6 = throw "nomad_1_6 is no longer supported upstream. You can switch to using a newer version of the nomad package, or revert to older nixpkgs if you cannot upgrade"; # Added 2025-02-02
|
||||
nomad_1_7 = throw "nomad_1_7 is no longer supported upstream. You can switch to using a newer version of the nomad package, or revert to older nixpkgs if you cannot upgrade"; # Added 2025-03-27
|
||||
nomad_1_8 = throw "nomad_1_8 is no longer supported upstream. You can switch to using a newer version of the nomad package, or revert to older nixpkgs if you cannot upgrade"; # Added 2025-03-27
|
||||
nomad_1_4 = throw "nomad_1_4 is no longer supported upstream. You can switch to using a newer version of the nomad package. If you cannot upgrade, you can revert to older nixpkgs."; # Added 2025-02-02
|
||||
nomad_1_5 = throw "nomad_1_5 is no longer supported upstream. You can switch to using a newer version of the nomad package. If you cannot upgrade, you can revert to older nixpkgs."; # Added 2025-02-02
|
||||
nomad_1_6 = throw "nomad_1_6 is no longer supported upstream. You can switch to using a newer version of the nomad package. If you cannot upgrade, you can revert to older nixpkgs."; # Added 2025-02-02
|
||||
nomad_1_7 = throw "nomad_1_7 is no longer supported upstream. You can switch to using a newer version of the nomad package. If you cannot upgrade, you can revert to older nixpkgs."; # Added 2025-03-27
|
||||
nomad_1_8 = throw "nomad_1_8 is no longer supported upstream. You can switch to using a newer version of the nomad package. If you cannot upgrade, you can revert to older nixpkgs."; # Added 2025-03-27
|
||||
norouter = throw "norouter has been removed because it has been marked as broken since at least November 2024."; # Added 2025-09-29
|
||||
notes-up = throw "'notes-up' has been removed as it was unmaintained and depends on deprecated webkitgtk_4_0"; # Added 2025-10-09
|
||||
notify-sharp = throw "'notify-sharp' has been removed as it was unmaintained and depends on deprecated dbus-sharp versions"; # Added 2025-08-25
|
||||
@@ -1972,8 +1972,8 @@ mapAliases {
|
||||
OSCAR = oscar; # Added 2024-06-12
|
||||
osm2xmap = throw "osm2xmap has been removed, as it is unmaintained upstream and depended on old dependencies with broken builds"; # Added 2025-09-16
|
||||
osxfuse = throw "'osxfuse' has been renamed to/replaced by 'macfuse-stubs'"; # Converted to throw 2024-10-17
|
||||
overrideLibcxx = "overrideLibcxx has beeen removed, as it was no longer used and Darwin now uses libc++ from the latest SDK; see the Nixpkgs 25.11 release notes for details"; # Added 2025-09-15
|
||||
overrideSDK = "overrideSDK has been removed as it was a legacy compatibility stub. See <https://nixos.org/manual/nixpkgs/stable/#sec-darwin-legacy-frameworks-overrides> for migration instructions"; # Added 2025-08-04
|
||||
overrideLibcxx = throw "overrideLibcxx has been removed, as it was no longer used and Darwin now uses libc++ from the latest SDK; see the Nixpkgs 25.11 release notes for details"; # Added 2025-09-15
|
||||
overrideSDK = throw "overrideSDK has been removed as it was a legacy compatibility stub. See <https://nixos.org/manual/nixpkgs/stable/#sec-darwin-legacy-frameworks-overrides> for migration instructions"; # Added 2025-08-04
|
||||
ovn-lts = throw "ovn-lts has been removed. Please use the latest version available under ovn"; # Added 2024-08-24
|
||||
oxygen-icons5 = throw "
|
||||
The top-level oxygen-icons5 alias has been removed.
|
||||
@@ -2457,7 +2457,7 @@ mapAliases {
|
||||
symbiyosys = sby; # Added 2024-08-18
|
||||
syn2mas = throw "'syn2mas' has been removed. It has been integrated into the main matrix-authentication-service CLI as a subcommand: 'mas-cli syn2mas'."; # Added 2025-07-07
|
||||
sync = taler-sync; # Added 2024-09-04
|
||||
syncall = "'syncall' has been removed because it has been marked as broken since at least November 2024."; # Added 2025-10-01
|
||||
syncall = throw "'syncall' has been removed because it has been marked as broken since at least November 2024."; # Added 2025-10-01
|
||||
syncthing-cli = throw "'syncthing-cli' has been renamed to/replaced by 'syncthing'"; # Converted to throw 2024-10-17
|
||||
syncthing-tray = throw "syncthing-tray has been removed because it is broken and unmaintained"; # Added 2025-05-18
|
||||
syncthingtray-qt6 = syncthingtray; # Added 2024-03-06
|
||||
@@ -2582,7 +2582,7 @@ mapAliases {
|
||||
tumpa = throw "tumpa has been removed, as it is broken"; # Added 2024-07-15
|
||||
turbogit = throw "turbogit has been removed as it is unmaintained upstream and depends on an insecure version of libgit2"; # Added 2024-08-25
|
||||
tvbrowser-bin = tvbrowser; # Added 2023-03-02
|
||||
tvheadend = throw "tvheadend has been removed as it nobody was willing to maintain it and it was stuck on an unmaintained version that required FFmpeg 4. Please see https://github.com/NixOS/nixpkgs/pull/332259 if you are interested in maintaining a newer version"; # Added 2024-08-21
|
||||
tvheadend = throw "tvheadend has been removed as it nobody was willing to maintain it and it was stuck on an unmaintained version that required FFmpeg 4. If you are interested in maintaining a newer version, please see https://github.com/NixOS/nixpkgs/pull/332259."; # Added 2024-08-21
|
||||
typst-fmt = typstfmt; # Added 2023-07-15
|
||||
typst-lsp = throw "'typst-lsp' has been removed due to lack of upstream maintenance, consider using 'tinymist' instead"; # Added 2025-01-25
|
||||
typst-preview = throw "The features of 'typst-preview' have been consolidated to 'tinymist', an all-in-one language server for typst"; # Added 2024-07-07
|
||||
|
||||
Reference in New Issue
Block a user