Skip to content

Commit

Permalink
Report top level dependencies properly for conda packages
Browse files Browse the repository at this point in the history
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
  • Loading branch information
AyanSinhaMahapatra committed Jan 14, 2025
1 parent dce5b2a commit 20663f4
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/packagedcode/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ def assemble(cls, package_data, resource, codebase, package_adder=models.add_to_
package.populate_license_fields()
yield package

dependent_packages = package_data.dependencies
if dependent_packages:
yield from models.Dependency.from_dependent_packages(
dependent_packages=dependent_packages,
datafile_path=resource.path,
datasource_id=package_data.datasource_id,
package_uid=package.package_uid,
)

CondaMetaYamlHandler.assign_package_to_resources(
package=package,
resource=resource,
Expand Down Expand Up @@ -104,6 +113,14 @@ def assemble(cls, package_data, resource, codebase, package_adder=models.add_to_
codebase=codebase,
package_adder=package_adder,
)
meta_yaml_package_data = models.PackageData.from_dict(conda_meta_yaml_package_data)
if meta_yaml_package_data.dependencies:
yield from models.Dependency.from_dependent_packages(
dependent_packages=meta_yaml_package_data.dependencies,
datafile_path=conda_meta_yaml.path,
datasource_id=meta_yaml_package_data.datasource_id,
package_uid=package.package_uid,
)
yield conda_meta_yaml

package.populate_license_fields()
Expand Down
45 changes: 45 additions & 0 deletions tests/packagedcode/data/conda/assembly-conda-scan.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,51 @@
}
],
"dependencies": [
{
"purl": "pkg:conda/zlib",
"extracted_requirement": "1.2.13 h5eee18b_1",
"scope": "host",
"is_runtime": false,
"is_optional": true,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {},
"dependency_uid": "pkg:conda/zlib?uuid=fixed-uid-done-for-testing-5642512d1758",
"for_package_uid": "pkg:conda/[email protected]?uuid=fixed-uid-done-for-testing-5642512d1758",
"datafile_path": "assembly/opt/conda/pkgs/requests-2.32.3-py312h06a4308_1/info/recipe/meta.yaml",
"datasource_id": "conda_meta_yaml"
},
{
"purl": "pkg:conda/certifi",
"extracted_requirement": ">=2017.4.17",
"scope": "run",
"is_runtime": true,
"is_optional": false,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {},
"dependency_uid": "pkg:conda/certifi?uuid=fixed-uid-done-for-testing-5642512d1758",
"for_package_uid": "pkg:conda/[email protected]?uuid=fixed-uid-done-for-testing-5642512d1758",
"datafile_path": "assembly/opt/conda/pkgs/requests-2.32.3-py312h06a4308_1/info/recipe/meta.yaml",
"datasource_id": "conda_meta_yaml"
},
{
"purl": "pkg:conda/chardet",
"extracted_requirement": ">=3.0.2,<6",
"scope": "run_constrained",
"is_runtime": true,
"is_optional": false,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {},
"dependency_uid": "pkg:conda/chardet?uuid=fixed-uid-done-for-testing-5642512d1758",
"for_package_uid": "pkg:conda/[email protected]?uuid=fixed-uid-done-for-testing-5642512d1758",
"datafile_path": "assembly/opt/conda/pkgs/requests-2.32.3-py312h06a4308_1/info/recipe/meta.yaml",
"datasource_id": "conda_meta_yaml"
},
{
"purl": "pkg:pypi/charset-normalizer",
"extracted_requirement": "<4,>=2",
Expand Down
7 changes: 7 additions & 0 deletions tests/packagedcode/data/plugin/plugins_list_linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ Package type: conan
description: conan recipe
path_patterns: '*/conanfile.py'
--------------------------------------------
Package type: conda
datasource_id: conda_meta_json
documentation URL: https://docs.conda.io/
primary language: Python
description: Conda metadata JSON in rootfs
path_patterns: '*conda-meta/*.json'
--------------------------------------------
Package type: conda
datasource_id: conda_meta_yaml
documentation URL: https://docs.conda.io/
Expand Down

0 comments on commit 20663f4

Please sign in to comment.