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

feat(spdx): Expose the validation of license text files' existence #9523

Conversation

nnobelis
Copy link
Member

@nnobelis nnobelis commented Nov 28, 2024

ORT has a complicate logic to search for a file containing the full license text of a given license: several search paths are tried. Unfortunately, the latter are not exposed, making it hard for an alternative LicenseTextProvider to have the same logic. Additionally, the current code assumes that the license files are on a local storage and the I/Os are therefore cheap. To allow the current utility function to be used with a LicenseTextProvider that works with license text files stored on a network storage, this commit exposes the validation function.

Copy link

codecov bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.97%. Comparing base (a093540) to head (ed2f67e).
Report is 129 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #9523   +/-   ##
=========================================
  Coverage     67.97%   67.97%           
  Complexity     1290     1290           
=========================================
  Files           249      249           
  Lines          8813     8813           
  Branches        916      916           
=========================================
  Hits           5991     5991           
  Misses         2433     2433           
  Partials        389      389           
Flag Coverage Δ
funTest-docker 64.84% <ø> (ø)
funTest-non-docker 33.24% <ø> (ø)
test 35.84% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

return getLicenseTextReader(id, handleExceptions, licenseTextDirectories) { dir, filename ->
dir.resolve(filename).takeIf { it.isFile }
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Have you considered refactoring the function to stop returning a lambda, in favour of the actual text / String?

Copy link
Member Author

@nnobelis nnobelis Nov 29, 2024

Choose a reason for hiding this comment

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

No, what would be the motivation to do it ? Just for code cleanup ?

BTW, do you know why it was decided to return a lambda in the first place ?

EDIT: I think @mnonnenmacher wrote the implementation. Could you please share your opinion on this ?

Copy link
Member

Choose a reason for hiding this comment

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

BTW, do you know why it was decided to return a lambda in the first place ?

Git blame is your friend, the rationale is in the commit message of 45a3087.

Copy link
Member

@fviernau fviernau Nov 29, 2024

Choose a reason for hiding this comment

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

No, what would be the motivation to do it ?

Motivation IMO would be to have a cleaner / simpler (public) API.
The approach to do this lazily could still be kept, but by an ORT internal function.

(To me this API looks a bit more complicated than necessary / not clean enough, which I believe it should be fixed before made public).

I don't understand why exposing something like the following does not suffice (which I believe we already have).

interface LicenseTextReader {
    fun getLicenseText(licenseId: String, handleExceptions: Boolean)
}

fun getLicenseTextReader(textDirectories: List<File>)

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

This PR exposes return type (() -> String)? of getLicenseTextReader(), doesn't it ?

Copy link
Member Author

@nnobelis nnobelis Nov 29, 2024

Choose a reason for hiding this comment

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

Yes, but this is because the LicenseTextProvider.getLicenseTextReader also exposes this return type:

fun getLicenseTextReader(licenseId: String): (() -> String)?

getLicenseText -> String?
getLicenseTextReader -> (() -> String)?

Therefore this is consistent with the current state of the implementation.

ORT has a complicate logic to search for a file containing the full license
text of a given license: several search paths are tried. Unfortunately,
the latter are not exposed, making it hard for an alternative
`LicenseTextProvider` to have the same logic. Additionally, the current
code assumes that the license files are on a local storage and the I/Os are
therefore cheap. To allow the current utility function to be used with a
`LicenseTextProvider` that works with license text files stored on a
network storage, this commit exposes the validation function.

Signed-off-by: Nicolas Nobelis <[email protected]>
@nnobelis nnobelis force-pushed the nnobelis/license_text_loading branch from 4537bc8 to ed2f67e Compare November 29, 2024 07:27
@nnobelis nnobelis marked this pull request as ready for review November 29, 2024 07:28
@nnobelis nnobelis requested a review from a team as a code owner November 29, 2024 07:28
@nnobelis nnobelis requested a review from fviernau November 29, 2024 07:32
@sschuberth
Copy link
Member

ORT has a complicate logic to search for a file containing the full license text of a given license: several search paths are tried. Unfortunately, the latter are not exposed, making it hard for an alternative LicenseTextProvider to have the same logic. Additionally, the current code assumes that the license files are on a local storage and the I/Os are therefore cheap. To allow the current utility function to be used with a LicenseTextProvider that works with license text files stored on a network storage, this commit exposes the validation function.

I totally agree to the described limitation, and that the current code with top-level functions is really ugly and hard to maintain.

That's why I started a while ago to think about a "license text provider API" where implementations should be done as plugins. Now that we have the KSP-based plugin architecture, it's probably a good time to revive that effort and implement it before making further changes to this code area.

@nnobelis
Copy link
Member Author

@sschuberth Even if the current License Test Providers is migrated to a plugin architecture, you would still need to decouple the DefaultLicenseProvider to the logic for searching different paths with a given naming convention, so that other providers can use and extends it.
IMO, the API you mention should allow to:

  • control the logic for the lookup of the licence texts, by adding/remove paths and controlling their priority
  • control the file loading mechanism to allow some pre- and postprocessing

and in parallel you would have a core engine that processes the paths according to their priority, and call the processing functions.

However, we should discuss that with the Core developers in tech meeting.

The question is: How to move forward now ?
Who is going to actively work on this task ?

@nnobelis
Copy link
Member Author

This PR is not needed by the ORT Server anymore:
Superseeded by eclipse-apoapsis/ort-server#1654

See also #9620 for the continuation of the discussion.

@nnobelis nnobelis closed this Dec 16, 2024
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.

3 participants