Skip to content

Commit 4edc219

Browse files
committed
feat: fix lint issues and tests
1 parent 4b2e026 commit 4edc219

File tree

3 files changed

+17
-27
lines changed

3 files changed

+17
-27
lines changed

src/scanoss/cli.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@
6666
from .threadeddependencies import SCOPE
6767
from .utils.file import validate_json_file
6868

69-
DEFAULT_POST_SIZE = 32
70-
DEFAULT_TIMEOUT = 180
71-
MIN_TIMEOUT_VALUE = 5
72-
DEFAULT_RETRY = 5
73-
PYTHON3_OR_LATER = 3
7469
HEADER_PARTS_COUNT = 2
7570

7671

@@ -589,9 +584,9 @@ def setup_args() -> None: # noqa: PLR0915
589584
# Global Scan/Fingerprint filter options
590585
for p in [p_scan, p_wfp]:
591586
p.add_argument('--obfuscate', action='store_true', help='Obfuscate fingerprints')
592-
p.add_argument('--all-extensions', action='store_true', help='Fingerprint all file extensions')
593-
p.add_argument('--all-folders', action='store_true', help='Fingerprint all folders')
594-
p.add_argument('--all-hidden', action='store_true', help='Fingerprint all hidden files/folders')
587+
p.add_argument('--all-extensions', action='store_true', help='Fingerprint all file extensions/types...')
588+
p.add_argument('--all-folders', action='store_true', help='Fingerprint all folders...')
589+
p.add_argument('--all-hidden', action='store_true', help='Fingerprint all hidden files/folders...')
595590
p.add_argument('--hpsm', '-H', action='store_true', help='Use High Precision Snippet Matching algorithm.')
596591
p.add_argument('--skip-snippets', '-S', action='store_true', help='Skip the generation of snippets')
597592
p.add_argument('--skip-extension', '-E', type=str, action='append', help='File Extension to skip.')
@@ -1282,7 +1277,7 @@ def get_pac_file(pac: str):
12821277
if pac == 'auto':
12831278
pac_file = pypac.get_pac() # try to determine the PAC file
12841279
elif pac.startswith('file://'):
1285-
pac_local = pac.strip('file://')
1280+
pac_local = pac[7:] # Remove 'file://' prefix (7 characters)
12861281
if not os.path.exists(pac_local):
12871282
print_stderr(f'Error: PAC file does not exist: {pac_local}.')
12881283
sys.exit(1)

src/scanoss/scanossgrpc.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@
5757
from .api.components.v2.scanoss_components_pb2_grpc import ComponentsStub
5858
from .api.cryptography.v2.scanoss_cryptography_pb2 import AlgorithmResponse
5959
from .api.cryptography.v2.scanoss_cryptography_pb2_grpc import CryptographyStub
60-
from .api.dependencies.v2.scanoss_dependencies_pb2 import (
61-
DependencyRequest,
62-
DependencyResponse,
63-
)
60+
from .api.dependencies.v2.scanoss_dependencies_pb2 import DependencyRequest
6461
from .api.dependencies.v2.scanoss_dependencies_pb2_grpc import DependenciesStub
6562
from .api.provenance.v2.scanoss_provenance_pb2 import ProvenanceResponse
6663
from .api.scanning.v2.scanoss_scanning_pb2 import HFHRequest
@@ -77,6 +74,7 @@
7774

7875
MAX_CONCURRENT_REQUESTS = 5
7976

77+
8078
class ScanossGrpcError(Exception):
8179
"""
8280
Custom exception for SCANOSS gRPC errors
@@ -139,7 +137,6 @@ def __init__( # noqa: PLR0913, PLR0915
139137
self.req_headers = req_headers
140138
self.metadata = []
141139

142-
143140
if self.api_key:
144141
self.metadata.append(('x-api-key', api_key)) # Set API key if we have one
145142
if ver_details:
@@ -528,9 +525,6 @@ def _check_status_response(self, status_response: StatusResponse, request_id: st
528525
:return: True if successful, False otherwise
529526
"""
530527

531-
SUCCEDED_WITH_WARNINGS_STATUS_CODE = 2
532-
FAILED_STATUS_CODE = 3
533-
534528
if not status_response:
535529
self.print_stderr(f'Warning: No status response supplied (rqId: {request_id}). Assuming it was ok.')
536530
return True
@@ -601,18 +595,20 @@ def get_provenance_json(self, purls: dict) -> dict:
601595

602596
def load_generic_headers(self):
603597
"""
604-
Adds custom headers from req_headers to metadata.
598+
Adds custom headers from req_headers to metadata.
605599
606-
If x-api-key is present and no URL is configured (directly or via
607-
environment), sets URL to the premium endpoint (DEFAULT_URL2).
608-
"""
600+
If x-api-key is present and no URL is configured (directly or via
601+
environment), sets URL to the premium endpoint (DEFAULT_URL2).
602+
"""
609603
if self.req_headers: # Load generic headers
610604
for key, value in self.req_headers.items():
611-
if key == 'x-api-key': # Set premium URL if x-api-key header is set
605+
if key == 'x-api-key': # Set premium URL if x-api-key header is set
612606
if not self.url and not os.environ.get('SCANOSS_GRPC_URL'):
613607
self.url = DEFAULT_URL2 # API key specific and no alternative URL, so use the default premium
614608
self.api_key = value
615609
self.metadata.append((key, value))
610+
611+
616612
#
617613
# End of ScanossGrpc Class
618614
#

tests/test_file_filters.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,15 @@ def test_get_filtered_files_from_files(self):
197197
os.path.join(self.test_dir, 'file1.js'),
198198
os.path.join(self.test_dir, 'file2.css'), # Should be skipped
199199
os.path.join(self.test_dir, 'dir1/file3.py'),
200-
os.path.join(self.test_dir, 'dir1/__pycache__/file4.py'),
200+
os.path.join(self.test_dir, 'dir1/__pycache__/file4.py'), # Should be skipped
201201
]
202202
self.create_files(files)
203203

204-
filtered_files = self.file_filters.get_filtered_files_from_files(files)
204+
filtered_files = self.file_filters.get_filtered_files_from_files(files, self.test_dir)
205205

206206
expected_files = [
207-
os.path.relpath(os.path.join(self.test_dir, 'file1.js'), os.getcwd()),
208-
os.path.relpath(os.path.join(self.test_dir, 'dir1', 'file3.py'), os.getcwd()),
209-
os.path.relpath(os.path.join(self.test_dir, 'dir1', '__pycache__', 'file4.py'), os.getcwd()),
207+
'file1.js',
208+
'dir1/file3.py',
210209
]
211210
self.assertEqual(sorted(filtered_files), sorted(expected_files))
212211

0 commit comments

Comments
 (0)