From 93a5a94dab50e916ed13d28b55d5ba584a288b3d Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 13 May 2021 23:52:46 +0200 Subject: [PATCH] Single-source version number --- PFERD/__init__.py | 43 ------------------------------------------- PFERD/__main__.py | 43 +++++++++++++++++++++++++++++++++++++++++++ PFERD/version.py | 1 + setup.cfg | 4 ++-- 4 files changed, 46 insertions(+), 45 deletions(-) create mode 100644 PFERD/__main__.py create mode 100644 PFERD/version.py diff --git a/PFERD/__init__.py b/PFERD/__init__.py index a16b19b..e69de29 100644 --- a/PFERD/__init__.py +++ b/PFERD/__init__.py @@ -1,43 +0,0 @@ -import argparse -import asyncio -from pathlib import Path - -from .config import Config, ConfigDumpException, ConfigLoadException -from .pferd import Pferd - - -def main() -> None: - parser = argparse.ArgumentParser() - parser.add_argument( - "--config", "-c", - type=Path, - metavar="PATH", - help="specify custom config file path", - ) - parser.add_argument( - "--dump-config", - nargs="?", - const=True, - type=Path, - metavar="PATH", - help="dump current configuration to a file and exit." - " Uses default config file path if no path is specified", - ) - args = parser.parse_args() - - try: - config_parser = Config.load_parser(args.config) - config = Config(config_parser) - except ConfigLoadException: - exit(1) - - if args.dump_config: - path = None if args.dump_config is True else args.dump_config - try: - config.dump(path) - except ConfigDumpException: - exit(1) - exit() - - pferd = Pferd(config) - asyncio.run(pferd.run()) diff --git a/PFERD/__main__.py b/PFERD/__main__.py new file mode 100644 index 0000000..a16b19b --- /dev/null +++ b/PFERD/__main__.py @@ -0,0 +1,43 @@ +import argparse +import asyncio +from pathlib import Path + +from .config import Config, ConfigDumpException, ConfigLoadException +from .pferd import Pferd + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument( + "--config", "-c", + type=Path, + metavar="PATH", + help="specify custom config file path", + ) + parser.add_argument( + "--dump-config", + nargs="?", + const=True, + type=Path, + metavar="PATH", + help="dump current configuration to a file and exit." + " Uses default config file path if no path is specified", + ) + args = parser.parse_args() + + try: + config_parser = Config.load_parser(args.config) + config = Config(config_parser) + except ConfigLoadException: + exit(1) + + if args.dump_config: + path = None if args.dump_config is True else args.dump_config + try: + config.dump(path) + except ConfigDumpException: + exit(1) + exit() + + pferd = Pferd(config) + asyncio.run(pferd.run()) diff --git a/PFERD/version.py b/PFERD/version.py new file mode 100644 index 0000000..528787c --- /dev/null +++ b/PFERD/version.py @@ -0,0 +1 @@ +__version__ = "3.0.0" diff --git a/setup.cfg b/setup.cfg index 9dcb111..f2806e2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = PFERD -version = 3.0.0 +version = attr: PFERD.version.__version__ [options] packages = PFERD @@ -12,4 +12,4 @@ install_requires = [options.entry_points] console_scripts = - pferd = PFERD:main + pferd = PFERD.__main__:main