@@ -99,11 +99,11 @@ def _py_wheel_impl(ctx):
9999 other_inputs = []
100100
101101 # Wrap the inputs into a file to reduce command line length.
102- packageinputfile = ctx .actions .declare_file (ctx .attr .name + ' _target_wrapped_inputs.txt' )
103- content = ''
102+ packageinputfile = ctx .actions .declare_file (ctx .attr .name + " _target_wrapped_inputs.txt" )
103+ content = ""
104104 for input_file in inputs_to_package .to_list ():
105- content += _input_file_to_arg (input_file ) + ' \n '
106- ctx .actions .write (output = packageinputfile , content = content )
105+ content += _input_file_to_arg (input_file ) + " \n "
106+ ctx .actions .write (output = packageinputfile , content = content )
107107 other_inputs .append (packageinputfile )
108108
109109 args = ctx .actions .args ()
@@ -140,8 +140,30 @@ def _py_wheel_impl(ctx):
140140 for r in requirements :
141141 args .add ("--extra_requires" , r + ";" + option )
142142
143- for name , ref in ctx .attr .console_scripts .items ():
144- args .add ("--console_script" , name + " = " + ref )
143+ # Merge console_scripts into entry_points.
144+ entrypoints = dict (ctx .attr .entry_points ) # Copy so we can mutate it
145+ if ctx .attr .console_scripts :
146+ # Copy a console_scripts group that may already exist, so we can mutate it.
147+ console_scripts = list (entrypoints .get ("console_scripts" , []))
148+ entrypoints ["console_scripts" ] = console_scripts
149+ for name , ref in ctx .attr .console_scripts .items ():
150+ console_scripts .append ("{name} = {ref}" .format (name = name , ref = ref ))
151+
152+ # If any entry_points are provided, construct the file here and add it to the files to be packaged.
153+ # see: https://packaging.python.org/specifications/entry-points/
154+ if entrypoints :
155+ lines = []
156+ for group , entries in sorted (entrypoints .items ()):
157+ if lines :
158+ # Blank line between groups
159+ lines .append ("" )
160+ lines .append ("[{group}]" .format (group = group ))
161+ lines += sorted (entries )
162+ entry_points_file = ctx .actions .declare_file (ctx .attr .name + "_entry_points.txt" )
163+ content = "\n " .join (lines )
164+ ctx .actions .write (output = entry_points_file , content = content )
165+ other_inputs .append (entry_points_file )
166+ args .add ("--entry_points_file" , entry_points_file )
145167
146168 if ctx .attr .description_file :
147169 description_file = ctx .file .description_file
@@ -208,7 +230,14 @@ _requirement_attrs = {
208230_entrypoint_attrs = {
209231 "console_scripts" : attr .string_dict (
210232 doc = """\
211- console_script entry points, e.g. 'experimental.examples.wheel.main:main'.
233+ Deprecated console_script entry points, e.g. {'main': 'experimental.examples.wheel.main:main'}.
234+
235+ Deprecated: prefer the `entry_points` attribute, which supports `console_scripts` as well as other entry points.
236+ """ ,
237+ ),
238+ "entry_points" : attr .string_list_dict (
239+ doc = """\
240+ entry_points, e.g. {'console_scripts': ['main = experimental.examples.wheel.main:main']}.
212241""" ,
213242 ),
214243}
@@ -281,7 +310,7 @@ Targets to be included in the distribution.
281310The targets to package are usually `py_library` rules or filesets (for packaging data files).
282311
283312Note it's usually better to package `py_library` targets and use
284- `console_scripts ` attribute to specify entry points than to package
313+ `entry_points ` attribute to specify `console_scripts` than to package
285314`py_binary` rules. `py_binary` targets would wrap a executable script that
286315tries to locate `.runfiles` directory which is not packaged in the wheel.
287316""" ,
0 commit comments