From cc5eb516bf3f3c2a5f0b5232245fda6785e47784 Mon Sep 17 00:00:00 2001 From: Sven Sager Date: Mon, 2 Oct 2023 14:46:06 +0200 Subject: [PATCH] feat: Add python base project files These files create a callable Python package and manage the version number of the complete project in the __about__.py file only. All other parts, including Makefile, will use that version number. --- src/revpi_middleware/__about__.py | 8 ++++++++ src/revpi_middleware/__init__.py | 5 +++++ src/revpi_middleware/__main__.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 src/revpi_middleware/__about__.py create mode 100644 src/revpi_middleware/__init__.py create mode 100644 src/revpi_middleware/__main__.py diff --git a/src/revpi_middleware/__about__.py b/src/revpi_middleware/__about__.py new file mode 100644 index 0000000..a3e52d4 --- /dev/null +++ b/src/revpi_middleware/__about__.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: 2025 KUNBUS GmbH +# SPDX-License-Identifier: GPL-2.0-or-later +"""Metadata of package.""" +__author__ = "Sven Sager" +__copyright__ = "Copyright (C) 2025 KUNBUS GmbH" +__license__ = " GPL-2.0-or-later" +__version__ = "0.0.1" diff --git a/src/revpi_middleware/__init__.py b/src/revpi_middleware/__init__.py new file mode 100644 index 0000000..68e760d --- /dev/null +++ b/src/revpi_middleware/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: 2025 KUNBUS GmbH +# SPDX-License-Identifier: GPL-2.0-or-later +"""Package: revpi_middleware.""" +from .__about__ import __author__, __copyright__, __license__, __version__ diff --git a/src/revpi_middleware/__main__.py b/src/revpi_middleware/__main__.py new file mode 100644 index 0000000..7f95f45 --- /dev/null +++ b/src/revpi_middleware/__main__.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: 2025 KUNBUS GmbH +# SPDX-License-Identifier: GPL-2.0-or-later +"""Start main application of this package.""" + +# If we are running from a wheel, add the wheel to sys.path +if __package__ == "": + from os.path import dirname + from sys import path + + # __file__ is package-*.whl/package/__main__.py + # Resulting path is the name of the wheel itself + package_path = dirname(dirname(__file__)) + path.insert(0, package_path) + +if __name__ == "__main__": + import sys + + try: + # Use absolute import in the __main__ module + from revpi_middleware.main_application import main + + # Run the main application of this package + sys.exit(main()) + + except Exception as e: + sys.stderr.write(f"Can not start __main__ module: {e}\n") + sys.exit(1)