Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ The following organizations or individuals have contributed to ScanCode:

- Abhigyan Kumar Singh @Abhigyankrsingh
- Abhishek Kumar @Abhishek-Dev09
- Adnan Raza @Mars-60
- Aditya Viki @adityaviki
- Adrian Braemer @abraemer
- Agni Bhattacharyya @PyAgni
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
Next release
--------------

- Fix incorrect optional dependency reporting when parsing Poetry lockfiles.
https://github.com/aboutcode-org/scancode-toolkit/issues/5294

- Fix the optional ``licenses`` extra dependency typo to install
``licensedcode-data``.
https://github.com/aboutcode-org/scancode-toolkit/pull/5056
Expand Down
2 changes: 1 addition & 1 deletion src/packagedcode/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ def parse(cls, location, package_only=False):
)
resolved_package = models.PackageData.from_data(package_data, package_only)

is_optional = package.get("is_optional") or True
is_optional = package.get("optional", False)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good catch

dependency = models.DependentPackage(
purl=resolved_package.purl,
extracted_requirement=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"extracted_requirement": null,
"scope": null,
"is_runtime": true,
"is_optional": true,
"is_optional": false,
"is_pinned": true,
"is_direct": false,
"resolved_package": {
Expand Down Expand Up @@ -579,7 +579,7 @@
"extracted_requirement": null,
"scope": null,
"is_runtime": true,
"is_optional": true,
"is_optional": false,
"is_pinned": true,
"is_direct": false,
"resolved_package": {
Expand Down Expand Up @@ -649,7 +649,7 @@
"extracted_requirement": null,
"scope": null,
"is_runtime": true,
"is_optional": true,
"is_optional": false,
"is_pinned": true,
"is_direct": false,
"resolved_package": {
Expand Down Expand Up @@ -730,7 +730,7 @@
"extracted_requirement": null,
"scope": null,
"is_runtime": true,
"is_optional": true,
"is_optional": false,
"is_pinned": true,
"is_direct": false,
"resolved_package": {
Expand Down Expand Up @@ -921,7 +921,7 @@
"extracted_requirement": null,
"scope": null,
"is_runtime": true,
"is_optional": true,
"is_optional": false,
"is_pinned": true,
"is_direct": false,
"resolved_package": {
Expand Down Expand Up @@ -1033,7 +1033,7 @@
"extracted_requirement": null,
"scope": null,
"is_runtime": true,
"is_optional": true,
"is_optional": false,
"is_pinned": true,
"is_direct": false,
"resolved_package": {
Expand Down Expand Up @@ -1462,7 +1462,7 @@
"extracted_requirement": null,
"scope": null,
"is_runtime": true,
"is_optional": true,
"is_optional": false,
"is_pinned": true,
"is_direct": false,
"resolved_package": {
Expand Down Expand Up @@ -1528,7 +1528,7 @@
"extracted_requirement": null,
"scope": null,
"is_runtime": true,
"is_optional": true,
"is_optional": false,
"is_pinned": true,
"is_direct": false,
"resolved_package": {
Expand Down Expand Up @@ -1605,7 +1605,7 @@
"extracted_requirement": null,
"scope": null,
"is_runtime": true,
"is_optional": true,
"is_optional": false,
"is_pinned": true,
"is_direct": false,
"resolved_package": {
Expand Down Expand Up @@ -1792,7 +1792,7 @@
"extracted_requirement": null,
"scope": null,
"is_runtime": true,
"is_optional": true,
"is_optional": false,
"is_pinned": true,
"is_direct": false,
"resolved_package": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion tests/packagedcode/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,39 @@ def test_parse_poetry_lock_univers(self):
expected_loc = self.get_test_loc('pypi/poetry/univers-poetry.lock-expected.json')
self.check_packages_data(package, expected_loc, regen=REGEN_TEST_FIXTURES)

def test_parse_poetry_lock_package_optional(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use an actual test file and expected results file like in the tests above?

test_file = self.get_temp_file('poetry.lock')
with open(test_file, 'w') as lockfile:
lockfile.write('''\
[[package]]
name = "required-dep"
version = "1.0.0"
description = "required dependency"
optional = false
python-versions = ">=3.8"

[[package]]
name = "optional-dep"
version = "2.0.0"
description = "optional dependency"
optional = true
python-versions = ">=3.8"

[metadata]
lock-version = "2.0"
python-versions = ">=3.8"
content-hash = "test"
''')

package_data = list(pypi.PoetryLockHandler.parse(test_file))[0]
dependencies_by_purl = {
dependency['purl']: dependency
for dependency in package_data.dependencies
}

assert dependencies_by_purl['pkg:pypi/required-dep@1.0.0']['is_optional'] is False
assert dependencies_by_purl['pkg:pypi/optional-dep@2.0.0']['is_optional'] is True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to parse results and assert specifically, we run whole file results test with a test and an expected file, just check the expected behaviour and results as a whole


def test_parse_pyproject_toml_poetry_univers(self):
test_file = self.get_test_loc('pypi/poetry/univers/pyproject.toml')
package = pypi.PoetryPyprojectTomlHandler.parse(test_file)
Expand Down Expand Up @@ -805,4 +838,3 @@ def test_parse_setup_py(test_loc):
)
def test_parse_more_setup_py(test_loc):
check_setup_py_parsing(test_loc)