Skip to content

Commit ad9b966

Browse files
Merge pull request #49 from amd/alex_pyversion
Downgrade: python3.10 -> python 3.9
2 parents 4ab0016 + 9ce6dd1 commit ad9b966

Some content is hidden

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

54 files changed

+240
-201
lines changed

nodescraper/base/inbandcollectortask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#
2525
###############################################################################
2626
import logging
27-
from typing import Generic, Optional
27+
from typing import Generic, Optional, Union
2828

2929
from nodescraper.connection.inband import InBandConnection
3030
from nodescraper.connection.inband.inband import BaseFileArtifact, CommandArtifact
@@ -49,7 +49,7 @@ def __init__(
4949
connection: InBandConnection,
5050
logger: Optional[logging.Logger] = None,
5151
system_interaction_level: SystemInteractionLevel = SystemInteractionLevel.INTERACTIVE,
52-
max_event_priority_level: EventPriority | str = EventPriority.CRITICAL,
52+
max_event_priority_level: Union[EventPriority, str] = EventPriority.CRITICAL,
5353
parent: Optional[str] = None,
5454
task_result_hooks: Optional[list[TaskResultHook]] = None,
5555
**kwargs,

nodescraper/base/regexanalyzer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#
2525
###############################################################################
2626
import re
27+
from typing import Union
2728

2829
from pydantic import BaseModel
2930

@@ -36,7 +37,7 @@
3637
class ErrorRegex(BaseModel):
3738
regex: re.Pattern
3839
message: str
39-
event_category: str | EventCategory = EventCategory.UNKNOWN
40+
event_category: Union[str, EventCategory] = EventCategory.UNKNOWN
4041
event_priority: EventPriority = EventPriority.ERROR
4142

4243

@@ -54,14 +55,15 @@ class RegexAnalyzer(DataAnalyzer[TDataModel, TAnalyzeArg]):
5455
"""Parent class for all regex based data analyzers."""
5556

5657
def _build_regex_event(
57-
self, regex_obj: ErrorRegex, match: str | list[str], source: str
58+
self, regex_obj: ErrorRegex, match: Union[str, list[str]], source: str
5859
) -> RegexEvent:
5960
"""Build a RegexEvent object from a regex match and source.
6061
6162
Args:
6263
regex_obj (ErrorRegex): regex object containing the regex pattern, message, category, and priorit
63-
match (str | list[str]): matched content from the regex
64-
source (str): descriptor for the content where the match was found
64+
match (
65+
Union[str, list[str]]): matched content from the regex
66+
source (str): descriptor for the content where the match was found
6567
6668
Returns:
6769
RegexEvent: an instance of RegexEvent containing the match details

nodescraper/cli/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,18 @@ def build_parser(
264264
model_type_map = parser_builder.build_plugin_parser()
265265
except Exception as e:
266266
print(f"Exception building arg parsers for {plugin_name}: {str(e)}") # noqa: T201
267+
continue
267268
plugin_subparser_map[plugin_name] = (plugin_subparser, model_type_map)
268269

269270
return parser, plugin_subparser_map
270271

271272

272-
def setup_logger(log_level: str = "INFO", log_path: str | None = None) -> logging.Logger:
273+
def setup_logger(log_level: str = "INFO", log_path: Optional[str] = None) -> logging.Logger:
273274
"""set up root logger when using the CLI
274275
275276
Args:
276277
log_level (str): log level to use
277-
log_path (str | None): optional path to filesystem log location
278+
log_path (Optional[str]): optional path to filesystem log location
278279
279280
Returns:
280281
logging.Logger: logger intstance

nodescraper/cli/dynamicparserbuilder.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
#
2525
###############################################################################
2626
import argparse
27-
import types
28-
from typing import Type
27+
from typing import Optional, Type
2928

3029
from pydantic import BaseModel
3130

@@ -59,7 +58,7 @@ def build_plugin_parser(self) -> dict:
5958
}
6059

6160
# skip args where generic type has been set to None
62-
if types.NoneType in type_class_map:
61+
if type(None) in type_class_map:
6362
continue
6463

6564
model_arg = self.get_model_arg(type_class_map)
@@ -75,14 +74,14 @@ def build_plugin_parser(self) -> dict:
7574
return model_type_map
7675

