Skip to content

Commit a187dd5

Browse files
committed
feat: ES-163 fix pr comments, update lint.yml workflow
1 parent f3a2acb commit a187dd5

File tree

11 files changed

+66
-59
lines changed

11 files changed

+66
-59
lines changed

Diff for: .github/workflows/lint.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ jobs:
3232
# List all changed Python files since the merge base.
3333
files=$(git diff --name-only "$merge_base" HEAD | grep '\.py$' || true)
3434
35+
# Filter out files that match exclude patterns from pyproject.toml
36+
# this is a temporary workaround until we fix all the lint errors
37+
filtered_files=$(echo "$files" | grep -v -E 'tests/|test_.*\.py|src/protoc_gen_swagger/|src/scanoss/api/' || true)
38+
3539
# Use the multi-line syntax for outputs.
3640
echo "files<<EOF" >> "$GITHUB_OUTPUT"
37-
echo "${files}" >> "$GITHUB_OUTPUT"
41+
echo "${filtered_files}" >> "$GITHUB_OUTPUT"
3842
echo "EOF" >> "$GITHUB_OUTPUT"
3943
40-
echo "Changed files: ${files}"
44+
echo "Changed files before filtering: ${files}"
45+
echo "Changed files after filtering: ${filtered_files}"
4146
4247
- name: Run Ruff on changed files
4348
run: |
@@ -50,3 +55,4 @@ jobs:
5055
# Pass the list of changed files to Ruff.
5156
echo "${{ steps.changed_files.outputs.files }}" | xargs ruff check
5257
fi
58+

Diff for: src/scanoss/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
THE SOFTWARE.
2323
"""
2424

25-
__version__ = '1.20.0'
25+
__version__ = '1.21.0'

Diff for: src/scanoss/api/scanning/v2/scanoss_scanning_pb2_grpc.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
22
"""Client and server classes corresponding to protobuf-defined services."""
33
import grpc
4-
import warnings
54

65
from scanoss.api.common.v2 import scanoss_common_pb2 as scanoss_dot_api_dot_common_dot_v2_dot_scanoss__common__pb2
76
from scanoss.api.scanning.v2 import scanoss_scanning_pb2 as scanoss_dot_api_dot_scanning_dot_v2_dot_scanoss__scanning__pb2

Diff for: src/scanoss/file_filters.py

+26-40
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
from pathspec import GitIgnoreSpec
3131

32-
from .scanoss_settings import ScanossSettings
3332
from .scanossbase import ScanossBase
3433

3534
# Files to skip
@@ -240,48 +239,35 @@ class FileFilters(ScanossBase):
240239
Handles both inclusion and exclusion rules based on file paths, extensions, and sizes.
241240
"""
242241

243-
def __init__(
244-
self,
245-
debug: bool = False,
246-
trace: bool = False,
247-
quiet: bool = False,
248-
scanoss_settings: 'ScanossSettings | None' = None,
249-
all_extensions: bool = False,
250-
all_folders: bool = False,
251-
hidden_files_folders: bool = False,
252-
operation_type: str = 'scanning',
253-
skip_size: int = 0,
254-
skip_extensions=None,
255-
skip_folders=None,
256-
):
242+
def __init__(self, debug: bool = False, trace: bool = False, quiet: bool = False, **kwargs):
257243
"""
258244
Initialize scan filters based on default settings. Optionally append custom settings.
259245
260246
Args:
261247
debug (bool): Enable debug output
262248
trace (bool): Enable trace output
263249
quiet (bool): Suppress output
264-
scanoss_settings (ScanossSettings): Custom settings to override defaults
265-
all_extensions (bool): Include all file extensions
266-
all_folders (bool): Include all folders
267-
hidden_files_folders (bool): Include hidden files and folders
268-
operation_type: operation type. can be either 'scanning' or 'fingerprinting'
250+
**kwargs: Additional arguments including:
251+
scanoss_settings (ScanossSettings): Custom settings to override defaults
252+
all_extensions (bool): Include all file extensions
253+
all_folders (bool): Include all folders
254+
hidden_files_folders (bool): Include hidden files and folders
255+
operation_type (str): Operation type ('scanning' or 'fingerprinting')
256+
skip_size (int): Size to skip
257+
skip_extensions (list): Extensions to skip
258+
skip_folders (list): Folders to skip
269259
"""
270260
super().__init__(debug, trace, quiet)
271261

