3
3
import shutil
4
4
import sys
5
5
import tempfile
6
+ import warnings
6
7
7
8
from collections import defaultdict
8
9
from contextlib import contextmanager
@@ -285,12 +286,43 @@ def convert_entry_points(self) -> Dict[str, List[str]]:
285
286
286
287
# Scripts -> Entry points
287
288
for name , ep in self ._poetry .local_config .get ("scripts" , {}).items ():
288
- extras = ""
289
- if isinstance (ep , dict ):
289
+ extras : str = ""
290
+ module_path : str = ""
291
+
292
+ # Currently we support 2 legacy and 1 new format:
293
+ # (legacy) my_script = 'my_package.main:entry'
294
+ # (legacy) my_script = { callable = 'my_package.main:entry' }
295
+ # (supported) my_script = { reference = 'my_package.main:entry', type = "console" }
296
+
297
+ if isinstance (ep , str ):
298
+ warnings .warn (
299
+ "This way of declaring console scripts is deprecated and will be removed in a future version. "
300
+ 'Use reference = "{}", type = "console" instead.' .format (ep ),
301
+ DeprecationWarning ,
302
+ )
303
+ extras = ""
304
+ module_path = ep
305
+ elif isinstance (ep , dict ) and (
306
+ ep .get ("type" ) == "console"
307
+ or "callable" in ep # Supporting both new and legacy format for now
308
+ ):
309
+ if "callable" in ep :
310
+ warnings .warn (
311
+ "Using the keyword callable is deprecated and will be removed in a future version. "
312
+ 'Use reference = "{}", type = "console" instead.' .format (
313
+ ep ["callable" ]
314
+ ),
315
+ DeprecationWarning ,
316
+ )
317
+
290
318
extras = "[{}]" .format (", " .join (ep ["extras" ]))
291
- ep = ep ["callable" ]
319
+ module_path = ep .get ("reference" , ep .get ("callable" ))
320
+ else :
321
+ continue
292
322
293
- result ["console_scripts" ].append ("{} = {}{}" .format (name , ep , extras ))
323
+ result ["console_scripts" ].append (
324
+ "{} = {}{}" .format (name , module_path , extras )
325
+ )
294
326
295
327
# Plugins -> entry points
296
328
plugins = self ._poetry .local_config .get ("plugins" , {})
@@ -303,6 +335,29 @@ def convert_entry_points(self) -> Dict[str, List[str]]:
303
335
304
336
return dict (result )
305
337
338
+ def convert_script_files (self ) -> List [Path ]:
339
+ script_files : List [Path ] = []
340
+
341
+ for _ , ep in self ._poetry .local_config .get ("scripts" , {}).items ():
342
+ if isinstance (ep , dict ) and ep .get ("type" ) == "file" :
343
+ source = ep ["reference" ]
344
+
345
+ if Path (source ).is_absolute ():
346
+ raise RuntimeError (
347
+ "{} is an absolute path. Expected relative path." .format (source )
348
+ )
349
+
350
+ abs_path = Path .joinpath (self ._path , source )
351
+
352
+ if not abs_path .exists ():
353
+ raise RuntimeError ("{} file-script is not found." .format (abs_path ))
354
+ if not abs_path .is_file ():
355
+ raise RuntimeError ("{} file-script is not a file." .format (abs_path ))
356
+
357
+ script_files .append (abs_path )
358
+
359
+ return script_files
360
+
306
361
@classmethod
307
362
def convert_author (cls , author : str ) -> Dict [str , str ]:
308
363
m = AUTHOR_REGEX .match (author )
0 commit comments