Skip to content

Commit 9433eec

Browse files
committed
Mark extra_requires as optional #3083
* Ensure extracted_requirement contains dependency name * Update test expectations Signed-off-by: Jono Yang <jyang@nexb.com>
1 parent d6b68d2 commit 9433eec

File tree

53 files changed

+533
-822
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+533
-822
lines changed

src/packagedcode/pypi.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -768,14 +768,16 @@ def parse(cls, location):
768768
name="python",
769769
)
770770
resolved_purl = get_resolved_purl(purl=purl, specifiers=SpecifierSet(python_requires_specifier))
771-
dependent_packages.append(models.DependentPackage(
772-
purl=str(resolved_purl.purl),
773-
scope=scope,
774-
is_runtime=True,
775-
is_optional=False,
776-
is_resolved=resolved_purl.is_resolved,
777-
extracted_requirement=f"python_requires{python_requires_specifier}",
778-
))
771+
dependent_packages.append(
772+
models.DependentPackage(
773+
purl=str(resolved_purl.purl),
774+
scope=scope,
775+
is_runtime=True,
776+
is_optional=False,
777+
is_resolved=resolved_purl.is_resolved,
778+
extracted_requirement=f"python_requires{python_requires_specifier}",
779+
)
780+
)
779781

780782
if section.name == "options.extras_require":
781783
for sub_section in section:
@@ -975,11 +977,7 @@ def get_requirements_txt_dependencies(location, include_nested=False):
975977
purl = None
976978

977979
purl = purl and purl.to_string() or None
978-
979-
if req.is_editable:
980-
requirement = req.dumps()
981-
else:
982-
requirement = req.dumps(with_name=False)
980+
requirement = req.dumps()
983981

