From e9894cc9fe56f7d9bd0a0ccca8f13043d812dd5a Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Fri, 22 Sep 2023 08:14:11 +0200 Subject: [PATCH] Updated version fetch method, since pyproject.toml is never present in installed distributions --- rnsh/__init__.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/rnsh/__init__.py b/rnsh/__init__.py index 7c1e6b2..a89613c 100644 --- a/rnsh/__init__.py +++ b/rnsh/__init__.py @@ -26,17 +26,26 @@ module_dir = os.path.dirname(module_abs_filename) # print(os.path.dirname(module_dir)) def _get_version(): + def pkg_res_version(): + import pkg_resources + return pkg_resources.get_distribution("rnsh").version + + def tomli_version(): + import tomli + return tomli.load(open(os.path.join(os.path.dirname(module_dir), "pyproject.toml"), "rb"))["tool"]["poetry"]["version"] + try: - try: - import tomli - return tomli.load(open(os.path.join(os.path.dirname(module_dir), "pyproject.toml"), "rb"))["tool"]["poetry"]["version"] - except: + if (os.path.isfile(os.path.join(os.path.dirname(module_dir), "pyproject.toml"))): try: - import pkg_resources - return pkg_resources.get_distribution("rnsh").version + return tomli_version() except: return "0.0.0" - + else: + try: + return pkg_res_version() + except: + return "0.0.0" + except: return "0.0.0"