Skip to content

Commit

Permalink
Merge pull request #39 from avalentino/build-with-system-liberfa
Browse files Browse the repository at this point in the history
Do not run the code generator if PYERFA_USE_SYSTEM_LIBERFA=1 (Closes #38)
  • Loading branch information
avalentino authored Jul 7, 2020
2 parents b2f2654 + 83a512c commit a9dec94
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)):
Expand Down

0 comments on commit a9dec94

Please sign in to comment.