]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
manager: explicitely crash on old Python versions
authorVasek Sraier <git@vakabus.cz>
Thu, 9 Jun 2022 21:21:41 +0000 (23:21 +0200)
committerVasek Sraier <git@vakabus.cz>
Sun, 31 Jul 2022 15:26:39 +0000 (17:26 +0200)
manager/knot_resolver_manager/__main__.py
manager/knot_resolver_manager/main.py [new file with mode: 0644]
manager/pyproject.toml

index d1ed6f26054564ec690efe885488524c3165be59..33151e9623c626db08823530f06af86f0ee9dd1d 100644 (file)
@@ -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 (file)
index 0000000..362c6bb
--- /dev/null
@@ -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)
index 373c88c96f9f755c6392981be0626f74081663a6..a6755f43428c2616c56a0408b04af2fa5316af83 100644 (file)
@@ -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]