diff --git a/Cargo.lock b/Cargo.lock index d5e90e41c..25ae8f30d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2066,9 +2066,9 @@ checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e" [[package]] name = "pklr" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7010962140d2369f8d1d287fa9b8862d4ca9d104621dcf614777efa33fccc545" +checksum = "46a2a30479b1648d912e1d85b939ccab3813b8fcdd4c3f805f3fb8f2efa95215" dependencies = [ "async-recursion", "indexmap 2.14.0", diff --git a/Cargo.toml b/Cargo.toml index 55b0350cd..8786dab6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ itertools = "0.14" libc = "0.2" log = "0.4" once_cell = "1" -pklr = "0.4.1" +pklr = "0.4.2" regex = "1" semver = "1" serde = { version = "1", features = ["derive"] } diff --git a/scripts/gen_builtins.py b/scripts/gen_builtins.py index cd7b39ddf..63b92b23e 100644 --- a/scripts/gen_builtins.py +++ b/scripts/gen_builtins.py @@ -40,15 +40,48 @@ class meta extends Annotation { """ +# Deprecated aliases. These point at a canonical builtin so loading +# Builtins.pkl never reads a deprecated property — under pklr's lazy +# @Deprecated handling (>= 0.4.2) the warning then fires only when a +# user references e.g. `Builtins.check_byte_order_marker`. +# (alias_name, canonical_name, since, message) +DEPRECATED_ALIASES = [ + ( + "check_byte_order_marker", + "byte_order_marker", + "1.30.0", + "Use `Builtins.byte_order_marker`", + ), + ( + "fix_byte_order_marker", + "byte_order_marker", + "1.30.0", + "Use `Builtins.byte_order_marker`", + ), +] + + def main(): + skip = {alias for alias, _, _, _ in DEPRECATED_ALIASES} + # Generate pkl/Builtins.pkl with open("pkl/Builtins.pkl", "w", newline="\n") as f: f.write(HEADER) for filepath in sorted(glob.glob("pkl/builtins/*.pkl")): filename = os.path.splitext(os.path.basename(filepath))[0] identifier = filename.replace("-", "_") + if identifier in skip: + continue f.write(f'{identifier} = Builtins["builtins/{filename}.pkl"].{identifier}\n') + for alias, canonical, since, message in DEPRECATED_ALIASES: + f.write("\n") + f.write("@Deprecated {\n") + f.write(f' since = "{since}"\n') + f.write(f' message = "{message}"\n') + f.write("}\n") + f.write(f'{alias} = Builtins["builtins/{canonical}.pkl"].{canonical}\n') + # pkl format (exits 11 after formatting, ignore that) subprocess.run(["pkl", "format", "--write", "pkl/Builtins.pkl"]) diff --git a/src/cli/migrate/pre_commit.rs b/src/cli/migrate/pre_commit.rs index d75516bbf..7c104d852 100644 --- a/src/cli/migrate/pre_commit.rs +++ b/src/cli/migrate/pre_commit.rs @@ -1165,13 +1165,13 @@ impl PreCommit { "check_executables_have_shebangs", ); map.insert("check-symlinks", "check_symlinks"); - map.insert("check-byte-order-marker", "check_byte_order_marker"); + map.insert("check-byte-order-marker", "byte_order_marker"); map.insert("check-added-large-files", "check_added_large_files"); map.insert("check-ast", "python_check_ast"); map.insert("debug-statements", "python_debug_statements"); map.insert("detect-private-key", "detect_private_key"); map.insert("no-commit-to-branch", "no_commit_to_branch"); - map.insert("fix-byte-order-marker", "fix_byte_order_marker"); + map.insert("fix-byte-order-marker", "byte_order_marker"); map }