From: Vasek Sraier Date: Thu, 9 Jun 2022 21:21:41 +0000 (+0200) Subject: manager: explicitely crash on old Python versions X-Git-Tag: v6.0.0a1~29^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=81666c03ba8dc69e1e19ac57fa3702aac79beea5;p=thirdparty%2Fknot-resolver.git manager: explicitely crash on old Python versions --- diff --git a/manager/knot_resolver_manager/__main__.py b/manager/knot_resolver_manager/__main__.py index d1ed6f260..33151e962 100644 --- a/manager/knot_resolver_manager/__main__.py +++ b/manager/knot_resolver_manager/__main__.py @@ -1,38 +1,5 @@ -import argparse -import sys -from pathlib import Path +# throws nice syntax error on old Python versions: +0_0 # Python >= 3.6 required -from knot_resolver_manager import compat -from knot_resolver_manager.constants import DEFAULT_MANAGER_CONFIG_FILE -from knot_resolver_manager.log import logger_startup -from knot_resolver_manager.server import start_server - - -def parse_args() -> argparse.Namespace: - parser = argparse.ArgumentParser(description="Knot Resolver - caching DNS resolver") - parser.add_argument( - "-c", - "--config", - help="Config file to load. Overrides default config location at '" + str(DEFAULT_MANAGER_CONFIG_FILE) + "'", - type=str, - nargs=1, - required=False, - default=None, - ) - return parser.parse_args() - - -def main(args: argparse.Namespace) -> int: - # where to look for config - config_path = DEFAULT_MANAGER_CONFIG_FILE if args.config is None else Path(args.config[0]) - - exit_code = compat.asyncio.run(start_server(config=config_path)) - sys.exit(exit_code) - - -if __name__ == "__main__": - # initial logging is to memory until we read the config - logger_startup() - - # run the main - main(parse_args()) +from knot_resolver_manager import main +main.main() diff --git a/manager/knot_resolver_manager/main.py b/manager/knot_resolver_manager/main.py new file mode 100644 index 000000000..362c6bbaa --- /dev/null +++ b/manager/knot_resolver_manager/main.py @@ -0,0 +1,41 @@ +""" +Effectively the same as normal __main__.py. However, we moved it's content over to this +file to allow us to exclude the __main__.py file from black's autoformatting +""" + +import argparse +import sys +from pathlib import Path + +from knot_resolver_manager import compat +from knot_resolver_manager.constants import DEFAULT_MANAGER_CONFIG_FILE +from knot_resolver_manager.log import logger_startup +from knot_resolver_manager.server import start_server + + +def parse_args() -> argparse.Namespace: + parser = argparse.ArgumentParser(description="Knot Resolver - caching DNS resolver") + parser.add_argument( + "-c", + "--config", + help="Config file to load. Overrides default config location at '" + str(DEFAULT_MANAGER_CONFIG_FILE) + "'", + type=str, + nargs=1, + required=False, + default=None, + ) + return parser.parse_args() + + +def main() -> None: + # initial logging is to memory until we read the config + logger_startup() + + # parse arguments + args = parse_args() + + # where to look for config + config_path = DEFAULT_MANAGER_CONFIG_FILE if args.config is None else Path(args.config[0]) + + exit_code = compat.asyncio.run(start_server(config=config_path)) + sys.exit(exit_code) diff --git a/manager/pyproject.toml b/manager/pyproject.toml index 373c88c96..a6755f434 100644 --- a/manager/pyproject.toml +++ b/manager/pyproject.toml @@ -82,6 +82,7 @@ target_version = ['py38'] include = '\.py$' exclude = ''' ^/setup.py # Poetry generates it and we want to keep it unchanged +knot_resolver_manager/__main__.py # due to pretty syntax error blocking old versions of python ''' [tool.isort] @@ -93,6 +94,7 @@ float_to_top=true profile = "black" skip = [ "setup.py", # Poetry generates it and we want to keep it unchanged + "knot_resolver_manager/__main__.py", ] [tool.tox]