Skip to content

Commit 96d942d

Browse files
authored
fix(deps): pin kubernetes!=36.0.0 due to broken bearer-token auth (#2731)
* Pin kubernetes!=36.0.0 due to broken bearer-token auth kubernetes v36.0.0 has a regression where auth_settings() no longer recognizes the 'authorization' key in api_key, silently dropping the Authorization header from all API requests. The upstream fix (PR #2585) is merged but not yet released. Exclude 36.0.0 until a patched v36.x ships. Ref: kubernetes-client/python#2582 * Fix mcp_server tests for mcp>=1.27 The mcp library changed @mcp.tool to return the original function directly instead of a wrapper with .fn attribute. Remove .fn access to match the upgraded mcp version. * Update ruff and mypy versions, fix formatting Multiple manifest classes have blank lines added after method signatures, ruff v0.15.14 and mypy v2.1.0 are pinned in pre-commit config, and test code is refactored for improved type hints and linting compliance with noqa annotations added where appropriate. * Fix import ordering and type hint modernization Apply ruff formatting rules including import sorting with isort, PEP 585 style type hints (list instead of List, dict instead of Dict), and remove redundant exception handlers. Replace IOError with OSError for Python 3.3+ compatibility, consolidate nested context managers, and update string formatting to use f-strings with !s and !r conversion flags. Add ruff lint ignore list to pyproject.toml.
1 parent 7ffb53f commit 96d942d

285 files changed

Lines changed: 2014 additions & 1392 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ repos:
4545
]
4646

4747
- repo: https://github.com/astral-sh/ruff-pre-commit
48-
rev: v0.14.2
48+
rev: v0.15.14
4949
hooks:
5050
- id: ruff
5151
- id: ruff-format
@@ -56,7 +56,7 @@ repos:
5656
- id: gitleaks
5757

5858
- repo: https://github.com/pre-commit/mirrors-mypy
59-
rev: v1.20.2
59+
rev: v2.1.0
6060
hooks:
6161
- id: mypy
6262
exclude: ^(tests/|examples/|docs/)

class_generator/cli.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
"""Command-line interface for the class generator."""
22

33
import fnmatch
4+
import logging
45
import shutil
56
import sys
67
from datetime import datetime
78
from pathlib import Path
89
from typing import Any
910

10-
import logging
11-
1211
import cloup
1312
from cloup.constraints import If, IsSet, accept_none, require_one
1413
from simple_logger.logger import get_logger
@@ -17,7 +16,7 @@
1716
from class_generator.core.coverage import analyze_coverage, generate_report
1817
from class_generator.core.discovery import discover_generated_resources
1918
from class_generator.core.generator import class_generator
20-
from class_generator.core.schema import update_kind_schema, ClusterVersionError
19+
from class_generator.core.schema import ClusterVersionError, update_kind_schema
2120
from class_generator.tests.test_generation import generate_class_generator_tests
2221
from class_generator.utils import execute_parallel_tasks
2322
from ocp_resources.utils.utils import convert_camel_case_to_snake_case
@@ -57,7 +56,7 @@ def handle_schema_update(update_schema: bool, generate_missing: bool) -> bool:
5756
LOGGER.info("Updating resource schema...")
5857
try:
5958
update_kind_schema()
60-
except (RuntimeError, IOError, ClusterVersionError) as e:
59+
except (OSError, RuntimeError, ClusterVersionError) as e:
6160
LOGGER.exception(f"Failed to update schema: {e}")
6261
sys.exit(1)
6362

class_generator/core/discovery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Discovery functions for finding cluster resources and generated files."""
22

3+
from concurrent.futures import Future, ThreadPoolExecutor, as_completed
34
from pathlib import Path
45
from typing import Any
5-
from concurrent.futures import ThreadPoolExecutor, as_completed, Future
66

77
from kubernetes.dynamic import DynamicClient
88
from simple_logger.logger import get_logger

class_generator/core/generator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def class_generator(
155155
LOGGER.info("Updating schema")
156156
try:
157157
update_kind_schema()
158-
except (RuntimeError, IOError) as e:
158+
except (OSError, RuntimeError) as e:
159159
error_msg = f"Failed to update schema: {e}"
160160
LOGGER.error(error_msg)
161161
raise RuntimeError(error_msg) from e
@@ -188,7 +188,7 @@ def class_generator(
188188
unique_groups = set()
189189
for resource in resources:
190190
# Use the original group name that we stored
191-
if "original_group" in resource and resource["original_group"]:
191+
if resource.get("original_group"):
192192
unique_groups.add(resource["original_group"])
193193

194194
use_output_file_suffix: bool = len(unique_groups) > 1

class_generator/core/schema.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from simple_logger.logger import get_logger
1313

1414
from class_generator.constants import DEFINITIONS_FILE, RESOURCES_MAPPING_FILE, SCHEMA_DIR
15-
from class_generator.utils import execute_parallel_with_mapping, execute_parallel_tasks
15+
from class_generator.utils import execute_parallel_tasks, execute_parallel_with_mapping
1616
from ocp_resources.utils.archive_utils import save_json_archive
1717
from ocp_resources.utils.schema_validator import SchemaValidator
1818

@@ -22,8 +22,6 @@
2222
class ClusterVersionError(Exception):
2323
"""Raised when there are issues with cluster version operations."""
2424

25-
pass
26-
2725

2826
def get_client_binary() -> str:
2927
"""Determine whether to use 'oc' or 'kubectl' binary."""
@@ -138,7 +136,7 @@ def check_and_update_cluster_version(client: str) -> bool:
138136
try:
139137
with open(cluster_version_file, "r") as fd:
140138
last_cluster_version_generated = fd.read().strip()
141-
except (FileNotFoundError, IOError):
139+
except (OSError, FileNotFoundError):
142140
# Treat missing file as first run - use baseline version that allows updates
143141
last_cluster_version_generated = "v0.0.0"
144142
LOGGER.info("Cluster version file not found - treating as first run with baseline version v0.0.0")
@@ -1360,10 +1358,10 @@ def write_schema_files(
13601358
# Ensure schema directory exists
13611359
try:
13621360
Path(SCHEMA_DIR).mkdir(parents=True, exist_ok=True)
1363-
except (OSError, IOError) as e:
1361+
except OSError as e:
13641362
error_msg = f"Failed to create schema directory {SCHEMA_DIR}: {e}"
13651363
LOGGER.error(error_msg)
1366-
raise IOError(error_msg) from e
1364+
raise OSError(error_msg) from e
13671365

13681366
# Fetch missing core definitions if schemas are available
13691367
if schemas:
@@ -1400,18 +1398,18 @@ def write_schema_files(
14001398
with open(definitions_file, "w") as fd:
14011399
json.dump(definitions_data, fd, indent=2, sort_keys=True)
14021400
LOGGER.info(f"Written {len(definitions)} definitions to {definitions_file}")
1403-
except (OSError, IOError, TypeError) as e:
1401+
except (OSError, TypeError) as e:
14041402
error_msg = f"Failed to write definitions file {definitions_file}: {e}"
14051403
LOGGER.error(error_msg)
1406-
raise IOError(error_msg) from e
1404+
raise OSError(error_msg) from e
14071405

14081406
# Write and archive resources mapping
14091407
try:
14101408
save_json_archive(resources_mapping, RESOURCES_MAPPING_FILE)
1411-
except (OSError, IOError, TypeError) as e:
1409+
except (OSError, TypeError) as e:
14121410
error_msg = f"Failed to save and archive resources mapping file {RESOURCES_MAPPING_FILE}: {e}"
14131411
LOGGER.error(error_msg)
1414-
raise IOError(error_msg) from e
1412+
raise OSError(error_msg) from e
14151413

14161414

14171415
@dataclasses.dataclass
@@ -1527,7 +1525,7 @@ def _handle_no_schemas_case() -> None:
15271525
existing_definitions_data = json.load(fd)
15281526
definitions = existing_definitions_data.get("definitions", {})
15291527
LOGGER.info(f"Found {len(definitions)} existing definitions that will be preserved")
1530-
except (FileNotFoundError, IOError, json.JSONDecodeError):
1528+
except (OSError, FileNotFoundError, json.JSONDecodeError):
15311529
LOGGER.debug("Could not load existing definitions file. No existing definitions to preserve.")
15321530

15331531

class_generator/formatters/template_renderer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Jinja template rendering for resource generation."""
22

3-
from typing import Any
43
from pathlib import Path
4+
from typing import Any
55

66
from jinja2 import DebugUndefined, Environment, FileSystemLoader, meta
77
from simple_logger.logger import get_logger

class_generator/parsers/type_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from simple_logger.logger import get_logger
88

9-
from class_generator.constants import MISSING_DESCRIPTION_STR, SPEC_STR, DEFINITIONS_FILE
9+
from class_generator.constants import DEFINITIONS_FILE, MISSING_DESCRIPTION_STR, SPEC_STR
1010
from class_generator.utils import sanitize_python_name
1111
from ocp_resources.utils.utils import convert_camel_case_to_snake_case
1212

class_generator/parsers/user_code_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def parse_user_code_from_file(file_path: str) -> tuple[str, str]:
3939
f"Failed to decode file {file_path} with UTF-8 encoding. The file may contain invalid characters.",
4040
)
4141
except Exception as e:
42-
raise Exception(f"Unexpected error reading file {file_path}: {type(e).__name__}: {str(e)}")
42+
raise Exception(f"Unexpected error reading file {file_path}: {type(e).__name__}: {e!s}")
4343

4444
end_of_generated_code_line = " # End of generated code"
4545
user_code: str = ""

class_generator/tests/manifests/APIServer/api_server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def __init__(
7272
self.tls_security_profile = tls_security_profile
7373

7474
def to_dict(self) -> None:
75+
7576
super().to_dict()
7677

7778
if not self.kind_dict and not self.yaml_file:

class_generator/tests/manifests/ConfigMap/config_map.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(
4848
self.immutable = immutable
4949

5050
def to_dict(self) -> None:
51+
5152
super().to_dict()
5253

5354
if not self.kind_dict and not self.yaml_file:

0 commit comments

Comments
 (0)