@@ -390,7 +390,11 @@ def assign_package_to_resources(cls, package, resource, codebase, package_adder)
390
390
Assign files to package for an installed wheel. This requires a bit
391
391
of navigation around as the files can be in multiple places.
392
392
"""
393
- site_packages = resource .parent (codebase ).parent (codebase )
393
+ dist_info_dir = resource .parent (codebase )
394
+ if not dist_info_dir :
395
+ return
396
+
397
+ site_packages = dist_info_dir .parent (codebase )
394
398
if not site_packages :
395
399
return
396
400
package_data = resource .package_data
@@ -400,9 +404,7 @@ def assign_package_to_resources(cls, package, resource, codebase, package_adder)
400
404
)
401
405
402
406
package_data = models .PackageData .from_dict (package_data [0 ])
403
-
404
407
package_uid = package .package_uid
405
-
406
408
if package_uid :
407
409
# save thyself!
408
410
package_adder (package_uid , resource , codebase )
@@ -414,76 +416,32 @@ def assign_package_to_resources(cls, package, resource, codebase, package_adder)
414
416
# relative paths need special treatment
415
417
# most of thense are references to bin ../../../bin/wheel
416
418
cannot_resolve = False
417
- ref_resource = None
419
+ ref_resource = site_packages
418
420
while path_ref .startswith ('..' ):
419
421
_ , _ , path_ref = path_ref .partition ('../' )
420
- ref_resource = site_packages .parent (codebase )
422
+ ref_resource = ref_resource .parent (codebase )
421
423
if not ref_resource :
422
424
cannot_resolve = True
423
425
break
426
+
424
427
if cannot_resolve or not ref_resource :
425
428
# TODO:w e should log these kind of things
426
429
continue
427
430
else :
428
- if package_uid :
431
+ ref_resource = codebase .get_resource (
432
+ path = os .path .join (ref_resource .path , path_ref )
433
+ )
434
+ if ref_resource and package_uid :
429
435
package_adder (package_uid , ref_resource , codebase )
430
436
else :
431
- ref_resource = get_resource_for_path (
432
- path = path_ref ,
433
- root = site_packages ,
434
- codebase = codebase ,
437
+ # These are absolute paths from the site-packages directory
438
+ ref_resource = codebase .get_resource (
439
+ path = os .path .join (site_packages .path , path_ref )
435
440
)
436
441
if ref_resource and package_uid :
437
442
package_adder (package_uid , ref_resource , codebase )
438
443
439
444
440
- def get_resource_for_path (path , root , codebase ):
441
- """
442
- Return a resource in ``codebase`` that has a ``path`` relative to the
443
- ``root` Resource
444
-
445
- For example, say we start from this:
446
- path: this/is/that therefore segments [this, is, that]
447
- root: /usr/foo
448
-
449
- We would have these iterations:
450
- iteration1
451
- root = /usr/foo
452
- segments = [this, is, that]
453
- seg this
454
- segments = [is, that]
455
- children = [/usr/foo/this]
456
- root = /usr/foo/this
457
-
458
- iteration2
459
- root = /usr/foo/this
460
- segments = [is, that]
461
- seg is
462
- segments = [that]
463
- children = [/usr/foo/this/is]
464
- root = /usr/foo/this/is
465
-
466
- iteration3
467
- root = /usr/foo/this/is
468
- segments = [that]
469
- seg that
470
- segments = []
471
- children = [/usr/foo/this/is/that]
472
- root = /usr/foo/this/is/that
473
-
474
- finally return root as /usr/foo/this/is/that
475
- """
476
- segments = path .strip ('/' ).split ('/' )
477
- while segments :
478
- seg = segments .pop (0 )
479
- children = [c for c in root .children (codebase ) if c .name == seg ]
480
- if len (children ) != 1 :
481
- return
482
- else :
483
- root = children [0 ]
484
- return root
485
-
486
-
487
445
class PyprojectTomlHandler (BaseExtractedPythonLayout ):
488
446
datasource_id = 'pypi_pyproject_toml'
489
447
path_patterns = ('*pyproject.toml' ,)
0 commit comments