272-
if skip_folders is None:
273-
skip_folders = []
274-
if skip_extensions is None:
275-
skip_extensions = []
276-
self.hidden_files_folders = hidden_files_folders
277-
self.scanoss_settings = scanoss_settings
278-
self.all_extensions = all_extensions
279-
self.all_folders = all_folders
280-
self.skip_folders = skip_folders
281-
self.skip_size = skip_size
282-
self.skip_extensions = skip_extensions
283-
self.file_folder_pat_spec = self._get_file_folder_pattern_spec(operation_type)
284-
self.size_pat_rules = self._get_size_limit_pattern_rules(operation_type)
262+
self.hidden_files_folders = kwargs.get('hidden_files_folders', False)
263+
self.scanoss_settings = kwargs.get('scanoss_settings')
264+
self.all_extensions = kwargs.get('all_extensions', False)
265+
self.all_folders = kwargs.get('all_folders', False)
266+
self.skip_folders = kwargs.get('skip_folders', [])
267+
self.skip_size = kwargs.get('skip_size', 0)
268+
self.skip_extensions = kwargs.get('skip_extensions', [])
269+
self.file_folder_pat_spec = self._get_file_folder_pattern_spec(kwargs.get('operation_type', 'scanning'))
270+
self.size_pat_rules = self._get_size_limit_pattern_rules(kwargs.get('operation_type', 'scanning'))
285271

286272
def get_filtered_files_from_folder(self, root: str) -> List[str]:
287273
"""
@@ -311,16 +297,16 @@ def get_filtered_files_from_folder(self, root: str) -> List[str]:
311297
return all_files
312298
# Walk the tree looking for files to process. While taking into account files/folders to skip
313299
for dirpath, dirnames, filenames in os.walk(root_path):
314-
dirpath = Path(dirpath)
315-
rel_path = dirpath.relative_to(root_path)
316-
if dirpath.is_symlink(): # TODO should we skip symlink folders?
317-
self.print_msg(f'WARNING: Found symbolic link folder: {dirpath}')
300+
dir_path = Path(dirpath)
301+
rel_path = dir_path.relative_to(root_path)
302+
if dir_path.is_symlink(): # TODO should we skip symlink folders?
303+
self.print_msg(f'WARNING: Found symbolic link folder: {dir_path}')
318304

319305
if self.should_skip_dir(str(rel_path)): # Current directory should be skipped
320306
dirnames.clear()
321307
continue
322308
for filename in filenames:
323-
file_path = dirpath / filename
309+
file_path = dir_path / filename
324310
all_files.append(str(file_path))
325311
# End os.walk loop
326312
# Now filter the files and return the reduced list
@@ -452,7 +438,7 @@ def _get_operation_size_limits(self, file_path: str = None) -> tuple:
452438
# End rules loop
453439
return min_size, max_size
454440

455-
def should_skip_dir(self, dir_rel_path: str) -> bool:
441+
def should_skip_dir(self, dir_rel_path: str) -> bool: # noqa: PLR0911
456442
"""
457443
Check if a directory should be skipped based on operation type and default rules.
458444
@@ -490,7 +476,7 @@ def should_skip_dir(self, dir_rel_path: str) -> bool:
490476
return True
491477
return False
492478

