Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(nuget): add nuget dependency extract #3121

Conversation

hellhound-abu
Copy link

@hellhound-abu hellhound-abu commented Oct 6, 2022

Fixes #0000

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled 📑 and links the original issue above 🔗
  • Tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR
    Run tests locally to check for errors.
  • Commits are in uniquely-named feature branch and has no merge conflicts 📁

@AyanSinhaMahapatra
Copy link
Member

Thanks! Could you fix the test failures at tests/packagedcode/test_nuget.py with:

  • pytest -vvs tests/packagedcode/test_nuget.py and then
  • SCANCODE_REGEN_TEST_FIXTURES=yes pytest -vvs tests/packagedcode/test_nuget.py --lf

Also please add your signoff. 🙇

@pombredanne
Copy link
Member

@hellhound-abu gentle ping.. we would like to merge this... but we cannot unless you update your PR at least with a DCO signoff.

@pombredanne
Copy link
Member

@6mile ping you seem to be from the same group, may be you can help there?

@6mile
Copy link

6mile commented Oct 28, 2022

@6mile ping you seem to be from the same group, may be you can help there?

I've let him know. Cheers.

@jaitaiwan
Copy link

Hey folks, Dan from SecureStack here. Abu is on holidays so won’t be able to contribute till 2 weeks from now. I can fix the failing tests if that’s helpful but that won’t help get a DCO from him.

Do you have a way around this or content to wait?

@pombredanne
Copy link
Member

@jaitaiwan Thank you ++ for your reply!
No rush, we can wait alright!
We are just making sure we do not have too many PRs that could go stale from lack of TLC especially like this one which is valuable addition.

Whatever you guys are doing on SecureStack looks great BTW! 👍

@pombredanne
Copy link
Member

@hellhound-abu gentle ping ... you may be back now?

    1. update code to look for dependencies in a group as well
    2. update nuget test data with dependency data

Signed-off-by: Abedin Poonawala <[email protected]>
@hellhound-abu
Copy link
Author

Updated the branch with necessary changes. If we can merge it whenever possible.

Thanks for waiting.

Copy link
Member

@pombredanne pombredanne left a comment

Choose a reason for hiding this comment

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

@hellhound-abu Thank you ++ for the updates! I posted a few review comments inline for your consideration. There is also one failing test.

"""
Handle NuGet packages and their manifests.
"""
# TODO: add dependencies

# TODO: Add section to handle dependencies of dependencies
Copy link
Member

Choose a reason for hiding this comment

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

For this you may want to create a separate issue... TODO comments (that I tend to abuse) eventually get lost.
Note also that for a full, dynamic dependency resolution of nugets. there is this new project at https://github.com/nexB/nuget-inspector

Choose a reason for hiding this comment

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

I say the same thing about TODO's internally 😂 That nuget-inspector proejct looks promising.

type='nuget',
namespace=None,
name=dependency.get("@id"),
version=dependency.get("@version"),
Copy link
Member

Choose a reason for hiding this comment

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

You can only put a version here if this is not a range so IMHO you would have to test for this.

dep_pack = models.DependentPackage(
purl=str(dpurl),
extracted_requirement=dependency.get("@version"),
scope="dependency",
Copy link
Member

Choose a reason for hiding this comment

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

Would not each dependency group become a scope here?

scope="dependency",
is_runtime=False,
is_optional=False,
is_resolved=True,
Copy link
Member

Choose a reason for hiding this comment

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

A dependency is resolved if an only if we have a concrete version and not a range. Here the version is optional AFAIK and could be a range?


dependencies.append(dep_pack)

if "dependency" in nuspec.get("dependencies"):
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer something like this, and then reuse the nuget_dependency var below:

Suggested change
if "dependency" in nuspec.get("dependencies"):
nuget_dependencies = nuspec.get("dependencies") or {}
nuget_dependency = nuget_dependencies.get("dependency")
if nuget_dependency:

Choose a reason for hiding this comment

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

Out of curiosity, any reason for or {} over get("...", {})?

Copy link
Member

Choose a reason for hiding this comment

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

@jaitaiwan re:

Out of curiosity, any reason for or {} over get("...", {})?

This is an idiom I like to use to make sure that I am getting a proper empty dict in all cases even if the get returns None or some emptyish value.
Getting an empty dict when you expect a dict enable chaining the next call without requiring an extra check for empties.

>>> repr({1: None, 2: "", 3: {"bar": "baz"}}.get(1, {}))
'None'
>>> repr({1: None, 2: "", 3: {"bar": "baz"}}.get(1, {}) or {})
'{}'
>>> repr({1: None, 2: "", 3: {"bar": "baz"}}.get(1) or {})
'{}'

Choose a reason for hiding this comment

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

Fair call. thanks!

dep_pack = models.DependentPackage(
purl=str(dpurl),
extracted_requirement=nuspec.get("dependencies").get(
"dependency").get("@version"),
Copy link
Member

Choose a reason for hiding this comment

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

Factor version here and above in a variable.

scope="dependency",
is_runtime=False,
is_optional=False,
is_resolved=True,
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above... resolve is True IFF we have a concrete pinned, non-empty version

return dependencies

except Exception as e:
print(e)
Copy link
Member

@pombredanne pombredanne Nov 22, 2022

Choose a reason for hiding this comment

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

Please do not print exceptions. In general your should avoid to wrap you code in a try/except altogether as this can never be debugged this way. Let the exception bubble up and we will catch it where needed, and worse case at the top level.

@@ -62,14 +144,15 @@ def parse(cls, location):

# Summary: A short description of the package for UI display. If omitted, a
# truncated version of description is used.
description = build_description(nuspec.get('summary') , nuspec.get('description'))
description = build_description(
Copy link
Member

Choose a reason for hiding this comment

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

Why wrapping this on tow lines? I am not sure this helps with readability.

"datasource_id": "nuget_nupsec",
"purl": "pkg:nuget/[email protected]"
}
"type": "nuget",
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid changing the spacing if possible as this makes reviewing the diff difficult

@pombredanne
Copy link
Member

@hellhound-abu Happy new year! gentle ping

@pombredanne pombredanne added this to the v32.0 milestone Jan 6, 2023
@pombredanne pombredanne requested review from jaitaiwan and AyanSinhaMahapatra and removed request for jaitaiwan January 9, 2023 15:45
@pombredanne
Copy link
Member

@AyanSinhaMahapatra since there is no reply for now, let's move this to the next milestone

@AyanSinhaMahapatra AyanSinhaMahapatra modified the milestones: v32.0, v32.1 Jan 9, 2023
@AyanSinhaMahapatra
Copy link
Member

@pombredanne moved this to v32.1

@pombredanne pombredanne mentioned this pull request Jan 18, 2023
4 tasks
@pombredanne
Copy link
Member

pombredanne commented Jan 18, 2023

I have applied the fixes in #3206 on top of your commits. So I am losing this and will merge this other branch!
Thanks!

@pombredanne pombredanne modified the milestones: v32.1, v32.0 Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants