Skip to content

Commit 4142a31

Browse files
committed
ruff fixes
1 parent c5cec57 commit 4142a31

File tree

6 files changed

+30
-27
lines changed

6 files changed

+30
-27
lines changed

cycode/cli/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typer.completion import install_callback, show_callback
1010

1111
from cycode import __version__
12-
from cycode.cli.apps import ai_remediation, auth, configure, ignore, report, scan, status, report_import
12+
from cycode.cli.apps import ai_remediation, auth, configure, ignore, report, report_import, scan, status
1313

1414
if sys.version_info >= (3, 10):
1515
from cycode.cli.apps import mcp

cycode/cli/apps/report_import/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import typer
22

3-
from cycode.cli.apps.report_import.sbom import sbom_command
43
from cycode.cli.apps.report_import.report_import_command import report_import_command
4+
from cycode.cli.apps.report_import.sbom import sbom_command
55

66
app = typer.Typer(name='import', no_args_is_help=True)
77
app.callback(short_help='Import report. You`ll need to specify which report type to import.')(report_import_command)

cycode/cli/apps/report_import/sbom/sbom_command.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pathlib import Path
2-
from typing import Annotated, Optional, List
2+
from typing import Annotated, Optional
33

44
import typer
55

@@ -32,21 +32,21 @@ def sbom_command(
3232
str, typer.Option('--vendor', '-v', help='Vendor Name.', case_sensitive=False, show_default=False)
3333
],
3434
labels: Annotated[
35-
Optional[List[str]],
35+
Optional[list[str]],
3636
typer.Option(
3737
'--label', '-l', help='Label, can be specified multiple times.', case_sensitive=False, show_default=False
3838
),
39-
] = [],
39+
] = None,
4040
owners: Annotated[
41-
Optional[List[str]],
41+
Optional[list[str]],
4242
typer.Option(
4343
'--owner',
4444
'-o',
4545
help='Email address of a user in Cycode platform, can be specified multiple times.',
4646
case_sensitive=True,
4747
show_default=False,
4848
),
49-
] = [],
49+
] = None,
5050
business_impact: Annotated[
5151
BusinessImpactOption,
5252
typer.Option(

cycode/cli/utils/get_api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
if TYPE_CHECKING:
99
import typer
1010

11+
from cycode.cyclient.import_sbom_client import ImportSbomClient
1112
from cycode.cyclient.report_client import ReportClient
1213
from cycode.cyclient.scan_client import ScanClient
13-
from cycode.cyclient.import_sbom_client import ImportSbomClient
1414

1515

1616
def _get_cycode_client(

cycode/cyclient/import_sbom_client.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import dataclasses
2-
from typing import List, Optional
32
from pathlib import Path
3+
from typing import Optional
4+
45
from requests import Response
5-
from urllib.parse import quote
66

77
from cycode.cli.cli_types import BusinessImpactOption
8-
from cycode.cli.exceptions.custom_exceptions import CycodeError, RequestHttpError
9-
from cycode.cyclient.cycode_client_base import CycodeClientBase
8+
from cycode.cli.exceptions.custom_exceptions import RequestHttpError
109
from cycode.cyclient import models
10+
from cycode.cyclient.cycode_client_base import CycodeClientBase
1111

1212

1313
@dataclasses.dataclass
1414
class ImportSbomParameters:
1515
Name: str
1616
Vendor: str
1717
BusinessImpact: BusinessImpactOption
18-
Labels: Optional[List[str]]
19-
Owners: Optional[List[str]]
18+
Labels: Optional[list[str]]
19+
Owners: Optional[list[str]]
2020

21-
def _owners_to_ids(self) -> List[str]:
21+
def _owners_to_ids(self) -> list[str]:
2222
return []
2323

2424
def to_request_form(self) -> dict:
@@ -49,18 +49,20 @@ def request_sbom_import_execution(self, params: ImportSbomParameters, file_path:
4949

5050
form_data = params.to_request_form()
5151

52-
request_args = {
53-
'url_path': self.IMPORT_SBOM_REQUEST_PATH,
54-
'data': form_data,
55-
'files': {'File': open(file_path.absolute(), 'rb')},
56-
}
52+
with open(file_path.absolute(), 'rb') as f:
53+
54+
request_args = {
55+
'url_path': self.IMPORT_SBOM_REQUEST_PATH,
56+
'data': form_data,
57+
'files': {'File': f},
58+
}
5759

58-
response = self.client.post(**request_args)
60+
response = self.client.post(**request_args)
5961

6062
if response.status_code != 201:
6163
raise RequestHttpError(response.status_code, response.text, response)
6264

63-
def get_owners_user_ids(self, owners: List[str]) -> List[str]:
65+
def get_owners_user_ids(self, owners: list[str]) -> list[str]:
6466
return [self._get_user_id_by_email(owner) for owner in owners]
6567

6668
def _get_user_id_by_email(self, email: str) -> str:

tests/cli/commands/import/test_import_sbom.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import tempfile
2-
import pytest
3-
import responses
42
from pathlib import Path
53
from typing import TYPE_CHECKING
4+
5+
import pytest
6+
import responses
67
from typer.testing import CliRunner
78

89
from cycode.cli.app import app
910
from cycode.cli.cli_types import BusinessImpactOption
1011
from cycode.cyclient.client_creator import create_import_sbom_client
1112
from cycode.cyclient.import_sbom_client import ImportSbomClient, ImportSbomParameters
12-
from tests.conftest import CLI_ENV_VARS, _CLIENT_ID, _CLIENT_SECRET
13+
from tests.conftest import _CLIENT_ID, _CLIENT_SECRET, CLI_ENV_VARS
1314
from tests.cyclient.mocked_responses import import_sbom_client as mocked_import_sbom
1415

1516
if TYPE_CHECKING:
@@ -21,7 +22,7 @@ def import_sbom_client() -> ImportSbomClient:
2122
return create_import_sbom_client(_CLIENT_ID, _CLIENT_SECRET, False)
2223

2324

24-
def _validate_called_endpoint(calls: responses.CallList, path: str, expected_count: int = 1):
25+
def _validate_called_endpoint(calls: responses.CallList, path: str, expected_count: int = 1) -> None:
2526
# Verify the import request was made
2627
import_calls = [c for c in calls if path in c.request.url]
2728
assert len(import_calls) == expected_count
@@ -149,7 +150,7 @@ def test_sbom_command_with_all_options(
149150
def test_sbom_command_file_not_exists(self, mocker: 'MockerFixture') -> None:
150151
from uuid import uuid4
151152

152-
non_existent_file = f'/tmp/{uuid4}'
153+
non_existent_file = str(uuid4())
153154

154155
args = [
155156
'import',

0 commit comments

Comments
 (0)