File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed
Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -386,13 +386,41 @@ def _whl_library_impl(rctx):
386386 "pypi_name=" + metadata ["name" ],
387387 "pypi_version=" + metadata ["version" ],
388388 ],
389- entry_points = {} ,
389+ entry_points = entry_points ,
390390 annotation = None if not rctx .attr .annotation else struct (** json .decode (rctx .read (rctx .attr .annotation ))),
391391 )
392392 rctx .file ("BUILD.bazel" , build_file_contents )
393393
394394 return
395395
396+ def _generate_entry_point_contents (
397+ module ,
398+ attribute ,
399+ shebang = "#!/usr/bin/env python3" ):
400+ """Generate the contents of an entry point script.
401+
402+ Args:
403+ module (str): The name of the module to use.
404+ attribute (str): The name of the attribute to call.
405+ shebang (str, optional): The shebang to use for the entry point python
406+ file.
407+
408+ Returns:
409+ str: A string of python code.
410+ """
411+ contents = """\
412+ {shebang}
413+ import sys
414+ from {module} import {attribute}
415+ if __name__ == "__main__":
416+ sys.exit({attribute}())
417+ """ .format (
418+ shebang = shebang ,
419+ module = module ,
420+ attribute = attribute ,
421+ )
422+ return contents
423+
396424# NOTE @aignas 2024-03-21: The usage of dict({}, **common) ensures that all args to `dict` are unique
397425whl_library_attrs = dict ({
398426 "annotation" : attr .label (
You can’t perform that action at this time.
0 commit comments