diff --git a/CHANGELOG.md b/CHANGELOG.md index efa79ec5..9932e5b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Upcoming changes... +## [1.17.3] - 2024-11-05 +### Fixed +- Fixed undeclared policy + + ## [1.17.2] - 2024-11-01 ### Fixed - Fixed parsing of dependencies in Policy Checks @@ -378,4 +383,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [1.16.0]: https://github.com/scanoss/scanoss.py/compare/v1.15.0...v1.16.0 [1.17.0]: https://github.com/scanoss/scanoss.py/compare/v1.16.0...v1.17.0 [1.17.1]: https://github.com/scanoss/scanoss.py/compare/v1.17.0...v1.17.1 -[1.17.2]: https://github.com/scanoss/scanoss.py/compare/v1.17.1...v1.17.2 \ No newline at end of file +[1.17.2]: https://github.com/scanoss/scanoss.py/compare/v1.17.1...v1.17.2 +[1.17.3]: https://github.com/scanoss/scanoss.py/compare/v1.17.2...v1.17.3 \ No newline at end of file diff --git a/src/scanoss/__init__.py b/src/scanoss/__init__.py index 6a2d87d3..bfe37a3a 100644 --- a/src/scanoss/__init__.py +++ b/src/scanoss/__init__.py @@ -22,4 +22,4 @@ THE SOFTWARE. """ -__version__ = "1.17.2" +__version__ = "1.17.3" diff --git a/src/scanoss/cli.py b/src/scanoss/cli.py index 16a3d8f0..9eadcaca 100644 --- a/src/scanoss/cli.py +++ b/src/scanoss/cli.py @@ -26,8 +26,9 @@ from pathlib import Path import sys import pypac -from scanoss.inspection.copyleft import Copyleft -from scanoss.inspection.undeclared_component import UndeclaredComponent + +from .inspection.copyleft import Copyleft +from .inspection.undeclared_component import UndeclaredComponent from .threadeddependencies import SCOPE from .scanoss_settings import ScanossSettings from .scancodedeps import ScancodeDeps diff --git a/src/scanoss/inspection/copyleft.py b/src/scanoss/inspection/copyleft.py index c99621d5..d7d6992f 100644 --- a/src/scanoss/inspection/copyleft.py +++ b/src/scanoss/inspection/copyleft.py @@ -23,7 +23,7 @@ """ import json from typing import Dict, Any -from scanoss.inspection.policy_check import PolicyCheck, PolicyStatus +from .policy_check import PolicyCheck, PolicyStatus class Copyleft(PolicyCheck): """ diff --git a/src/scanoss/inspection/policy_check.py b/src/scanoss/inspection/policy_check.py index fd9a369b..20b75f8a 100644 --- a/src/scanoss/inspection/policy_check.py +++ b/src/scanoss/inspection/policy_check.py @@ -26,8 +26,9 @@ from abc import abstractmethod from enum import Enum from typing import Callable, List, Dict, Any -from scanoss.inspection.utils.license_utils import LicenseUtil -from scanoss.scanossbase import ScanossBase +from .utils.license_utils import LicenseUtil +from ..scanossbase import ScanossBase + class PolicyStatus(Enum): """ diff --git a/src/scanoss/inspection/undeclared_component.py b/src/scanoss/inspection/undeclared_component.py index d111334f..f18ff148 100644 --- a/src/scanoss/inspection/undeclared_component.py +++ b/src/scanoss/inspection/undeclared_component.py @@ -23,7 +23,7 @@ """ import json from typing import Dict, Any -from scanoss.inspection.policy_check import PolicyCheck, PolicyStatus +from .policy_check import PolicyCheck, PolicyStatus class UndeclaredComponent(PolicyCheck): """ @@ -115,7 +115,7 @@ def _markdown(self, components: list) -> Dict[str,Any]: 'summary': self._get_summary(components), } - def _generate_sbom_file(self, components: list) -> dict[str, list[dict[str, str]]]: + def _generate_sbom_file(self, components: list) -> dict: """ Generate a list of PURLs for the SBOM file. diff --git a/src/scanoss/inspection/utils/license_utils.py b/src/scanoss/inspection/utils/license_utils.py index 9111d346..f97b2758 100644 --- a/src/scanoss/inspection/utils/license_utils.py +++ b/src/scanoss/inspection/utils/license_utils.py @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from scanoss.scanossbase import ScanossBase +from ...scanossbase import ScanossBase DEFAULT_COPYLEFT_LICENSES = { 'agpl-3.0-only', 'artistic-1.0', 'artistic-2.0', 'cc-by-sa-4.0', 'cddl-1.0', 'cddl-1.1', 'cecill-2.1', diff --git a/src/scanoss/inspection/utils/markdown_utils.py b/src/scanoss/inspection/utils/markdown_utils.py deleted file mode 100644 index e4b9e902..00000000 --- a/src/scanoss/inspection/utils/markdown_utils.py +++ /dev/null @@ -1,23 +0,0 @@ -def generate_table(headers, rows, centered_columns=None): - """ - Generate Markdown table - :param headers: List of headers - :param rows: Rows - :param centered_columns: List with centered columns - """ - COL_SEP = ' | ' - centered_column_set = set(centered_columns or []) - def create_separator(header, index): - if centered_columns is None: - return '-' - return ':-:' if index in centered_column_set else '-' - - row_separator = COL_SEP + COL_SEP.join( - create_separator(header, index) for index, header in enumerate(headers) - ) + COL_SEP - - table_rows = [COL_SEP + COL_SEP.join(headers) + COL_SEP] - table_rows.append(row_separator) - table_rows.extend(COL_SEP + COL_SEP.join(row) + COL_SEP for row in rows) - - return '\n'.join(table_rows) \ No newline at end of file diff --git a/src/scanoss/inspection/utils/result_utils.py b/src/scanoss/inspection/utils/result_utils.py deleted file mode 100644 index 4d089924..00000000 --- a/src/scanoss/inspection/utils/result_utils.py +++ /dev/null @@ -1,79 +0,0 @@ -from enum import Enum -from typing import Dict, Any - -from scanoss.inspection.utils.license_utils import license_util - - -class ComponentID(Enum): - FILE = "file" - SNIPPET = "snippet" - DEPENDENCY = "dependency" - - -def _append_component(components: Dict[str, Any], new_component: Dict[str, Any]) -> Dict[str, Any]: - """ - Append a new component to the components dictionary. - - This function creates a new entry in the components dictionary for the given component, - or updates an existing entry if the component already exists. It also processes the - licenses associated with the component. - - :param components: The existing dictionary of components - :param new_component: The new component to be added or updated - :return: The updated components dictionary - """ - component_key = f"{new_component['purl'][0]}@{new_component['version']}" - components[component_key] = { - 'purl': new_component['purl'][0], - 'version': new_component['version'], - 'licenses': {}, - 'status': new_component['status'], - } - - # Process licenses for this component - for l in new_component['licenses']: - spdxid = l['name'] - components[component_key]['licenses'][spdxid] = { - 'spdxid': spdxid, - 'copyleft': license_util.is_copyleft(spdxid), - 'url': l.get('url') - } - - return components - - -def get_components(results: Dict[str, Any]) -> list: - """ - Process the results dictionary to extract and format component information. - - This function iterates through the results dictionary, identifying components from - different sources (files, snippets, and dependencies). It consolidates this information - into a list of unique components, each with its associated licenses and other details. - - :param results: A dictionary containing the raw results of a component scan - :return: A list of dictionaries, each representing a unique component with its details - """ - components = {} - for component in results.values(): - for c in component: - if c['id'] in [ComponentID.FILE.value, ComponentID.SNIPPET.value]: - component_key = f"{c['purl'][0]}@{c['version']}" - - # Initialize or update the component entry - if component_key not in components: - components = _append_component(components, c) - - if c['id'] == ComponentID.DEPENDENCY.value: - for d in c['dependencies']: - component_key = f"{d['purl'][0]}@{d['version']}" - - if component_key not in components: - components = _append_component(components, d) - # End of for loop - # End if - # End if - results = list(components.values()) - for component in results: - component['licenses'] = list(component['licenses'].values()) - - return results diff --git a/tests/policy-inspect-test.py b/tests/policy-inspect-test.py index 3bfd897c..bd9e5cad 100644 --- a/tests/policy-inspect-test.py +++ b/tests/policy-inspect-test.py @@ -26,8 +26,8 @@ import re import unittest -from scanoss.inspection.copyleft import Copyleft -from scanoss.inspection.undeclared_component import UndeclaredComponent +from src.scanoss.inspection.copyleft import Copyleft +from src.scanoss.inspection.undeclared_component import UndeclaredComponent class MyTestCase(unittest.TestCase):