@@ -6,22 +6,22 @@ def _generate_repl_main_impl(ctx):
66 stub_repo = ctx .attr .stub .label .repo_name or ctx .workspace_name
77 stub_path = "/" .join ([stub_repo , ctx .file .stub .short_path ])
88
9+ out = ctx .actions .declare_file (ctx .label .name + ".py" )
10+
911 # Point the generated main file at the stub.
1012 ctx .actions .expand_template (
1113 template = ctx .file ._template ,
12- output = ctx . outputs . out ,
14+ output = out ,
1315 substitutions = {
1416 "%stub_path%" : stub_path ,
1517 },
1618 )
1719
20+ return [DefaultInfo (files = depset ([out ]))]
21+
1822_generate_repl_main = rule (
1923 implementation = _generate_repl_main_impl ,
2024 attrs = {
21- "out" : attr .output (
22- mandatory = True ,
23- doc = "The path to the file to generate." ,
24- ),
2525 "stub" : attr .label (
2626 mandatory = True ,
2727 allow_single_file = True ,
@@ -40,6 +40,8 @@ Generates a "main" script for a py_binary target that starts a Python REPL.
4040The template is designed to take care of the majority of the logic. The user
4141customizes the exact shell that will be started via the stub. The stub is a
4242simple shell script that imports the desired shell and then executes it.
43+
44+ The target's name is used for the output filename (with a .py extension).
4345""" ,
4446)
4547
@@ -64,14 +66,14 @@ def py_repl_binary(name, stub, deps = [], data = [], **kwargs):
6466 _generate_repl_main (
6567 name = "%s_py" % name ,
6668 stub = stub ,
67- out = "%s.py" % name ,
6869 )
6970
7071 _py_binary (
7172 name = name ,
7273 srcs = [
73- ":%s.py " % name ,
74+ ":%s_py " % name ,
7475 ],
76+ main = "%s_py.py" % name ,
7577 data = data + [
7678 stub ,
7779 ],
0 commit comments