-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: SP-1855 Use scanoss.json as default settings file
- Loading branch information
1 parent
e96142f
commit 5dff2e2
Showing
6 changed files
with
170 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
SPDX-License-Identifier: MIT | ||
Copyright (c) 2024, SCANOSS | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import json | ||
import os | ||
import sys | ||
|
||
|
||
def print_stderr(*args, **kwargs): | ||
""" | ||
Print the given message to STDERR | ||
""" | ||
print(*args, file=sys.stderr, **kwargs) | ||
|
||
|
||
def is_valid_file(file_path: str) -> bool: | ||
"""Check if the specified file exists and is a file | ||
Args: | ||
file_path (str): The file path | ||
Returns: | ||
bool: True if valid, False otherwise | ||
""" | ||
if not os.path.exists(file_path) or not os.path.isfile(file_path): | ||
print_stderr(f'Specified file does not exist or is not a file: {file_path}') | ||
return False | ||
return True | ||
|
||
|
||
def validate_json_file(json_file_path: str) -> None: | ||
"""Validate if the specified file is indeed a valid JSON file | ||
Args: | ||
json_file_path (str): The JSON file to validate | ||
Raises: | ||
ValueError: If the JSON file is not valid | ||
""" | ||
if not json_file_path: | ||
raise ValueError('No JSON file provided to parse.') | ||
if not os.path.isfile(json_file_path): | ||
raise ValueError(f'JSON file does not exist or is not a file: {json_file_path}') | ||
try: | ||
with open(json_file_path) as f: | ||
json.load(f) | ||
except Exception as e: | ||
raise ValueError(f'Problem parsing JSON file "{json_file_path}": {e}') from e |