Skip to content

Commit b0aff52

Browse files
Merge pull request #4078 from aboutcode-org/fix-package-scan-bugs
Fix conda environment yaml parsing errors
2 parents abf65c7 + 2de7396 commit b0aff52

File tree

7 files changed

+73
-3
lines changed

7 files changed

+73
-3
lines changed

src/packagedcode/conda.py

+3
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ def parse(cls, location, package_only=False):
378378
primary_language=cls.default_primary_language,
379379
dependencies=dependencies,
380380
extra_data=extra_data,
381+
is_private=True,
381382
)
382383
yield models.PackageData.from_data(package_data, package_only)
383384

@@ -536,6 +537,8 @@ def get_conda_yaml_dependencies(conda_data):
536537

537538
if "::" in dep:
538539
namespace, dep = dep.split("::")
540+
if "/" in namespace or ":" in namespace:
541+
namespace = None
539542

540543
req = parse_requirement_line(dep)
541544
if req:

tests/packagedcode/data/conda/conda-yaml/phc-gnn/environment_gpu.yml-expected.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"notice_text": null,
3434
"source_packages": [],
3535
"file_references": [],
36-
"is_private": false,
36+
"is_private": true,
3737
"is_virtual": false,
3838
"extra_data": {
3939
"channels": [

tests/packagedcode/data/conda/conda-yaml/ringer/environment.yaml-expected.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"notice_text": null,
3434
"source_packages": [],
3535
"file_references": [],
36-
"is_private": false,
36+
"is_private": true,
3737
"is_virtual": false,
3838
"extra_data": {
3939
"channels": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: test
2+
dependencies:
3+
- https://104.17.92.24:443::flask=1.0.2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[
2+
{
3+
"type": "conda",
4+
"namespace": null,
5+
"name": "test",
6+
"version": null,
7+
"qualifiers": {},
8+
"subpath": null,
9+
"primary_language": "Python",
10+
"description": null,
11+
"release_date": null,
12+
"parties": [],
13+
"keywords": [],
14+
"homepage_url": null,
15+
"download_url": null,
16+
"size": null,
17+
"sha1": null,
18+
"md5": null,
19+
"sha256": null,
20+
"sha512": null,
21+
"bug_tracking_url": null,
22+
"code_view_url": null,
23+
"vcs_url": null,
24+
"copyright": null,
25+
"holder": null,
26+
"declared_license_expression": null,
27+
"declared_license_expression_spdx": null,
28+
"license_detections": [],
29+
"other_license_expression": null,
30+
"other_license_expression_spdx": null,
31+
"other_license_detections": [],
32+
"extracted_license_statement": null,
33+
"notice_text": null,
34+
"source_packages": [],
35+
"file_references": [],
36+
"is_private": true,
37+
"is_virtual": false,
38+
"extra_data": {},
39+
"dependencies": [
40+
{
41+
"purl": "pkg:conda/[email protected]",
42+
"extracted_requirement": "=1.0.2",
43+
"scope": "dependencies",
44+
"is_runtime": true,
45+
"is_optional": false,
46+
"is_pinned": true,
47+
"is_direct": true,
48+
"resolved_package": {},
49+
"extra_data": {}
50+
}
51+
],
52+
"repository_homepage_url": null,
53+
"repository_download_url": null,
54+
"api_data_url": null,
55+
"datasource_id": "conda_yaml",
56+
"purl": "pkg:conda/test"
57+
}
58+
]

tests/packagedcode/data/misc/conda/scenicplus.yaml-expected.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"notice_text": null,
3434
"source_packages": [],
3535
"file_references": [],
36-
"is_private": false,
36+
"is_private": true,
3737
"is_virtual": false,
3838
"extra_data": {
3939
"channels": [

tests/packagedcode/test_conda.py

+6
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ def test_parse_conda_yaml_simple_dependencies(self):
115115
expected_loc = self.get_test_loc('conda/conda-yaml/ringer/environment.yaml-expected.json')
116116
self.check_packages_data(package, expected_loc, regen=REGEN_TEST_FIXTURES)
117117

118+
def test_parse_conda_yaml_does_not_fail_on_test_files_with_port(self):
119+
test_file = self.get_test_loc('conda/conda-yaml/test/environment_host_port.yml')
120+
package = conda.CondaYamlHandler.parse(test_file)
121+
expected_loc = self.get_test_loc('conda/conda-yaml/test/environment_host_port.yml-expected.json')
122+
self.check_packages_data(package, expected_loc, regen=REGEN_TEST_FIXTURES)
123+
118124
def test_conda_get_conda_meta_json(self):
119125
meta_yaml_path = 'conda/pkgs/requests-2.32.3-py312h06a4308_1/info/recipe/meta.yaml'
120126
conda_meta_json_path = 'conda/conda-meta/requests-2.32.3-py312h06a4308_1.json'

0 commit comments

Comments
 (0)