diff --git a/.travis.yml b/.travis.yml index a4a5ec7..693161d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,7 +40,9 @@ env: # We include liberfa-dev so we can test using a system library, # and python3-astropy to run a few tests that rely on Time. # We need venv for a test environment and pip to install pyerfa itself. - - APT_DEPENDENCIES='python3-numpy python3-venv python3-pip python3-jinja2 python3-pytest-astropy liberfa-dev python3-astropy' + # Here, we need to include python3-attr, since the version on bionic + # is too old. + - APT_DEPENDENCIES='python3-numpy python3-venv python3-pip python3-jinja2 python3-pytest-astropy liberfa-dev python3-astropy python3-attr' jobs: include: diff --git a/setup.py b/setup.py index 224641a..7f16c1f 100644 --- a/setup.py +++ b/setup.py @@ -6,10 +6,15 @@ import setuptools import subprocess from warnings import warn +from distutils.dep_util import newer LIBERFADIR = os.path.join('liberfa', 'erfa') ERFA_SRC = os.path.join(LIBERFADIR, 'src') +GEN_FILES = [ + os.path.join('erfa', 'core.py'), + os.path.join('erfa', 'ufunc.c'), +] # https://mail.python.org/pipermail/distutils-sig/2007-September/008253.html @@ -27,13 +32,26 @@ def include_dirs(self, include_dirs): def get_extensions(): - cmd = [sys.executable, 'erfa_generator.py', ERFA_SRC, '--quiet'] - subprocess.run(cmd, check=True) + gen_files_exist = all(os.path.isfile(fn) for fn in GEN_FILES) + gen_files_outdated = False + if os.path.isdir(ERFA_SRC): + # assume thet 'erfaversion.c' is updated at each release at least + src = os.path.join(ERFA_SRC, 'erfaversion.c') + gen_files_outdated = any(newer(src, fn) for fn in GEN_FILES) + elif not gen_files_exist: + raise RuntimeError( + 'Missing "liberfa" source files, unable to generate ' + '"erfa/ufunc.c" and "erfa/core.py". ' + 'Please check your source tree. ' + 'Maybe "git submodule update" could help.') + + if not gen_files_exist or gen_files_outdated: + print('Run "erfa_generator.py"') + cmd = [sys.executable, 'erfa_generator.py', ERFA_SRC, '--quiet'] + subprocess.run(cmd, check=True) sources = [os.path.join('erfa', 'ufunc.c')] - include_dirs = [] - libraries = [] if int(os.environ.get('PYERFA_USE_SYSTEM_LIBERFA', 0)):