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

[FEATURE] SPDX License factory #304

Closed
jkowalleck opened this issue Sep 12, 2022 · 7 comments · Fixed by #305
Closed

[FEATURE] SPDX License factory #304

jkowalleck opened this issue Sep 12, 2022 · 7 comments · Fixed by #305
Assignees
Labels
enhancement New feature or request

Comments

@jkowalleck
Copy link
Member

have a license factory, a thing that i feed a string and that returns the appropriate license model: expression, named license, spdx license.

required for

as a contrast implementation of CycloneDX/cyclonedx-python#410

solution ala

@jkowalleck jkowalleck added the enhancement New feature or request label Sep 12, 2022
@jkowalleck jkowalleck self-assigned this Sep 12, 2022
@jkowalleck
Copy link
Member Author

will prepare a POC for discussion

this would lead to a v2 implementation in module(file) cyclonedx/factory/license.py
and a forward-port to v3

@Jonas-vdb
Copy link

Will there be an option to force a specific license model? e.g. Dependency Track does not support expressions yet so even if the string is actually an expression, forcing it to a named license would at least make it visible in Dependency Track (knowing that the matching will not work).

@jkowalleck
Copy link
Member Author

jkowalleck commented Sep 12, 2022

good point. the factory should be supporting both

  • string -> Expression|Named|SPDX|None
  • string -> Named|SPDX|None

the later one is the thing that is required, so that an implementation in the https://github.com/CycloneDX/cyclonedx-python/ should be a one-liner, then.

@Jonas-vdb
Copy link

I'm curious to see how it will determine what the return type should be.

  • Expression if there is a logical operator?
  • SPDX ID if it is part of the list of possible SPDX license identifiers e.g. https://spdx.org/licenses/ ?
  • Named if none of the above apply?

Examples of licenses which are currently present in the BOM we use:

  • BSD-like: Not an Expression, not a valid SPDX Identifier so it would be Named?
  • MIT: Not an Expression but it is a valid SPDX identifier
  • BSD-2-Clause or Apache-2.0: Expression

@jkowalleck
Copy link
Member Author

jkowalleck commented Sep 12, 2022

re: #304 (comment)

the source of SPDX is different, but the rest is basically correc.
just see the JS and PHP implementations linked above as a reference point.

a best-effort detection:

  • if value starts with ( and ends with ) => probably an expression -> return license expression
    • i asked the SPDX people if they had a regex for the expression - even they do not have one, so we need to go with best-effort detection.
  • else if: lower-cased value is a known/supported SPDX license => return license with id
  • else: return license with name

implementation will be good-enough for now and can be seen as a ground for improvements later.

see #305

@jkowalleck jkowalleck mentioned this issue Sep 12, 2022
4 tasks
@Jonas-vdb
Copy link

Note: identifying an expression with brackets will not always work.

Example of license expression without brackets:

('License', 'BSD-2-Clause or Apache-2.0')

image

@jkowalleck
Copy link
Member Author

jkowalleck commented Sep 13, 2022

i am providing a best-effort-implementation - as a ground for improvements.
after i am done with this, you are free to make the SPDX expression detection better.

@madpah madpah changed the title license factory [FEATURE] SPDX License factory Sep 15, 2022
madpah added a commit that referenced this issue Sep 15, 2022
feat: add license factories to more easily support creation of `License` or `LicenseChoice` from SPDX license strings #304
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants