Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not run the code generator if PYERFA_USE_SYSTEM_LIBERFA=1 (Closes #38) #39

Merged
merged 2 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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