@@ -97,6 +97,10 @@ def extract_metainfo_files_from_package(
97
97
if not os .path .exists (output_folder ) or os .path .isfile (output_folder ):
98
98
raise ValueError ("output folder needs to be existing folder" )
99
99
100
+ if debug :
101
+ print ("extract_metainfo_files_from_package: extracting for " +
102
+ "package: " + str (package ))
103
+
100
104
# A temp folder for making a package copy in case it's a local folder,
101
105
# because extracting metadata might modify files
102
106
# (creating sdists/wheels...)
@@ -418,6 +422,7 @@ def _extract_metainfo_files_from_package_unsafe(
418
422
try :
419
423
build_requires = []
420
424
metadata_path = None
425
+
421
426
if path_type != "wheel" :
422
427
# We need to process this first to get the metadata.
423
428
@@ -447,7 +452,9 @@ def _extract_metainfo_files_from_package_unsafe(
447
452
metadata = None
448
453
with env :
449
454
hooks = Pep517HookCaller (path , backend )
450
- env .pip_install ([transform_dep_for_pip (req ) for req in build_requires ])
455
+ env .pip_install (
456
+ [transform_dep_for_pip (req ) for req in build_requires ]
457
+ )
451
458
reqs = hooks .get_requires_for_build_wheel ({})
452
459
env .pip_install ([transform_dep_for_pip (req ) for req in reqs ])
453
460
try :
@@ -466,6 +473,15 @@ def _extract_metainfo_files_from_package_unsafe(
466
473
"METADATA"
467
474
)
468
475
476
+ # Store type of metadata source. Can be "wheel", "source" for source
477
+ # distribution, and others get_package_as_folder() may support
478
+ # in the future.
479
+ with open (os .path .join (output_path , "metadata_source" ), "w" ) as f :
480
+ try :
481
+ f .write (path_type )
482
+ except TypeError : # in python 2 path_type may be str/bytes:
483
+ f .write (path_type .decode ("utf-8" , "replace" ))
484
+
469
485
# Copy the metadata file:
470
486
shutil .copyfile (metadata_path , os .path .join (output_path , "METADATA" ))
471
487
finally :
@@ -518,12 +534,23 @@ def _extract_info_from_package(dependency,
518
534
- name
519
535
- dependencies (a list of dependencies)
520
536
"""
537
+ if debug :
538
+ print ("_extract_info_from_package called with "
539
+ "extract_type={} include_build_requirements={}" .format (
540
+ extract_type , include_build_requirements ,
541
+ ))
521
542
output_folder = tempfile .mkdtemp (prefix = "pythonpackage-metafolder-" )
522
543
try :
523
544
extract_metainfo_files_from_package (
524
545
dependency , output_folder , debug = debug
525
546
)
526
547
548
+ # Extract the type of data source we used to get the metadata:
549
+ with open (os .path .join (output_folder ,
550
+ "metadata_source" ), "r" ) as f :
551
+ metadata_source_type = f .read ().strip ()
552
+
553
+ # Extract main METADATA file:
527
554
with open (os .path .join (output_folder , "METADATA" ),
528
555
"r" , encoding = "utf-8"
529
556
) as f :
@@ -539,14 +566,34 @@ def _extract_info_from_package(dependency,
539
566
raise ValueError ("failed to obtain package name" )
540
567
return name
541
568
elif extract_type == "dependencies" :
569
+ # First, make sure we don't attempt to return build requirements
570
+ # for wheels since they usually come without pyproject.toml
571
+ # and we haven't implemented another way to get them:
572
+ if include_build_requirements and \
573
+ metadata_source_type == "wheel" :
574
+ if debug :
575
+ print ("_extract_info_from_package: was called "
576
+ "with include_build_requirements=True on "
577
+ "package obtained as wheel, raising error..." )
578
+ raise NotImplementedError (
579
+ "fetching build requirements for "
580
+ "wheels is not implemented"
581
+ )
582
+
583
+ # Get build requirements from pyproject.toml if requested:
542
584
requirements = []
543
585
if os .path .exists (os .path .join (output_folder ,
544
586
'pyproject.toml' )
545
587
) and include_build_requirements :
588
+ # Read build system from pyproject.toml file: (PEP518)
546
589
with open (os .path .join (output_folder , 'pyproject.toml' )) as f :
547
590
build_sys = pytoml .load (f )['build-system' ]
548
591
if "requires" in build_sys :
549
592
requirements += build_sys ["requires" ]
593
+ elif include_build_requirements :
594
+ # For legacy packages with no pyproject.toml, we have to
595
+ # add setuptools as default build system.
596
+ requirements .append ("setuptools" )
550
597
551
598
# Add requirements from metadata:
552
599
requirements += [
0 commit comments