493-
def _should_skip_file(self, file_rel_path: str) -> bool:
479+
def _should_skip_file(self, file_rel_path: str) -> bool: # noqa: PLR0911
494480
"""
495481
Check if a file should be skipped based on operation type and default rules.
496482

Diff for: src/scanoss/results.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,15 @@ def _format_json_output(self) -> str:
208208
return json.dumps({'results': formatted_data, 'total': len(formatted_data)}, indent=2)
209209

210210
def _format_plain_output(self) -> str:
211+
"""Format the output data into a plain text string
212+
213+
Returns:
214+
str: The formatted output data
215+
"""
211216
if not self.data:
212-
return self.print_stderr('No results to present')
217+
msg = 'No results to present'
218+
self.print_stderr(msg)
219+
return msg
213220

214221
formatted = ''
215222
for item in self.data:

Diff for: src/scanoss/scanners/scanner_config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def create_scanner_config_from_args(args) -> ScannerConfig:
5959
debug=args.debug,
6060
trace=args.trace,
6161
quiet=args.quiet,
62-
api_key=getattr(args, 'api_key', None),
63-
url=getattr(args, 'url', None),
62+
api_key=getattr(args, 'key', None),
63+
url=getattr(args, 'api_url', None),
6464
grpc_url=getattr(args, 'grpc_url', None),
6565
post_size=getattr(args, 'post_size', DEFAULT_POST_SIZE),
6666
timeout=getattr(args, 'timeout', DEFAULT_TIMEOUT),

Diff for: src/scanoss/scanners/scanner_hfh.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,6 @@ def _format_plain_output(self) -> str:
292292
"""
293293
Format the scan output data into a plain text string
294294
"""
295-
return self.scan_results
295+
return (
296+
json.dumps(self.scan_results, indent=2) if isinstance(self.scan_results, dict) else str(self.scan_results)
297+
)

Diff for: src/scanoss/scanossgrpc.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import os
2727
import uuid
2828
from dataclasses import dataclass
29+
from enum import IntEnum
2930
from typing import Dict, Optional
3031
from urllib.parse import urlparse
3132

@@ -82,12 +83,21 @@ class ScanossGrpcError(Exception):
8283
pass
8384

8485

86+
class ScanossGrpcStatusCode(IntEnum):
87+
"""Status codes for SCANOSS gRPC responses"""
88+
89+
SUCCESS = 1
90+
SUCCESS_WITH_WARNINGS = 2
91+
FAILED_WITH_WARNINGS = 3
92+
FAILED = 4
93+
94+
8595
class ScanossGrpc(ScanossBase):
8696
"""
8797
Client for gRPC functionality
8898
"""
8999

90-
def __init__( # noqa: PLR0913
100+
def __init__( # noqa: PLR0913, PLR0915
91101
self,
92102
url: str = None,
93103
debug: bool = False,
@@ -489,13 +499,13 @@ def _check_status_response(self, status_response: StatusResponse, request_id: st
489499
return True
490500
self.print_debug(f'Checking response status (rqId: {request_id}): {status_response}')
491501
status_code: StatusCode = status_response.status
492-
if status_code > 1:
502+
if status_code > ScanossGrpcStatusCode.SUCCESS:
493503
ret_val = False # default to failed
494504
msg = 'Unsuccessful'
495-
if status_code == 2:
505+
if status_code == ScanossGrpcStatusCode.SUCCESS_WITH_WARNINGS:
496506
msg = 'Succeeded with warnings'
497507
ret_val = True # No need to fail as it succeeded with warnings
498-
elif status_code == 3:
508+
elif status_code == ScanossGrpcStatusCode.FAILED_WITH_WARNINGS:
499509
msg = 'Failed with warnings'
500510
self.print_stderr(f'{msg} (rqId: {request_id} - status: {status_code}): {status_response.message}')
501511
return ret_val

Diff for: src/scanoss/utils/abstract_presenter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def present(self, output_format: str = None, output_file: str = None):
3434
fmt = output_format or self.output_format
3535

3636
if fmt and fmt not in AVAILABLE_OUTPUT_FORMATS:
37-
raise Exception(
37+
raise ValueError(
3838
f"ERROR: Invalid output format '{fmt}'. Valid values are: {', '.join(AVAILABLE_OUTPUT_FORMATS)}"
3939
)
4040

Diff for: src/scanoss/utils/crc64.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def hexdigest(self):
7171
"""Get the current CRC value as a hexadecimal string."""
7272
return format(self.digest(), '016x')
7373

74+
@classmethod
7475
def checksum(cls, data: bytes) -> int:
7576
"""Calculate CRC64 checksum for the given data."""
7677
crc = cls()
@@ -93,6 +94,3 @@ def get_hash_buff(cls, buff: bytes) -> List[bytes]:
9394
hash_val = crc.digest()
9495

9596
return list(struct.pack('>Q', hash_val))
96-
97-
98-
print(CRC64.get_hash_buff('Hello, World!'))

Diff for: version.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
THE SOFTWARE.
2424
"""
2525

26-
import os
2726
import codecs
27+
import os
2828

2929

3030
def read(rel_path):
@@ -48,8 +48,7 @@ def get_version(rel_path):
4848
if line.startswith('__version__'):
4949
delim = '"' if '"' in line else "'"
5050
return line.split(delim)[1]
51-
else:
52-
raise RuntimeError('Unable to find version string.')
51+
raise RuntimeError('Unable to find version string.')
5352

5453

5554
"""

0 commit comments

Comments
 (0)