From 057a8890fcd8169704efbf768cdafde4f240b52b Mon Sep 17 00:00:00 2001 From: Jeff Hazboun Date: Thu, 16 May 2019 11:41:45 -0700 Subject: [PATCH] Shielded libstempo dependencies if only pint installed (#184) * libstempo no longer required if user has pint installed * Fixed lint import issue. * Fixed lint import issue #2. --- enterprise/pulsar.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/enterprise/pulsar.py b/enterprise/pulsar.py index 407dfecc..9c6c1664 100644 --- a/enterprise/pulsar.py +++ b/enterprise/pulsar.py @@ -20,7 +20,7 @@ try: import libstempo as t2 except ImportError: - print('ERROR: Must have libstempo package installed!') + print('Ooh, no libstempo?') t2 = None try: @@ -35,6 +35,10 @@ import astropy.units as u +if pint is None and t2 is None: + err_msg = 'Must have either PINT or libstempo timing package installed' + raise ImportError(err_msg) + def get_maxobs(timfile): """Utility function to return number of lines in tim file. @@ -450,11 +454,12 @@ def Pulsar(*args, **kwargs): drop_t2pulsar = kwargs.get('drop_t2pulsar', True) timing_package = kwargs.get('timing_package', 'tempo2') - if pint: + if pint is not None: toas = list(filter(lambda x: isinstance(x, toa.TOAs), args)) model = list(filter(lambda x: isinstance(x, TimingModel), args)) - t2pulsar = list(filter(lambda x: isinstance(x, t2.tempopulsar), args)) + if t2 is not None: + t2pulsar = list(filter(lambda x: isinstance(x, t2.tempopulsar), args)) parfile = list(filter(lambda x: isinstance(x, str) and x.split('.')[-1] == 'par', args))