From 6b5748b5725c9693ed56a1df9658787918117a13 Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Fri, 8 Mar 2019 11:17:57 -0500 Subject: [PATCH] Another iteration on __init__.py --- Ska/engarchive/__init__.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Ska/engarchive/__init__.py b/Ska/engarchive/__init__.py index 430b5570..3b52fa94 100644 --- a/Ska/engarchive/__init__.py +++ b/Ska/engarchive/__init__.py @@ -3,12 +3,26 @@ from pkg_resources import get_distribution, DistributionNotFound try: - # Normally use the generic __name__ here, but for the dual Ska.engarchive - # and cheta install, hardwire to 'Ska.engarchive' which is the package name. - __version__ = get_distribution('Ska.engarchive').version -except DistributionNotFound: - # package is not installed - pass + _dist = get_distribution('Ska.engarchive') # hard-code only for this dual-name package + __version__ = _dist.version + assert __file__.startswith(_dist.location) + +except (AssertionError, DistributionNotFound): + try: + # get_distribution found a different package from this file, must be in source repo + from setuptools_scm import get_version + from pathlib import Path + + root = Path('..') + try: + __version__ = get_version(root=root, relative_to=__file__) + except LookupError: + __version__ = get_version(root=root / '..', relative_to=__file__) + + except Exception: + import warnings + warnings.warn('Failed to find a package version, setting to 0.0.0') + __version__ = '0.0.0' def test(*args, **kwargs):