Implement `for_packages_append` on `Resource`
JonoYang opened this issue · comments
We are updating the application package scanning process on scancode.io in nexB/scancode.io#447. We are implementing the package assembly step from scancode-toolkit in scancode.io. The assembly methods from packagedcode associates Resources to packages by appending the package_uid
to the for_packages
attribute on Resources. This method of associating Resources to Packages does not work on scancode.io because for_packages
is an property on CodebaseResource
that generates a list of purls from DiscoveredPackage
s associated with a CodebaseResource
.
A solution would be to create a method on the Resource
class named for_packages_append
that appends a package_uid
to Resource.for_packages
. This extra level of indirection allows us to create a different implementation on CodebaseResource
for associating Packages to Resources using the same interface.
re:
A solution would be to create a method on the Resource class named for_packages_append that appends a package_uid to Resource.for_packages
This can work.
An alternative could be use a new Codebase argument that would be the Resource class to use... today this class is crafted based on the provided attributes
commoncode/src/commoncode/resource.py
Line 402 in d3eed9a
Another possibility could be to add and pass a add_to_package(resource, ...)
method as an argument to the assemble(..., package_adder=add_to_package, ...)
functions?
With a default that would be using a list-backed implementation... and then in SCIO you would have a Django db-backed implmentation of the same function and you would call it when you call assemble?
Another possibility could be to add and pass a add_to_package(resource, ...) method as an argument to the assemble(..., package_adder=add_to_package, ...) functions?
With a default that would be using a list-backed implementation... and then in SCIO you would have a Django db-backed implmentation of the same function and you would call it when you call assemble?
I like this approach better than the one I posted before. It makes more sense to pass in the package adding function as an argument into assemble
than to add a method to Resource
that deals with an attribute that may not be there.
This has been implemented and merged in nexB/scancode-toolkit#3035
Thanks!