Skip to content

fix: SP-2339 Fix wfp command loading settings file from cwd #114

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Upcoming changes...

## [1.20.7] - 2025-04-11
### Fixed
- Fixed issue with wfp command where settings file was being loaded from the cwd instead of the scan root directory

## [1.20.6] - 2025-03-19
### Added
- Added HTTP/gRPC generic headers feature using --header flag
Expand Down Expand Up @@ -490,4 +494,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[1.20.3]: https://github.com/scanoss/scanoss.py/compare/v1.20.2...v1.20.3
[1.20.4]: https://github.com/scanoss/scanoss.py/compare/v1.20.3...v1.20.4
[1.20.5]: https://github.com/scanoss/scanoss.py/compare/v1.20.4...v1.20.5
[1.20.6]: https://github.com/scanoss/scanoss.py/compare/v1.20.5...v1.20.6
[1.20.6]: https://github.com/scanoss/scanoss.py/compare/v1.20.5...v1.20.6
[1.20.7]: https://github.com/scanoss/scanoss.py/compare/v1.20.6...v1.20.7
2 changes: 1 addition & 1 deletion src/scanoss/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
THE SOFTWARE.
"""

__version__ = '1.20.6'
__version__ = '1.20.7'
6 changes: 3 additions & 3 deletions src/scanoss/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import os
import sys
from pathlib import Path
from typing import List

import pypac
from typing import List

from . import __version__
from .components import Components
Expand Down Expand Up @@ -691,7 +691,7 @@ def wfp(parser, args):
if not args.skip_settings_file:
scan_settings = ScanossSettings(debug=args.debug, trace=args.trace, quiet=args.quiet)
try:
scan_settings.load_json_file(args.settings)
scan_settings.load_json_file(args.settings, args.scan_dir)
except ScanossSettingsError as e:
print_stderr(f'Error: {e}')
sys.exit(1)
Expand Down Expand Up @@ -1204,7 +1204,7 @@ def get_pac_file(pac: str):
if pac == 'auto':
pac_file = pypac.get_pac() # try to determine the PAC file
elif pac.startswith('file://'):
pac_local = pac.strip('file://')
pac_local = pac[7:] # Remove 'file://' prefix
if not os.path.exists(pac_local):
print_stderr(f'Error: PAC file does not exist: {pac_local}.')
sys.exit(1)
Expand Down
15 changes: 10 additions & 5 deletions src/scanoss/scanoss_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@

import json
from pathlib import Path
from typing import List, TypedDict
from typing import List, Optional, TypedDict

import importlib_resources
from jsonschema import validate

from .scanossbase import ScanossBase
from .utils.file import JSON_ERROR_FILE_NOT_FOUND, JSON_ERROR_FILE_EMPTY, validate_json_file
from .utils.file import (
JSON_ERROR_FILE_EMPTY,
JSON_ERROR_FILE_NOT_FOUND,
validate_json_file,
)

DEFAULT_SCANOSS_JSON_FILE = Path('scanoss.json')

Expand Down Expand Up @@ -96,12 +100,13 @@ def __init__(
if filepath:
self.load_json_file(filepath)

def load_json_file(self, filepath: 'str | None' = None, scan_root: 'str | None' = None) -> 'ScanossSettings':
def load_json_file(self, filepath: Optional[str] = None, scan_root: Optional[str] = None) -> 'ScanossSettings':
"""
Load the scan settings file. If no filepath is provided, scanoss.json will be used as default.

Args:
filepath (str): Path to the SCANOSS settings file
scan_root (str): Path to the scan root directory
"""

if not filepath:
Expand All @@ -118,7 +123,7 @@ def load_json_file(self, filepath: 'str | None' = None, scan_root: 'str | None'

result = validate_json_file(json_file)
if not result.is_valid:
if result.error_code == JSON_ERROR_FILE_NOT_FOUND or result.error_code == JSON_ERROR_FILE_EMPTY:
if result.error_code in (JSON_ERROR_FILE_NOT_FOUND, JSON_ERROR_FILE_EMPTY):
self.print_msg(
f'WARNING: The supplied settings file "{filepath}" was not found or is empty. Skipping...'
)
Expand Down Expand Up @@ -235,7 +240,7 @@ def _get_sbom_assets(self):
include_bom_entries = self._remove_duplicates(self.normalize_bom_entries(self.get_bom_include()))
replace_bom_entries = self._remove_duplicates(self.normalize_bom_entries(self.get_bom_replace()))
self.print_debug(
f"Scan type set to 'identify'. Adding {len(include_bom_entries) + len(replace_bom_entries)} components as context to the scan. \n"
f"Scan type set to 'identify'. Adding {len(include_bom_entries) + len(replace_bom_entries)} components as context to the scan. \n" # noqa: E501
f'From Include list: {[entry["purl"] for entry in include_bom_entries]} \n'
f'From Replace list: {[entry["purl"] for entry in replace_bom_entries]} \n'
)
Expand Down