Skip to content

Commit 2b83eaf

Browse files
Merge pull request #3115 from nexB/aboutfile-assemble
Yield package before assigning to resource
2 parents 3985e27 + 6f4cb09 commit 2b83eaf

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

src/packagedcode/about.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ def assemble(cls, package_data, resource, codebase, package_adder):
118118
package_data=package_data,
119119
datafile_path=datafile_path,
120120
)
121-
package_uid = package.package_uid
122-
123-
# NOTE: we do not attach files to the Package level. Instead we
124-
# update `for_package` in the file
125-
package_adder(package_uid, resource, codebase)
126121

127122
if not package.license_expression:
128123
package.license_expression = cls.compute_normalized_license(package)
129124

130125
yield package
131126

127+
package_uid = package.package_uid
128+
# NOTE: we do not attach files to the Package level. Instead we
129+
# update `for_package` in the file
130+
package_adder(package_uid, resource, codebase)
131+
132132
if resource.has_parent() and package_data.file_references:
133133
parent_resource = resource.parent(codebase)
134134
if parent_resource and package_data.file_references:

src/packagedcode/alpine.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ def assemble(cls, package_data, resource, codebase, package_adder):
9797
# path is found and processed: remove it, so we can check if we
9898
# found all of them
9999
del file_references_by_path[res.path]
100-
package_adder(package_uid, res, codebase)
101100
resources.append(res)
102101

103102
# if we have left over file references, add these to extra data
@@ -106,7 +105,9 @@ def assemble(cls, package_data, resource, codebase, package_adder):
106105
package.extra_data['missing_file_references'] = missing
107106

108107
yield package
109-
yield from resources
108+
for res in resources:
109+
package_adder(package_uid, res, codebase)
110+
yield res
110111

111112
dependent_packages = package_data.dependencies
112113
if dependent_packages:

src/packagedcode/models.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,11 @@ def add_to_package(package_uid, resource, codebase):
808808
Append `package_uid` to `resource.for_packages`, if the attribute exists and
809809
`package_uid` is not already in `resource.for_packages`.
810810
"""
811-
if hasattr(resource, 'for_packages') and isinstance(resource.for_packages, list):
811+
if (
812+
hasattr(resource, 'for_packages')
813+
and isinstance(resource.for_packages, list)
814+
and package_uid
815+
):
812816
if package_uid in resource.for_packages:
813817
return
814818
resource.for_packages.append(package_uid)
@@ -1113,16 +1117,21 @@ def assemble_from_many(cls, pkgdata_resources, codebase, package_adder=add_to_pa
11131117
package.license_expression = cls.compute_normalized_license(package)
11141118
yield package
11151119
yield from dependencies
1116-
yield from resources
11171120

1118-
# Associate Package to Resources once they have been yielded
1121+
# Associate Package to Resources and yield them
1122+
for resource in resources:
1123+
package_adder(package_uid, resource, codebase)
1124+
yield resource
1125+
11191126
for package_uid, resource in resources_from_package:
11201127
package_adder(package_uid, resource, codebase)
1128+
yield resource
11211129

11221130
# the whole parent subtree of the base_resource is for this package
11231131
if package_uid:
11241132
for res in base_resource.walk(codebase):
11251133
package_adder(package_uid, res, codebase)
1134+
yield res
11261135

11271136
@classmethod
11281137
def assemble_from_many_datafiles(

src/packagedcode/rpm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ def assemble(cls, package_data, resource, codebase, package_adder):
201201
if package_uid:
202202
# path is found and processed: remove it, so we can check if we
203203
# found all of them
204-
package_adder(package_uid, res, codebase)
205204
resources.append(res)
206205

207206
# if we have left over file references, add these to extra data
@@ -224,7 +223,9 @@ def assemble(cls, package_data, resource, codebase, package_adder):
224223
dep.namespace = namespace
225224
yield dep
226225

227-
yield from resources
226+
for resource in resources:
227+
package_adder(package_uid, resource, codebase)
228+
yield resource
228229

229230

230231
# TODO: add dependencies!!!

0 commit comments

Comments
 (0)