From 62b3464486c939ff7005f48a7d003895f32349a7 Mon Sep 17 00:00:00 2001 From: Ivan Blagoev Topolsky Date: Fri, 17 Jul 2020 01:51:57 +0200 Subject: [PATCH] .version file as default method --- src/shorah/cli.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/shorah/cli.py b/src/shorah/cli.py index 3981c4d..010d8c5 100644 --- a/src/shorah/cli.py +++ b/src/shorah/cli.py @@ -44,14 +44,18 @@ all_dirs = os.path.abspath(__file__).split(os.sep) base_dir = os.sep.join(all_dirs[:-all_dirs[::-1].index('shorah')]) - -try: - from pkg_resources import get_distribution #(get_distribution, DistributionNotFound) - __version__ = get_distribution('shorah').version -except: #DistributionNotFound: - # probably installed using Autotools - with open(os.path.join(base_dir, '.version'), 'r') as version_file: +version_fname = os.path.join(base_dir, '.version') +if os.path.exists(version_fname): + # probably installed using Autotools, e.g: bioconda package - the current recommended way + with open(version_fname, 'r') as version_file: __version__ = version_file.read() +else: + # probably installed using setup.py + from pkg_resources import (get_distribution, DistributionNotFound) + try: + __version__ = get_distribution('shorah').version + except DistributionNotFound: + print("your message", file=sys.stderr) # manipulate path to import functions parent_dir = os.path.join(base_dir, 'src')