@@ -92,6 +92,7 @@ def add_string(self, filename, contents):
92
92
93
93
def add_file (self , package_filename , real_filename ):
94
94
"""Add given file to the distribution."""
95
+
95
96
def arcname_from (name ):
96
97
# Always use unix path separators.
97
98
normalized_arcname = name .replace (os .path .sep , '/' )
@@ -157,12 +158,26 @@ def add_metadata(self, extra_headers, description, classifiers, requires,
157
158
metadata += "\n "
158
159
self .add_string (self .distinfo_path ('METADATA' ), metadata )
159
160
160
- def add_entry_points (self , console_scripts ):
161
+ def add_entry_points (self , console_scripts , plugins ):
161
162
"""Write entry_points.txt file to the distribution."""
162
163
# https://packaging.python.org/specifications/entry-points/
163
- if not console_scripts :
164
+ import re
165
+ pattern = re .compile (r'([^=:]+):([^:=]+)=([^=]+)' )
166
+ lines = []
167
+ if console_scripts :
168
+ lines += ["[console_scripts]" ] + console_scripts
169
+ if plugins :
170
+ for line in plugins :
171
+ match = pattern .fullmatch (line )
172
+ if not match :
173
+ raise ValueError ('{line} is not a valid entry point' .format (line = line ))
174
+ plugin_type = match .group (1 ).strip ()
175
+ plugin_name = match .group (2 ).strip ()
176
+ plugin_value = match .group (3 ).strip ()
177
+ lines += ['[{plugin_type}]' .format (plugin_type = plugin_type ),
178
+ '{plugin_name} = {plugin_value}' .format (plugin_name = plugin_name , plugin_value = plugin_value )]
179
+ if not lines :
164
180
return
165
- lines = ["[console_scripts]" ] + console_scripts
166
181
contents = '\n ' .join (lines )
167
182
self .add_string (self .distinfo_path ('entry_points.txt' ), contents )
168
183
@@ -246,6 +261,10 @@ def main():
246
261
'--console_script' , action = 'append' ,
247
262
help = "Defines a 'console_script' entry point. "
248
263
"Can be supplied multiple times." )
264
+ contents_group .add_argument (
265
+ '--plugin' , action = 'append' ,
266
+ help = "Defines a 'plugin' entry_point in the format 'a:b=c'. "
267
+ "Can be supplied multiple times." )
249
268
250
269
requirements_group = parser .add_argument_group ("Package requirements" )
251
270
requirements_group .add_argument (
@@ -303,13 +322,14 @@ def main():
303
322
requires = arguments .requires or []
304
323
extra_headers = arguments .header or []
305
324
console_scripts = arguments .console_script or []
325
+ plugins = arguments .plugin or []
306
326
307
327
maker .add_metadata (extra_headers = extra_headers ,
308
328
description = description ,
309
329
classifiers = classifiers ,
310
330
requires = requires ,
311
331
extra_requires = extra_requires )
312
- maker .add_entry_points (console_scripts = console_scripts )
332
+ maker .add_entry_points (console_scripts = console_scripts , plugins = plugins )
313
333
maker .add_recordfile ()
314
334
315
335
0 commit comments