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: option to choose license format #410

Closed
wants to merge 4 commits into from

Conversation

Jonas-vdb
Copy link

@Jonas-vdb Jonas-vdb commented Sep 8, 2022

Updates

  • Added a new flag to choose the license format with default set to the original
  • Updated the readme
  • Fixed a bug when using the license from the classifier

Important change: the license classifier header will only be used if the license header is not available.
This codepath was not working before, it was looping over the different letters of the classifier values instead of looping over all the classifier headers.

Note: When choosing license as license output format, the SPDX expression is set as the license name property. The license format is not a valid SPDX licenseID. So this PR will only add the ability to SEE the license. The matching will no actually work.
See comment from @madpah in #377

fixes #378

@Jonas-vdb Jonas-vdb requested a review from a team as a code owner September 8, 2022 13:21
…he original

- Updated the readme
- Fixed a bug when using the license from the classifier

Signed-off-by: Jonas Van Den Bossche <jonas.van.den.bossche@awingu.com>
Copy link
Member

@jkowalleck jkowalleck left a comment

Choose a reason for hiding this comment

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

still needs some changes.

  • critical spots are marked with ❌
  • other comments are notes or questions

class EnvironmentParser(BaseParser):
"""
This will look at the current Python environment and list out all installed packages.

Best used when you have virtual Python environments per project.
"""

def __init__(self, use_purl_bom_ref: bool = False) -> None:
def __init__(self, use_purl_bom_ref: bool = False, licence_output_format: str = 'expression') -> None:
Copy link
Member

Choose a reason for hiding this comment

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

  • licence_output_format is supposed to be not an arbitrary string, but of the type the new enum is.
  • the default value should be derived from that enum
  • type: licence_output_format -> license_output_format

from cyclonedx.model.component import Component
from cyclonedx.parser import BaseParser


@enum.unique
class LICENSE_OUTPUT_FORMAT(enum.Enum):
Copy link
Member

Choose a reason for hiding this comment

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

this is an enum, not a constant. user proper casing ala pep8 - https://peps.python.org/pep-0008/#class-names

is there a pep that encourages all-upper-case for enums?

@jkowalleck
Copy link
Member

Hello @Jonas-vdb ,

Thank you for the contribution.

Some of the tests did not pass - see https://github.com/CycloneDX/cyclonedx-python/runs/8255584075?check_suite_focus=true
I merged latest master into your branch, so you should be able to run the tests locally via tox .

@jkowalleck jkowalleck changed the title Option to choose license format feat: option to choose license format Sep 8, 2022
Jonas-vdb and others added 2 commits September 9, 2022 13:43
- Filter getting Classifier headers using the get_all function
- Fix isort and pep8 issues

Signed-off-by: Jonas Van Den Bossche <jonas.van.den.bossche@awingu.com>
@Jonas-vdb
Copy link
Author

@jkowalleck Thanks for the PR review.

  • I have processed the remarks
  • Got the tox successfully running locally
  • Ran the isort and autopop8 commands

Copy link
Member

@jkowalleck jkowalleck left a comment

Choose a reason for hiding this comment

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

please see my remarks.

@enum.unique
class LicenseOutputFormat(enum.Enum):
EXPRESSION = 'expression'
LICENSE = 'license'
Copy link
Member

Choose a reason for hiding this comment

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

❌ please UpperCalecase names
❌ named license should be made clearer
❌ even though this enum will eventually affect the output(CLI result), it affects the builder/factory results - therefore rename

@enum.unique
class LicenseFormat(enum.Enum):
    Expression = 'license-expression'
    Name = 'named-license'

from cyclonedx.model.component import Component
from cyclonedx.parser import BaseParser


@enum.unique
class LicenseOutputFormat(enum.Enum):
Copy link
Member

Choose a reason for hiding this comment

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


as this is a global config in the CLI,
this class definition should be soomwhere centalized - like in parser/__init__.py

if str(cl_header).startswith('License :: OSI Approved :: '):
cl_license = str(cl_header).replace('License :: OSI Approved :: ', "").strip()
if licence_output_format == LicenseOutputFormat.EXPRESSION:
c.licenses.add(
Copy link
Member

Choose a reason for hiding this comment

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

can this we made shorter - a oneliner?

@@ -96,6 +96,9 @@ SBOM Output Configuration:
exists, it will be overwritten.
-pb, --purl-bom-ref Use a component's purl for the bom-ref value, instead
of a random UUID
--licence_output_format {expression,license}
Copy link
Member

Choose a reason for hiding this comment

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

indention seams off.
did you actually call the CLI with -h and copy-paste the new help page paragraph here?

@jkowalleck
Copy link
Member

discussed the topic with @madpah , and we think we will prefer ad different solution:
we will take the opportunity and create a factory in the https://github.com/CycloneDX/cyclonedx-python-lib
that accepts any string and will create the fitting license model from it - an expression, a named, or an SPDX one.

Therefore, this PR will stay open to contract the different solutions,
until one is picked.

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.

feat: SPDX license instead of expression
2 participants