File tree Expand file tree Collapse file tree 5 files changed +19
-12
lines changed Expand file tree Collapse file tree 5 files changed +19
-12
lines changed Original file line number Diff line number Diff line change 1+ load ("//python:py_binary.bzl" , "py_binary" )
12load ("//python/private:interpreter.bzl" , _interpreter_binary = "interpreter_binary" )
23load ("//python/private:repl.bzl" , "generate_repl_main" )
3- load ("//python:py_binary.bzl" , "py_binary" )
44
55filegroup (
66 name = "distribution" ,
@@ -27,8 +27,8 @@ label_flag(
2727
2828generate_repl_main (
2929 name = "repl_py" ,
30- out = "repl.py" ,
3130 src = "repl_stub.py" ,
31+ out = "repl.py" ,
3232)
3333
3434label_flag (
@@ -47,11 +47,11 @@ label_flag(
4747py_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
Original file line number Diff line number Diff line change 11import code
2+
23code .interact (local = dict (globals (), ** locals ()))
Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff line change 33from pathlib import Path
44
55LINE_TO_REPLACE = """\
6- pass # %REPLACE_WHOLE_LINE_WITH_STUB%
6+ pass # %REPLACE_WHOLE_LINE_WITH_STUB%
77"""
88
9+
910def 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
Original file line number Diff line number Diff line change 11import os
22from pathlib import Path
33
4+
45def repl_stub ():
5- pass # %REPLACE_WHOLE_LINE_WITH_STUB%
6+ pass # %REPLACE_WHOLE_LINE_WITH_STUB%
7+
68
79def 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+
2225if __name__ == "__main__" :
2326 start_repl ()
You can’t perform that action at this time.
0 commit comments