Skip to content

Commit 6c4987e

Browse files
committed
Fixed Linting changes
1 parent 36c82df commit 6c4987e

28 files changed

Lines changed: 605 additions & 637 deletions

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ mcp-bzm-apitest = "main:main"
3333
packages = ["src", "src.common", "src.config", "src.formatters", "src.models", "src.tools"]
3434
py-modules = ["main"]
3535

36-
[tool.pycodestyle]
36+
[tool.flake8]
3737
max-line-length = 108
38+
extend-ignore = ["E203", "W503"]
39+
40+
[tool.black]
41+
line-length = 108
42+
43+
[tool.isort]
44+
profile = "black"
3845

src/common/api_client.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,77 +4,74 @@
44

55
import os
66
import platform
7-
from typing import Optional, Callable
7+
from typing import Callable, Optional
8+
89
import httpx
910

1011
from src.config.defaults import BZM_APIM_BASE_URL
1112
from src.config.token import BzmApimToken
1213
from src.config.version import __version__
1314
from src.models import BaseResult
1415

15-
16-
so = platform.system() # "Windows", "Linux", "Darwin"
16+
so = platform.system() # "Windows", "Linux", "Darwin"
1717
version = platform.version() # kernel / build version
1818
release = platform.release() # ex. "10", "5.15.0-76-generic"
1919
machine = platform.machine() # ex. "x86_64", "AMD64", "arm64"
2020

2121
ua_part = f"{so} {release}; {machine}"
2222

2323

24-
async def api_request(token: Optional[BzmApimToken], method: str, endpoint: str,
25-
result_formatter: Callable = None,
26-
result_formatter_params: Optional[dict] = None,
27-
**kwargs) -> BaseResult:
24+
async def api_request(
25+
token: Optional[BzmApimToken],
26+
method: str,
27+
endpoint: str,
28+
result_formatter: Callable = None,
29+
result_formatter_params: Optional[dict] = None,
30+
**kwargs,
31+
) -> BaseResult:
2832
"""
2933
Make an authenticated request to the BlazeMeter APIM APIs.
3034
Handles authentication errors gracefully.
3135
"""
3236
if not token:
3337
return BaseResult(
3438
error="No API token. Set BZM_API_TEST_TOKEN env var with the token or BZM_API_TEST_TOKEN_FILE "
35-
"with the file path or BZM_API_TEST_TOKEN secrets in docker catalog configuration.")
39+
"with the file path or BZM_API_TEST_TOKEN secrets in docker catalog configuration."
40+
)
3641

3742
headers = kwargs.pop("headers", {})
3843
headers["Authorization"] = f"Bearer {token}"
3944
headers["User-Agent"] = f"bzm-apitest-mcp/{__version__} ({ua_part})"
4045

41-
timeout = httpx.Timeout(
42-
connect=15.0,
43-
read=60.0,
44-
write=15.0,
45-
pool=60.0
46-
)
46+
timeout = httpx.Timeout(connect=15.0, read=60.0, write=15.0, pool=60.0)
4747

48-
async with (httpx.AsyncClient(base_url=BZM_APIM_BASE_URL, timeout=timeout) as client):
48+
async with httpx.AsyncClient(base_url=BZM_APIM_BASE_URL, timeout=timeout) as client:
4949
try:
5050
resp = await client.request(method, endpoint, headers=headers, **kwargs)
5151
resp.raise_for_status()
5252
response_dict = resp.json()
5353
result = response_dict.get("data", [])
5454
default_total = 0
55-
if not isinstance(
56-
result, list): # Generalize result always as a list
55+
if not isinstance(result, list): # Generalize result always as a list
5756
result = [result]
5857
default_total = 1
5958
elif "total" not in response_dict:
6059
default_total = len(result)
61-
final_result = result_formatter(
62-
result, result_formatter_params) if result_formatter else result
60+
final_result = result_formatter(result, result_formatter_params) if result_formatter else result
6361
return BaseResult(
6462
result=final_result,
6563
error=response_dict.get("error", None),
6664
total=response_dict.get("total", default_total),
67-
has_more=response_dict.get("total", 0) - (
68-
response_dict.get("skip", 0) + response_dict.get("limit", 0)) > 0,
69-
hint=kwargs.get("hint", [])
65+
has_more=response_dict.get("total", 0)
66+
- (response_dict.get("skip", 0) + response_dict.get("limit", 0))
67+
> 0,
68+
hint=kwargs.get("hint", []),
7069
)
7170
except httpx.HTTPStatusError as e:
7271
if e.response.status_code == 403:
7372
return BaseResult(
74-
error=e.response.json().get("error", {}).get('message', 'Invalid Credentials')
73+
error=e.response.json().get("error", {}).get("message", "Invalid Credentials")
7574
)
7675
elif e.response.status_code == 401:
77-
return BaseResult(
78-
error="Unauthorized to perform this action"
79-
)
76+
return BaseResult(error="Unauthorized to perform this action")
8077
raise

src/common/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from datetime import datetime
2-
from typing import Optional, Callable
2+
from typing import Callable, Optional
33

44

55
def get_date_time_iso(timestamp: int) -> Optional[str]:

src/config/token.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import os
2+
from functools import lru_cache
23
from pathlib import Path
34
from typing import Union
4-
from functools import lru_cache
5+
56
from dotenv import load_dotenv
67

