43
43
44
44
45
45
class PackageInfoError (ValueError ):
46
- def __init__ (self , path ): # type: (Union[Path, str]) -> None
46
+ def __init__ (
47
+ self , path , * reasons
48
+ ): # type: (Union[Path, str], *Union[BaseException, str]) -> None
49
+ reasons = (
50
+ "Unable to determine package info for path: {}" .format (str (path )),
51
+ ) + reasons
47
52
super (PackageInfoError , self ).__init__ (
48
- "Unable to determine package info for path: {}" . format (str (path ) )
53
+ "\n \n " . join (str (msg ). strip () for msg in reasons if msg )
49
54
)
50
55
51
56
@@ -290,12 +295,14 @@ def from_setup_files(cls, path): # type: (Path) -> PackageInfo
290
295
:param path: Path to `setup.py` file
291
296
"""
292
297
if not cls .has_setup_files (path ):
293
- raise PackageInfoError (path )
298
+ raise PackageInfoError (
299
+ path , "No setup files (setup.py, setup.cfg) was found."
300
+ )
294
301
295
302
try :
296
303
result = SetupReader .read_from_directory (path )
297
- except Exception :
298
- raise PackageInfoError (path )
304
+ except Exception as e :
305
+ raise PackageInfoError (path , e )
299
306
300
307
python_requires = result ["python_requires" ]
301
308
if python_requires is None :
@@ -328,7 +335,10 @@ def from_setup_files(cls, path): # type: (Path) -> PackageInfo
328
335
329
336
if not (info .name and info .version ) and not info .requires_dist :
330
337
# there is nothing useful here
331
- raise PackageInfoError (path )
338
+ raise PackageInfoError (
339
+ path ,
340
+ "No core metadata (name, version, requires-dist) could be retrieved." ,
341
+ )
332
342
333
343
return info
334
344
@@ -463,15 +473,21 @@ def _pep517_metadata(cls, path): # type (Path) -> PackageInfo
463
473
cls ._log ("PEP517 build failed: {}" .format (e ), level = "debug" )
464
474
setup_py = path / "setup.py"
465
475
if not setup_py .exists ():
466
- raise PackageInfoError (path )
476
+ raise PackageInfoError (
477
+ path ,
478
+ e ,
479
+ "No fallback setup.py file was found to generate egg_info." ,
480
+ )
467
481
468
482
cwd = Path .cwd ()
469
483
os .chdir (path .as_posix ())
470
484
try :
471
485
venv .run ("python" , "setup.py" , "egg_info" )
472
486
return cls .from_metadata (path )
473
- except EnvCommandError :
474
- raise PackageInfoError (path )
487
+ except EnvCommandError as fbe :
488
+ raise PackageInfoError (
489
+ path , "Fallback egg_info generation failed." , fbe
490
+ )
475
491
finally :
476
492
os .chdir (cwd .as_posix ())
477
493
@@ -482,7 +498,7 @@ def _pep517_metadata(cls, path): # type (Path) -> PackageInfo
482
498
return info
483
499
484
500
# if we reach here, everything has failed and all hope is lost
485
- raise PackageInfoError (path )
501
+ raise PackageInfoError (path , "Exhausted all core metadata sources." )
486
502
487
503
@classmethod
488
504
def from_directory (
@@ -561,8 +577,8 @@ def from_bdist(cls, path): # type: (Path) -> PackageInfo
561
577
562
578
try :
563
579
return cls ._from_distribution (pkginfo .BDist (str (path )))
564
- except ValueError :
565
- raise PackageInfoError (path )
580
+ except ValueError as e :
581
+ raise PackageInfoError (path , e )
566
582
567
583
@classmethod
568
584
def from_path (cls , path ): # type: (Path) -> PackageInfo
0 commit comments