@@ -390,7 +390,11 @@ def assign_package_to_resources(cls, package, resource, codebase, package_adder)
390390 Assign files to package for an installed wheel. This requires a bit
391391 of navigation around as the files can be in multiple places.
392392 """
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 )
394398 if not site_packages :
395399 return
396400 package_data = resource .package_data
@@ -400,9 +404,7 @@ def assign_package_to_resources(cls, package, resource, codebase, package_adder)
400404 )
401405
402406 package_data = models .PackageData .from_dict (package_data [0 ])
403-
404407 package_uid = package .package_uid
405-
406408 if package_uid :
407409 # save thyself!
408410 package_adder (package_uid , resource , codebase )
@@ -414,76 +416,32 @@ def assign_package_to_resources(cls, package, resource, codebase, package_adder)
414416 # relative paths need special treatment
415417 # most of thense are references to bin ../../../bin/wheel
416418 cannot_resolve = False
417- ref_resource = None
419+ ref_resource = site_packages
418420 while path_ref .startswith ('..' ):
419421 _ , _ , path_ref = path_ref .partition ('../' )
420- ref_resource = site_packages .parent (codebase )
422+ ref_resource = ref_resource .parent (codebase )
421423 if not ref_resource :
422424 cannot_resolve = True
423425 break
426+
424427 if cannot_resolve or not ref_resource :
425428 # TODO:w e should log these kind of things
426429 continue
427430 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 :
429435 package_adder (package_uid , ref_resource , codebase )
430436 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 )
435440 )
436441 if ref_resource and package_uid :
437442 package_adder (package_uid , ref_resource , codebase )
438443
439444
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-
487445class PyprojectTomlHandler (BaseExtractedPythonLayout ):
488446 datasource_id = 'pypi_pyproject_toml'
489447 path_patterns = ('*pyproject.toml' ,)
0 commit comments