Skip to content

Commit 56abb01

Browse files
authored
refactor(precompiler): give optimize/invalidation_mode flags default values (bazel-contrib#2180)
This allows one to actually run this script with *just* these flags: src, src_name, pyc Extra: refactor how the enum member is parsed
1 parent 79df3c9 commit 56abb01

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tools/precompiler/precompiler.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
def _create_parser() -> "argparse.Namespace":
2626
parser = argparse.ArgumentParser(fromfile_prefix_chars="@")
27-
parser.add_argument("--invalidation_mode")
28-
parser.add_argument("--optimize", type=int)
27+
parser.add_argument("--invalidation_mode", default="CHECKED_HASH")
28+
parser.add_argument("--optimize", type=int, default=-1)
2929
parser.add_argument("--python_version")
3030

3131
parser.add_argument("--src", action="append", dest="srcs")
@@ -40,10 +40,10 @@ def _create_parser() -> "argparse.Namespace":
4040

4141
def _compile(options: "argparse.Namespace") -> None:
4242
try:
43-
invalidation_mode = getattr(
44-
py_compile.PycInvalidationMode, options.invalidation_mode.upper()
45-
)
46-
except AttributeError as e:
43+
invalidation_mode = py_compile.PycInvalidationMode[
44+
options.invalidation_mode.upper()
45+
]
46+
except KeyError as e:
4747
raise ValueError(
4848
f"Unknown PycInvalidationMode: {options.invalidation_mode}"
4949
) from e

0 commit comments

Comments
 (0)