984982
if location.endswith(
985983
(
@@ -1355,15 +1353,16 @@ def get_requires_dependencies(requires, default_scope='install'):
13551353
is_resolved = True
13561354
purl = purl._replace(version=specifier.version)
13571355

1358-
# we use the extra as scope if avialble
1359-
scope = get_extra(req.marker) or default_scope
1356+
# we use the extra as scope if available
1357+
extra = get_extra(req.marker)
1358+
scope = extra or default_scope
13601359

13611360
dependent_packages.append(
13621361
models.DependentPackage(
13631362
purl=purl.to_string(),
13641363
scope=scope,
13651364
is_runtime=True,
1366-
is_optional=False,
1365+
is_optional=True if bool(extra) else False,
13671366
is_resolved=is_resolved,
13681367
extracted_requirement=str(req),
13691368
))

tests/cluecode/data/plugin_email_url/emails-threshold.expected.json

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,4 @@
11
{
2-
"headers": [
3-
{
4-
"tool_name": "scancode-toolkit",
5-
"options": {
6-
"input": "<path>",
7-
"--email": true,
8-
"--json": "<file>",
9-
"--max-email": "2",
10-
"--strip-root": true
11-
},
12-
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
13-
"output_format_version": "2.0.0",
14-
"message": null,
15-
"errors": [],
16-
"warnings": [],
17-
"extra_data": {
18-
"system_environment": {
19-
"operating_system": "linux",
20-
"cpu_architecture": "64",
21-
"platform": "Linux-5.4.0-109-generic-x86_64-with-Ubuntu-18.04-bionic",
22-
"platform_version": "#123~18.04.1-Ubuntu SMP Fri Apr 8 09:48:52 UTC 2022",
23-
"python_version": "3.6.9 (default, Mar 15 2022, 13:55:28) \n[GCC 8.4.0]"
24-
},
25-
"spdx_license_list_version": "3.16",
26-
"files_count": 2
27-
}
28-
}
29-
],
302
"files": [
313
{
324
"path": "3w-xxxx.c",

tests/cluecode/data/plugin_email_url/emails.expected.json

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
11
{
2-
"headers": [
3-
{
4-
"tool_name": "scancode-toolkit",
5-
"options": {
6-
"input": "<path>",
7-
"--email": true,
8-
"--json": "<file>",
9-
"--strip-root": true
10-
},
11-
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
12-
"output_format_version": "2.0.0",
13-
"message": null,
14-
"errors": [],
15-
"warnings": [],
16-
"extra_data": {
17-
"system_environment": {
18-
"operating_system": "linux",
19-
"cpu_architecture": "64",
20-
"platform": "Linux-5.4.0-109-generic-x86_64-with-Ubuntu-18.04-bionic",
21-
"platform_version": "#123~18.04.1-Ubuntu SMP Fri Apr 8 09:48:52 UTC 2022",
22-
"python_version": "3.6.9 (default, Mar 15 2022, 13:55:28) \n[GCC 8.4.0]"
23-
},
24-
"spdx_license_list_version": "3.16",
25-
"files_count": 2
26-
}
27-
}
28-
],
292
"files": [
303
{
314
"path": "3w-xxxx.c",

tests/cluecode/data/plugin_email_url/urls-threshold.expected.json

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,4 @@
11
{
2-
"headers": [
3-
{
4-
"tool_name": "scancode-toolkit",
5-
"options": {
6-
"input": "<path>",
7-
"--json": "<file>",
8-
"--max-url": "2",
9-
"--strip-root": true,
10-
"--url": true
11-
},
12-
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
13-
"output_format_version": "2.0.0",
14-
"message": null,
15-
"errors": [],
16-
"warnings": [],
17-
"extra_data": {
18-
"system_environment": {
19-
"operating_system": "linux",
20-
"cpu_architecture": "64",
21-
"platform": "Linux-5.4.0-109-generic-x86_64-with-Ubuntu-18.04-bionic",
22-
"platform_version": "#123~18.04.1-Ubuntu SMP Fri Apr 8 09:48:52 UTC 2022",
23-
"python_version": "3.6.9 (default, Mar 15 2022, 13:55:28) \n[GCC 8.4.0]"
24-
},
25-
"spdx_license_list_version": "3.16",
26-
"files_count": 2
27-
}
28-
}
29-
],
302
"files": [
313
{
324
"path": "3w-xxxx.c",

tests/cluecode/data/plugin_email_url/urls.expected.json

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
11
{
2-
"headers": [
3-
{
4-
"tool_name": "scancode-toolkit",
5-
"options": {
6-
"input": "<path>",
7-
"--json": "<file>",
8-
"--strip-root": true,
9-
"--url": true
10-
},
11-
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
12-
"output_format_version": "2.0.0",
13-
"message": null,
14-
"errors": [],
15-
"warnings": [],
16-
"extra_data": {
17-
"system_environment": {
18-
"operating_system": "linux",
19-
"cpu_architecture": "64",
20-
"platform": "Linux-5.4.0-109-generic-x86_64-with-Ubuntu-18.04-bionic",
21-
"platform_version": "#123~18.04.1-Ubuntu SMP Fri Apr 8 09:48:52 UTC 2022",
22-
"python_version": "3.6.9 (default, Mar 15 2022, 13:55:28) \n[GCC 8.4.0]"
23-
},
24-
"spdx_license_list_version": "3.16",
25-
"files_count": 2
26-
}
27-
}
28-
],
292
"files": [
303
{
314
"path": "3w-xxxx.c",

tests/cluecode/data/plugin_filter_clues/filtered-expected.json

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,4 @@
11
{
2-
"headers": [
3-
{
4-
"tool_name": "scancode-toolkit",
5-
"options": {
6-
"input": "<path>",
7-
"--copyright": true,
8-
"--email": true,
9-
"--filter-clues": true,
10-
"--info": true,
11-
"--json": "<file>",
12-
"--license": true,
13-
"--url": true
14-
},
15-
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
16-
"output_format_version": "2.0.0",
17-
"message": null,
18-
"errors": [],
19-
"warnings": [],
20-
"extra_data": {
21-
"system_environment": {
22-
"operating_system": "linux",
23-
"cpu_architecture": "64",
24-
"platform": "Linux-5.4.0-109-generic-x86_64-with-Ubuntu-18.04-bionic",
25-
"platform_version": "#123~18.04.1-Ubuntu SMP Fri Apr 8 09:48:52 UTC 2022",
26-
"python_version": "3.6.9 (default, Mar 15 2022, 13:55:28) \n[GCC 8.4.0]"
27-
},
28-
"spdx_license_list_version": "3.16",
29-
"files_count": 1
30-
}
31-
}
32-
],
332
"files": [
343
{
354
"path": "LICENSE",

tests/cluecode/data/plugin_filter_clues/filtered-expected2.json

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,4 @@
11
{
2-
"headers": [
3-
{
4-
"tool_name": "scancode-toolkit",
5-
"options": {
6-
"input": "<path>",
7-
"--copyright": true,
8-
"--email": true,
9-
"--filter-clues": true,
10-
"--info": true,
11-
"--json": "<file>",
12-
"--license": true,
13-
"--url": true
14-
},
15-
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
16-
"output_format_version": "2.0.0",
17-
"message": null,
18-
"errors": [],
19-
"warnings": [],
20-
"extra_data": {
21-
"system_environment": {
22-
"operating_system": "linux",
23-
"cpu_architecture": "64",
24-
"platform": "Linux-5.4.0-109-generic-x86_64-with-Ubuntu-18.04-bionic",
25-
"platform_version": "#123~18.04.1-Ubuntu SMP Fri Apr 8 09:48:52 UTC 2022",
26-
"python_version": "3.6.9 (default, Mar 15 2022, 13:55:28) \n[GCC 8.4.0]"
27-
},
28-
"spdx_license_list_version": "3.16",
29-
"files_count": 1
30-
}
31-
}
32-
],
332
"files": [
343
{
354
"path": "LICENSE2",

tests/cluecode/data/plugin_filter_clues/filtered-expected3.json

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,4 @@
11
{
2-
"headers": [
3-
{
4-
"tool_name": "scancode-toolkit",
5-
"options": {
6-
"input": "<path>",
7-
"--copyright": true,
8-
"--email": true,
9-
"--filter-clues": true,
10-
"--info": true,
11-
"--json": "<file>",
12-
"--license": true,
13-
"--url": true
14-
},
15-
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
16-
"output_format_version": "2.0.0",
17-
"message": null,
18-
"errors": [],
19-
"warnings": [],
20-
"extra_data": {
21-
"system_environment": {
22-
"operating_system": "linux",
23-
"cpu_architecture": "64",
24-
"platform": "Linux-5.4.0-109-generic-x86_64-with-Ubuntu-18.04-bionic",
25-
"platform_version": "#123~18.04.1-Ubuntu SMP Fri Apr 8 09:48:52 UTC 2022",
26-
"python_version": "3.6.9 (default, Mar 15 2022, 13:55:28) \n[GCC 8.4.0]"
27-
},
28-
"spdx_license_list_version": "3.16",
29-
"files_count": 1
30-
}
31-
}
32-
],
332
"files": [
343
{
354
"path": "LICENSE3",

tests/cluecode/data/plugin_ignore_copyrights/authors.expected.json

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,4 @@
11
{
2-
"headers": [
3-
{
4-
"tool_name": "scancode-toolkit",
5-
"options": {
6-
"input": "<path>",
7-
"--copyright": true,
8-
"--ignore-author": [
9-
"Berkeley"
10-
],
11-
"--json-pp": "<file>"
12-
},
13-
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
14-
"output_format_version": "2.0.0",
15-
"message": null,
16-
"errors": [],
17-
"warnings": [],
18-
"extra_data": {
19-
"system_environment": {
20-
"operating_system": "linux",
21-
"cpu_architecture": "64",
22-
"platform": "Linux-5.4.0-109-generic-x86_64-with-Ubuntu-18.04-bionic",
23-
"platform_version": "#123~18.04.1-Ubuntu SMP Fri Apr 8 09:48:52 UTC 2022",
24-
"python_version": "3.6.9 (default, Mar 15 2022, 13:55:28) \n[GCC 8.4.0]"
25-
},
26-
"spdx_license_list_version": "3.16",
27-
"files_count": 5
28-
}
29-
}
30-
],
312
"files": [
323
{
334
"path": "basic.tgz",

tests/cluecode/data/plugin_ignore_copyrights/holders.expected.json

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,4 @@
11
{
2-
"headers": [
3-
{
4-
"tool_name": "scancode-toolkit",
5-
"options": {
6-
"input": "<path>",
7-
"--copyright": true,
8-
"--ignore-copyright-holder": [
9-
"Regents"
10-
],
11-
"--json-pp": "<file>"
12-
},
13-
"notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
14-
"output_format_version": "2.0.0",
15-
"message": null,
16-
"errors": [],
17-
"warnings": [],
18-
"extra_data": {
19-
"system_environment": {
20-
"operating_system": "linux",
21-
"cpu_architecture": "64",
22-
"platform": "Linux-5.4.0-109-generic-x86_64-with-Ubuntu-18.04-bionic",
23-
"platform_version": "#123~18.04.1-Ubuntu SMP Fri Apr 8 09:48:52 UTC 2022",
24-
"python_version": "3.6.9 (default, Mar 15 2022, 13:55:28) \n[GCC 8.4.0]"
25-
},
26-
"spdx_license_list_version": "3.16",
27-
"files_count": 5
28-
}
29-
}
30-
],
312
"files": [
323
{
334
"path": "basic.tgz",

0 commit comments

Comments
 (0)