1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-07 00:57:22 +02:00

Fix PEP 8: E302 violation as part of boy scout principle

This commit is contained in:
Eden Refael
2024-12-03 22:28:08 +02:00
parent 58990f3a39
commit 241d1a1c63

View File

@ -239,14 +239,17 @@ parsers: List[str] = [
'zpool-status' 'zpool-status'
] ]
def _cliname_to_modname(parser_cli_name: str) -> str: def _cliname_to_modname(parser_cli_name: str) -> str:
"""Return real module name (dashes converted to underscores)""" """Return real module name (dashes converted to underscores)"""
return parser_cli_name.replace('--', '').replace('-', '_') return parser_cli_name.replace('--', '').replace('-', '_')
def _modname_to_cliname(parser_mod_name: str) -> str: def _modname_to_cliname(parser_mod_name: str) -> str:
"""Return module's cli name (underscores converted to dashes)""" """Return module's cli name (underscores converted to dashes)"""
return parser_mod_name.replace('_', '-') return parser_mod_name.replace('_', '-')
def _is_valid_parser_plugin(name: str, local_parsers_dir: str) -> bool: def _is_valid_parser_plugin(name: str, local_parsers_dir: str) -> bool:
if re.match(r'\w+\.py$', name) and os.path.isfile(os.path.join(local_parsers_dir, name)): if re.match(r'\w+\.py$', name) and os.path.isfile(os.path.join(local_parsers_dir, name)):
try: try:
@ -283,11 +286,13 @@ if os.path.isdir(local_parsers_dir):
except Exception: except Exception:
pass pass
def _parser_argument(parser_mod_name: str) -> str: def _parser_argument(parser_mod_name: str) -> str:
"""Return short name of the parser with dashes and with -- prefix""" """Return short name of the parser with dashes and with -- prefix"""
parser = _modname_to_cliname(parser_mod_name) parser = _modname_to_cliname(parser_mod_name)
return f'--{parser}' return f'--{parser}'
def get_parser(parser_mod_name: Union[str, ModuleType]) -> ModuleType: def get_parser(parser_mod_name: Union[str, ModuleType]) -> ModuleType:
""" """
Return the parser module object and check that the module is a valid Return the parser module object and check that the module is a valid
@ -327,6 +332,7 @@ def get_parser(parser_mod_name: Union[str, ModuleType]) -> ModuleType:
return jc_parser return jc_parser
def _get_parser(parser_mod_name: str) -> ModuleType: def _get_parser(parser_mod_name: str) -> ModuleType:
"""Return the parser module object""" """Return the parser module object"""
# ensure parser_mod_name is a true module name and not a cli name # ensure parser_mod_name is a true module name and not a cli name
@ -344,6 +350,7 @@ def _get_parser(parser_mod_name: str) -> ModuleType:
return mod return mod
def _parser_is_slurpable(parser: ModuleType) -> bool: def _parser_is_slurpable(parser: ModuleType) -> bool:
""" """
Returns True if this parser can use the `--slurp` command option, else False Returns True if this parser can use the `--slurp` command option, else False
@ -356,6 +363,7 @@ def _parser_is_slurpable(parser: ModuleType) -> bool:
return False return False
def _parser_is_streaming(parser: ModuleType) -> bool: def _parser_is_streaming(parser: ModuleType) -> bool:
""" """
Returns True if this is a streaming parser, else False Returns True if this is a streaming parser, else False
@ -367,6 +375,7 @@ def _parser_is_streaming(parser: ModuleType) -> bool:
return False return False
def _parser_is_hidden(parser: ModuleType) -> bool: def _parser_is_hidden(parser: ModuleType) -> bool:
""" """
Returns True if this is a hidden parser, else False Returns True if this is a hidden parser, else False
@ -378,6 +387,7 @@ def _parser_is_hidden(parser: ModuleType) -> bool:
return False return False
def _parser_is_deprecated(parser: ModuleType) -> bool: def _parser_is_deprecated(parser: ModuleType) -> bool:
""" """
Returns True if this is a deprecated parser, else False Returns True if this is a deprecated parser, else False
@ -389,6 +399,7 @@ def _parser_is_deprecated(parser: ModuleType) -> bool:
return False return False
def parse( def parse(
parser_mod_name: Union[str, ModuleType], parser_mod_name: Union[str, ModuleType],
data: Union[str, bytes, Iterable[str]], data: Union[str, bytes, Iterable[str]],
@ -498,6 +509,7 @@ def parse(
return jc_parser.parse(data, quiet=quiet, raw=raw, **kwargs) return jc_parser.parse(data, quiet=quiet, raw=raw, **kwargs)
def parser_mod_list( def parser_mod_list(
show_hidden: bool = False, show_hidden: bool = False,
show_deprecated: bool = False show_deprecated: bool = False
@ -517,6 +529,7 @@ def parser_mod_list(
return plist return plist
def plugin_parser_mod_list( def plugin_parser_mod_list(
show_hidden: bool = False, show_hidden: bool = False,
show_deprecated: bool = False show_deprecated: bool = False
@ -539,6 +552,7 @@ def plugin_parser_mod_list(
return plist return plist
def standard_parser_mod_list( def standard_parser_mod_list(
show_hidden: bool = False, show_hidden: bool = False,
show_deprecated: bool = False show_deprecated: bool = False
@ -564,6 +578,7 @@ def standard_parser_mod_list(
return plist return plist
def streaming_parser_mod_list( def streaming_parser_mod_list(
show_hidden: bool = False, show_hidden: bool = False,
show_deprecated: bool = False show_deprecated: bool = False
@ -588,6 +603,7 @@ def streaming_parser_mod_list(
return plist return plist
def slurpable_parser_mod_list( def slurpable_parser_mod_list(
show_hidden: bool = False, show_hidden: bool = False,
show_deprecated: bool = False show_deprecated: bool = False
@ -612,6 +628,7 @@ def slurpable_parser_mod_list(
return plist return plist
def parser_info( def parser_info(
parser_mod_name: Union[str, ModuleType], parser_mod_name: Union[str, ModuleType],
documentation: bool = False documentation: bool = False
@ -652,6 +669,7 @@ def parser_info(
return info_dict return info_dict
def all_parser_info( def all_parser_info(
documentation: bool = False, documentation: bool = False,
show_hidden: bool = False, show_hidden: bool = False,
@ -686,6 +704,7 @@ def all_parser_info(
return p_info_list return p_info_list
def get_help(parser_mod_name: Union[str, ModuleType]) -> None: def get_help(parser_mod_name: Union[str, ModuleType]) -> None:
""" """
Show help screen for the selected parser. Show help screen for the selected parser.