78

89
class BzmApimTokenError(Exception):
910
"""Error when constructing or loading BzmApimToken."""
11+
1012
pass
1113

1214

1315
class BzmApimToken:
14-
__slots__ = ("token")
16+
__slots__ = "token"
1517

1618
def __init__(self, token: str):
1719
if not token or not isinstance(token, str):
@@ -30,8 +32,7 @@ def from_file(cls, path: Union[str, Path]) -> "BzmApimToken":
3032
load_dotenv(dotenv_path=p)
3133
token_val = os.getenv("BZM_API_TEST_TOKEN")
3234
except Exception as e:
33-
raise BzmApimTokenError(
34-
f"Error reading/parsing Token from {p!r}: {e}") from e
35+
raise BzmApimTokenError(f"Error reading/parsing Token from {p!r}: {e}") from e
3536

3637
return cls(token=token_val)
3738

src/config/version.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ def get_version():
1515

1616

1717
def get_executable():
18-
if getattr(sys, 'frozen', False):
18+
if getattr(sys, "frozen", False):
1919
return sys.executable
2020
else:
2121
# Go up from src/config/version.py to project root, then to main.py
22-
return os.path.join(os.path.abspath(
23-
Path(__file__).parent.parent.parent), "main.py")
22+
return os.path.join(os.path.abspath(Path(__file__).parent.parent.parent), "main.py")
2423

2524

2625
__version__ = get_version()

src/formatters/bucket.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from typing import List, Any, Optional
1+
from typing import Any, List, Optional
2+
23
from src.models.bucket import Bucket
34

45

56
def format_buckets(buckets: List[Any], params: Optional[dict] = None) -> List[Bucket]:
67
formatted_buckets = []
78
for bucket in buckets:
8-
formatted_buckets.append(
9-
Bucket(**bucket).model_dump(by_alias=False)
10-
)
9+
formatted_buckets.append(Bucket(**bucket).model_dump(by_alias=False))
1110
return formatted_buckets

src/formatters/environment.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from typing import List, Any, Optional
1+
from typing import Any, List, Optional
2+
23
from src.models.environment import Environment
34

45

56
def format_environments(environments: List[Any], params: Optional[dict] = None) -> List[Environment]:
6-
formatted_environments = []
7-
for environment in environments:
8-
formatted_environments.append(
9-
Environment(**environment).model_dump(by_alias=False)
10-
)
11-
return formatted_environments
7+
formatted_environments = []
8+
for environment in environments:
9+
formatted_environments.append(Environment(**environment).model_dump(by_alias=False))
10+
return formatted_environments

src/formatters/result.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
1-
from typing import List, Any, Optional
2-
from src.models.result import TestExecution, TestResult, BucketLevelTestResult
1+
from typing import Any, List, Optional
2+
3+
from src.models.result import BucketLevelTestResult, TestExecution, TestResult
34

45

56
def format_triggered_runs(runs: List[Any], params: Optional[dict] = None) -> List[TestExecution]:
67
formatted_runs = []
78
for run in runs:
8-
formatted_runs.append(
9-
TestExecution(**run).model_dump(by_alias=False)
10-
)
9+
formatted_runs.append(TestExecution(**run).model_dump(by_alias=False))
1110
return formatted_runs
1211

1312

1413
def format_results(results: List[Any], params: Optional[dict] = None) -> List[TestResult]:
1514
formatted_results = []
1615
for result in results:
17-
formatted_results.append(
18-
TestResult(**result).model_dump(by_alias=False)
19-
)
16+
formatted_results.append(TestResult(**result).model_dump(by_alias=False))
2017
return formatted_results
2118

2219

2320
def format_bucket_level_results(
24-
results: List[Any], params: Optional[dict] = None) -> List[BucketLevelTestResult]:
21+
results: List[Any], params: Optional[dict] = None
22+
) -> List[BucketLevelTestResult]:
2523
formatted_results = []
2624
for result in results:
27-
formatted_results.append(
28-
BucketLevelTestResult(**result).model_dump(by_alias=False)
29-
)
25+
formatted_results.append(BucketLevelTestResult(**result).model_dump(by_alias=False))
3026
return formatted_results

src/formatters/schedule.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from typing import List, Any, Optional
1+
from typing import Any, List, Optional
2+
23
from src.models.schedule import Schedule
34

45

56
def format_schedules(schedules: List[Any], params: Optional[dict] = None) -> List[Schedule]:
67
formatted_schedules = []
78
for schedule in schedules:
8-
formatted_schedules.append(
9-
Schedule(**schedule).model_dump(by_alias=False)
10-
)
9+
formatted_schedules.append(Schedule(**schedule).model_dump(by_alias=False))
1110
return formatted_schedules

src/formatters/step.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from typing import List, Any, Optional
1+
from typing import Any, List, Optional
2+
23
from src.models.step import TestStep
34

45

56
def format_steps(steps: List[Any], params: Optional[dict] = None) -> TestStep:
67
formatted_steps = []
78
for step in steps:
8-
formatted_steps.append(
9-
TestStep(**step).model_dump(by_alias=False)
10-
)
9+
formatted_steps.append(TestStep(**step).model_dump(by_alias=False))
1110
return formatted_steps

0 commit comments

Comments
 (0)