Skip to content

Commit a2be313

Browse files
committed
precommit
1 parent fc9cdeb commit a2be313

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

python/bin/BUILD.bazel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
load("//python:py_binary.bzl", "py_binary")
12
load("//python/private:interpreter.bzl", _interpreter_binary = "interpreter_binary")
23
load("//python/private:repl.bzl", "generate_repl_main")
3-
load("//python:py_binary.bzl", "py_binary")
44

55
filegroup(
66
name = "distribution",
@@ -27,8 +27,8 @@ label_flag(
2727

2828
generate_repl_main(
2929
name = "repl_py",
30-
out = "repl.py",
3130
src = "repl_stub.py",
31+
out = "repl.py",
3232
)
3333

3434
label_flag(
@@ -47,11 +47,11 @@ label_flag(
4747
py_binary(
4848
name = "repl",
4949
srcs = [":repl.py"],
50+
visibility = ["//visibility:public"],
5051
deps = [
51-
":repl_stub_dep",
5252
":repl_dep",
53+
":repl_stub_dep",
5354
],
54-
visibility = ["//visibility:public"],
5555
)
5656

5757
# The user can modify this flag to make arbitrary PyInfo targets available for

python/bin/repl_stub.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import code
2+
23
code.interact(local=dict(globals(), **locals()))

python/private/repl.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ generate_repl_main = rule(
2626
mandatory = True,
2727
allow_single_file = True,
2828
),
29-
"_template": attr.label(
30-
default = "//python/private:repl_template.py",
31-
allow_single_file = True,
32-
),
3329
"_generator": attr.label(
3430
default = "//python/private:repl_main_generator",
3531
executable = True,
3632
cfg = "exec",
3733
),
34+
"_template": attr.label(
35+
default = "//python/private:repl_template.py",
36+
allow_single_file = True,
37+
),
3838
},
3939
)

python/private/repl_main_generator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from pathlib import Path
44

55
LINE_TO_REPLACE = """\
6-
pass # %REPLACE_WHOLE_LINE_WITH_STUB%
6+
pass # %REPLACE_WHOLE_LINE_WITH_STUB%
77
"""
88

9+
910
def main(argv):
1011
template = Path(sys.argv[1])
1112
stub = Path(sys.argv[2])
@@ -18,7 +19,9 @@ def main(argv):
1819

1920
output_text = template_text.replace(LINE_TO_REPLACE, indented_stub_text)
2021
if template_text == output_text:
21-
raise ValueError("Failed to find the following in the template: {LINE_TO_REPLACE}")
22+
raise ValueError(
23+
f"Failed to find the following in the template: {LINE_TO_REPLACE}"
24+
)
2225

2326
output.write_text(output_text)
2427

python/private/repl_template.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import os
22
from pathlib import Path
33

4+
45
def repl_stub():
5-
pass # %REPLACE_WHOLE_LINE_WITH_STUB%
6+
pass # %REPLACE_WHOLE_LINE_WITH_STUB%
7+
68

79
def start_repl():
810
# Simulate Python's behavior when a valid startup script is defined by the
911
# PYTHONSTARTUP variable. If this file path fails to load, print the error
1012
# and revert to the default behavior.
11-
if (startup_file := os.getenv("PYTHONSTARTUP")):
13+
if startup_file := os.getenv("PYTHONSTARTUP"):
1214
try:
1315
source_code = Path(startup_file).read_text()
1416
except Exception as error:
@@ -19,5 +21,6 @@ def start_repl():
1921

2022
repl_stub()
2123

24+
2225
if __name__ == "__main__":
2326
start_repl()

0 commit comments

Comments
 (0)