nexB / commoncode

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

codebase_attributes are ignored when creating a VirtualCodebase from a scan

JonoYang opened this issue · comments

I am using commoncode 31.0.0 to create a VirtualCodebase from a scan using the following code:

    vc = VirtualCodebase(
        location=scan_file_location,
        codebase_attributes=dict(
            packages=attr.ib(default=attr.Factory(list))
        ),
        resource_attributes=dict(
            packages=attr.ib(default=attr.Factory(list)),
            for_packages=attr.ib(default=attr.Factory(list))
        )
    )

The resulting VirtualCodebase has an attribute named packages, but its value is None instead of a list.

The issue is at https://github.com/nexB/commoncode/blob/main/src/commoncode/resource.py#L1842, where we try to get the codebase attribute value from the scan passed into VirtualCodebase. If there is no codebase attribute with the same name in the scan, then None is assigned to the codebase attribute instead of the default value that was passed in when VirtualCodebase was instantiated.

This fix has been merged into the main branch.