7776
@classmethod
78-
def get_model_arg(cls, type_class_map: dict) -> Type[BaseModel] | None:
77+
def get_model_arg(cls, type_class_map: dict) -> Optional[Type[BaseModel]]:
7978
"""Get the first type which is a pydantic model from a type class map
8079
8180
Args:
8281
type_class_map (dict): mapping of type classes
8382
8483
Returns:
85-
Type[BaseModel] | None: pydantic model type
84+
Optional[Type[BaseModel]]: pydantic model type
8685
"""
8786
return next(
8887
(
@@ -164,7 +163,7 @@ def build_model_arg_parser(self, model: type[BaseModel], required: bool) -> list
164163
type_class.type_class: type_class for type_class in attr_data.type_classes
165164
}
166165

167-
if types.NoneType in type_class_map and len(attr_data.type_classes) == 1:
166+
if type(None) in type_class_map and len(attr_data.type_classes) == 1:
168167
continue
169168

170169
self.add_argument(type_class_map, attr.replace("_", "-"), required)

nodescraper/cli/helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def parse_gen_plugin_config(
267267
sys.exit(1)
268268

269269

270-
def log_system_info(log_path: str | None, system_info: SystemInfo, logger: logging.Logger):
270+
def log_system_info(log_path: Optional[str], system_info: SystemInfo, logger: logging.Logger):
271271
"""dump system info object to json log
272272
273273
Args:
@@ -480,12 +480,12 @@ def dump_to_csv(all_rows: list, filename: str, fieldnames: list[str], logger: lo
480480
logger.info("Data written to csv file: %s", filename)
481481

482482

483-
def generate_summary(search_path: str, output_path: str | None, logger: logging.Logger):
483+
def generate_summary(search_path: str, output_path: Optional[str], logger: logging.Logger):
484484
"""Concatenate csv files into 1 summary csv file
485485
486486
Args:
487487
search_path (str): Path for previous runs
488-
output_path (str | None): Path for new summary csv file
488+
output_path (Optional[str]): Path for new summary csv file
489489
logger (logging.Logger): instance of logger
490490
"""
491491

nodescraper/cli/inputargtypes.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,21 @@
2525
###############################################################################
2626
import argparse
2727
import json
28-
import types
29-
from typing import Generic, Type
28+
from typing import Generic, Optional, Type
3029

3130
from pydantic import ValidationError
3231

3332
from nodescraper.generictypes import TModelType
3433

3534

36-
def log_path_arg(log_path: str) -> str | None:
35+
def log_path_arg(log_path: str) -> Optional[str]:
3736
"""Type function for a log path arg, allows 'none' to be specified to disable logging
3837
3938
Args:
4039
log_path (str): log path string
4140
4241
Returns:
43-
str | None: log path or None
42+
Optional[str]: log path or None
4443
"""
4544
if log_path.lower() == "none":
4645
return None
@@ -84,7 +83,7 @@ def dict_arg(str_input: str) -> dict:
8483
class ModelArgHandler(Generic[TModelType]):
8584
"""Class to handle loading json files into pydantic models"""
8685

87-
def __init__(self, model: Type[TModelType]) -> types.NoneType:
86+
def __init__(self, model: Type[TModelType]) -> None:
8887
self.model = model
8988

9089
def process_file_arg(self, file_path: str) -> TModelType:

nodescraper/configbuilder.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
###############################################################################
2626
import enum
2727
import logging
28-
import types
29-
from typing import Any, Optional, Type
28+
from typing import Any, Optional, Type, Union
3029

3130
from pydantic import BaseModel
3231

@@ -80,7 +79,7 @@ def _update_config(cls, config_key, type_data: TypeData, config: dict):
8079
type_class_map = {
8180
type_class.type_class: type_class for type_class in type_data.type_classes
8281
}
83-
if types.NoneType in type_class_map:
82+
if type(None) in type_class_map:
8483
return
8584

8685
model_arg = next(
@@ -102,7 +101,7 @@ def _update_config(cls, config_key, type_data: TypeData, config: dict):
102101
config[config_key] = cls._process_value(type_data.default)
103102

104103
@classmethod
105-
def _process_value(cls, value: Any) -> dict | str | int | float | list | None:
104+
def _process_value(cls, value: Any) -> Optional[Union[dict, str, int, float, list]]:
106105
if isinstance(value, enum.Enum):
107106
return value.name
108107

nodescraper/connection/inband/inbandmanager.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from __future__ import annotations
2727

2828
from logging import Logger
29+
from typing import Optional, Union
2930

3031
from nodescraper.enums import (
3132
EventCategory,
@@ -50,11 +51,11 @@ class InBandConnectionManager(ConnectionManager[InBandConnection, SSHConnectionP
5051
def __init__(
5152
self,
5253
system_info: SystemInfo,
53-
logger: Logger | None = None,
54-
max_event_priority_level: EventPriority | str = EventPriority.CRITICAL,
55-
parent: str | None = None,
56-
task_result_hooks: list[TaskResultHook] | None = None,
57-
connection_args: SSHConnectionParams | None = None,
54+
logger: Optional[Logger] = None,
55+
max_event_priority_level: Union[EventPriority, str] = EventPriority.CRITICAL,
56+
parent: Optional[str] = None,
57+
task_result_hooks: Optional[list[TaskResultHook]] = None,
58+
connection_args: Optional[SSHConnectionParams] = None,
5859
**kwargs,
5960
):
6061
super().__init__(

nodescraper/connection/inband/inbandremote.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
###############################################################################
2626
import os
2727
import socket
28-
from typing import Type
28+
from typing import Type, Union
2929

3030
import paramiko
3131
from paramiko.ssh_exception import (
@@ -99,14 +99,14 @@ def connect_ssh(self):
9999
def read_file(
100100
self,
101101
filename: str,
102-
encoding: str | None = "utf-8",
102+
encoding: Union[str, None] = "utf-8",
103103
strip: bool = True,
104104
) -> BaseFileArtifact:
105105
"""Read a remote file into a BaseFileArtifact.
106106
107107
Args:
108108
filename (str): Path to file on remote host
109-
encoding (str | None, optional): If None, file is read as binary. If str, decode using that encoding. Defaults to "utf-8".
109+
encoding Optional[Union[str, None]]: If None, file is read as binary. If str, decode using that encoding. Defaults to "utf-8".
110110
strip (bool): Strip whitespace for text files. Ignored for binary.
111111
112112
Returns:

nodescraper/connection/inband/sshparams.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ class SSHConnectionParams(BaseModel):
3434
"""Class which holds info for an SSH connection"""
3535

3636
model_config = ConfigDict(arbitrary_types_allowed=True)
37+
3738
hostname: Union[IPvAnyAddress, str]
3839
username: str
3940
password: Optional[SecretStr] = None
4041
pkey: Optional[PKey] = None
4142
key_filename: Optional[str] = None
42-
port: Annotated[int, Field(strict=True, gt=0, lt=65536)] = 22
43+
port: Annotated[int, Field(strict=True, gt=0, le=65535)] = 22

0 commit comments

Comments
 (0)