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

Give error when casacore is too old #195

Merged
merged 6 commits into from
Apr 16, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
language: python
matrix:
os: linux
dist: xenial
jobs:
include:
- env: TARGET=py2_casacore_v3.2
- env: TARGET=py3_casacore_v3.2
- env: TARGET=py2_casacore_master
- env: TARGET=py3_casacore_master
- env: TARGET=py2
- env: TARGET=py3
- env: TARGET=py2-kern
- env: TARGET=py3-kern
- env: TARGET=pep8
- env: TARGET=mypy
allow_failures:
- env: TARGET=py2
- env: TARGET=py3
- env: TARGET=py2-kern
- env: TARGET=py3-kern
- env: TARGET=pep8
- env: TARGET=mypy
sudo: required
services:
- docker
before_install:
Expand All @@ -25,7 +26,7 @@ script:
- .travis/script.sh
deploy:
provider: pypi
user: gijzelaerr
username: gijzelaerr
password:
secure: cdrrma3XaFjtv4lHvag6dfhSbKBF8iLmVgPQEjXP8qa+WxHnkHObkyraYAFGqThDY/0lBdrBm7Og6l1JfAcSA2BjdPQYxujP8KEoVicPwlgwEJ5LZo4HqympWVk33APvbcYNw7K/CwEXNJCCD1tDiO4pdwkPAWuKlnYUVfZq2yI=
skip_existing: true
Expand Down
2 changes: 1 addition & 1 deletion .travis/py2.docker → .travis/py2-kern.docker
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM kernsuite/base:4
FROM kernsuite/base:5
RUN docker-apt-install \
casacore-data \
casacore-dev \
Expand Down
2 changes: 1 addition & 1 deletion .travis/py3.docker → .travis/py3-kern.docker
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM kernsuite/base:4
FROM kernsuite/base:5
RUN docker-apt-install \
casacore-data \
casacore-dev \
Expand Down
1 change: 1 addition & 0 deletions .travis/py3_casacore_master.docker
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ WORKDIR /code
RUN pip3 install -e .
RUN pip3 install -r tests/requirements.txt
RUN nosetests3 --with-coverage --verbose --cover-package=casacore
RUN python3 setup.py clean
2 changes: 1 addition & 1 deletion casacore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "3.2.0"
__mincasacoreversion__ = "2.3.0"
__mincasacoreversion__ = "3.1.1"
55 changes: 40 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import warnings
from setuptools import setup, Extension, find_packages
from distutils.sysconfig import get_config_vars
from distutils.command import build_ext as build_ext_module
from distutils import ccompiler
from distutils.version import LooseVersion
import argparse
Expand Down Expand Up @@ -100,6 +101,33 @@ def find_boost():
return boostlibnames[0], '', ''


def find_casacore_version():
"""
Find the version of casacore, or None if it's not found
"""
if sys.version_info[0] == 2:
casa_python = 'casa_python'
else:
casa_python = 'casa_python3'

# Find casacore libpath
libcasacasa = find_library_file('casa_casa')

casacoreversion = None
if libcasacasa:
# Get version number from casacore
try:
libcasa = ctypes.cdll.LoadLibrary(libcasacasa)
getCasacoreVersion = libcasa.getVersion
getCasacoreVersion.restype = ctypes.c_char_p
casacoreversion = getCasacoreVersion().decode('utf-8')
except:
# getVersion was fixed in casacore 2.3.0
pass

return casacoreversion


def find_casacore():
"""
Find the name and path of casacore
Expand All @@ -120,23 +148,9 @@ def find_casacore():
libdir = ''
includedir = ''
if libcasacasa:
# Get version number from casacore
try:
libcasa = ctypes.cdll.LoadLibrary(libcasacasa)
getCasacoreVersion = libcasa.getVersion
getCasacoreVersion.restype = ctypes.c_char_p
casacoreversion = getCasacoreVersion()
except:
# getVersion was fixed in casacore 2.3.0
warnings.warn("Your casacore version is older than 2.3.0! You need to upgrade your casacore.")
tammojan marked this conversation as resolved.
Show resolved Hide resolved
else:
if LooseVersion(casacoreversion.decode()) < LooseVersion(__mincasacoreversion__):
warnings.warn("Your casacore version is too old. Minimum is " + __mincasacoreversion__)

libdir = dirname(libcasacasa)
includedir = join(dirname(libdir), "include")

if not find_library_file(casa_python):
else:
warnings.warn(no_casacore_error)

return casa_python, libdir, includedir
Expand Down Expand Up @@ -225,6 +239,16 @@ def get_extensions():
)



class my_build_ext(build_ext_module.build_ext):
def run(self):
casacoreversion = find_casacore_version()
if casacoreversion is not None and LooseVersion(casacoreversion) < LooseVersion(__mincasacoreversion__):
raise RuntimeError("Your casacore version is too old. Minimum is " + __mincasacoreversion__ +
", you have " + casacoreversion.decode('utf-8'))

build_ext_module.build_ext.run(self)

setup(name='python-casacore',
version=__version__,
description='A wrapper around CASACORE, the radio astronomy library',
Expand All @@ -237,4 +261,5 @@ def get_extensions():
long_description_content_type='text/x-rst',
packages=find_packages(),
ext_modules=get_extensions(),
cmdclass={'build_ext': my_build_ext},
license='GPL')