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

Emit results in a SBOM format #77

Closed
di opened this issue Oct 26, 2021 · 3 comments · Fixed by #109
Closed

Emit results in a SBOM format #77

di opened this issue Oct 26, 2021 · 3 comments · Fixed by #109
Labels
component:cli CLI components component:output-formats Supported output formats

Comments

@di
Copy link
Member

di commented Oct 26, 2021

Blocked on #3.

@di di added this to the Stable Release milestone Oct 26, 2021
@woodruffw woodruffw added the component:cli CLI components label Oct 28, 2021
@woodruffw
Copy link
Member

Closed #3 with CycloneDX as the choice.

@woodruffw
Copy link
Member

Using the local environment parser from CycloneDX as inspiration for the dependency source adapter we'll have to write: https://github.com/CycloneDX/cyclonedx-python-lib/blob/79538e92834e548a3f9697388a47efa3b27da678/cyclonedx/parser/environment.py

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):
        super().__init__()

        import pkg_resources

        i: pkg_resources.DistInfoDistribution
        for i in iter(pkg_resources.working_set):
            c = Component(name=i.project_name, version=i.version)

            i_metadata = self._get_metadata_for_package(i.project_name)
            if 'Author' in i_metadata.keys():
                c.set_author(author=i_metadata.get('Author'))

            if 'License' in i_metadata.keys() and i_metadata.get('License') != 'UNKNOWN':
                c.set_license(license_str=i_metadata.get('License'))

            if 'Classifier' in i_metadata.keys():
                for classifier in i_metadata.get_all('Classifier'):
                    if str(classifier).startswith('License :: OSI Approved :: '):
                        c.set_license(license_str=str(classifier).replace('License :: OSI Approved :: ', '').strip())

            self._components.append(c)

    @staticmethod
    def _get_metadata_for_package(package_name: str):
        if sys.version_info >= (3, 8, 0):
            return metadata(package_name)
        else:
            return metadata(package_name)

@woodruffw
Copy link
Member

Working on this now.

Not a blocker, but it looks like the cyclonedx module doesn't advertise its type hints. I've opened an upstream issue to track that: CycloneDX/cyclonedx-python-lib#52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:cli CLI components component:output-formats Supported output formats
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants