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

Modernize setup somewhat #2422

Merged
merged 10 commits into from Jan 21, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -18,6 +18,7 @@ Changes:
line arguments (see #2489)
* removed calls to deprecated NumPy functionality (see #2949)
* cleaned the documentation, build process, and docstrings (see #2662)
* refactored and modernized setup.py (see #2422)
- obspy.core:
* read_inventory(): add "level" option to read files faster when less level
of detail is needed. currently only implemented for StationXML reading
Expand Down
8 changes: 0 additions & 8 deletions MANIFEST.in
@@ -1,11 +1,3 @@
# Unfortunately setuptools and numpy.distutils do not like each other and lot's
# of small incompatibilities are around. One manifestation of this is that the
# source code and data files included in the setup.py are included in binary
# distributions but not in source distributions...
# Therefore the MANIFEST.in files appears to be necessary.
# See http://scipy-user.10969.n7.nabble.com/SciPy-User-setuptools-messing-with-sdists-using-numpy-distutils-and-Fortran-libraries-td19023.html
# for more details.

# Include all files in top-level and obspy-top-level directories (e.g. CHANGELOG, RELEASE-VERSION, ...)
include * # seem to catch only files, so ./misc and ./debian are not catched.. good!
recursive-include obspy * # includes all files in any subdirs, so it also catches *all* subdirs
Expand Down
5 changes: 4 additions & 1 deletion obspy/conftest.py
Expand Up @@ -15,12 +15,15 @@

import obspy
from obspy.core.util import NETWORK_MODULES
from obspy.core.util.requirements import SOFT_DEPENDENCIES


OBSPY_PATH = os.path.dirname(obspy.__file__)


# Soft dependencies to include in ObsPy test report.
SOFT_DEPENDENCIES = ['cartopy', 'flake8', 'geographiclib', 'pyproj',
'shapefile']

# --- ObsPy fixtures


Expand Down
2 changes: 2 additions & 0 deletions obspy/core/tests/__init__.py
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
MODULE_NAME = "obspy.core"
2 changes: 1 addition & 1 deletion obspy/core/tests/test_util_misc.py
Expand Up @@ -80,7 +80,7 @@ def test_no_obspy_imports(self):
Check files that are used at install time for obspy imports.
"""
from obspy.core import util
files = ["libnames.py", "version.py", "requirements.py"]
files = ["version.py"]

for file_ in files:
file_ = os.path.join(os.path.dirname(util.__file__), file_)
Expand Down
78 changes: 18 additions & 60 deletions obspy/core/util/libnames.py
Expand Up @@ -8,14 +8,10 @@
GNU Lesser General Public License, Version 3
(https://www.gnu.org/copyleft/lesser.html)
"""
# NO IMPORTS FROM OBSPY OR FUTURE IN THIS FILE! (file gets used at
# installation time)
import ctypes
import importlib.machinery
from pathlib import Path
import platform
import re
import warnings
from distutils import sysconfig


def cleanse_pymodule_filename(filename):
Expand All @@ -39,43 +35,6 @@ def cleanse_pymodule_filename(filename):
return filename


def _get_lib_name(lib, add_extension_suffix):
"""
Helper function to get an architecture and Python version specific library
filename.

:type add_extension_suffix: bool
:param add_extension_suffix: NumPy distutils adds a suffix to
the filename we specify to build internally (as specified by Python
builtin `sysconfig.get_config_var("EXT_SUFFIX")`. So when loading the
file we have to add this suffix, but not during building.
"""
# our custom defined part of the extension file name
libname = "lib%s_%s_%s_py%s" % (
lib, platform.system(), platform.architecture()[0],
''.join([str(i) for i in platform.python_version_tuple()[:2]]))
libname = cleanse_pymodule_filename(libname)
# NumPy distutils adds extension suffix by itself during build (#771, #755)
if add_extension_suffix:
# append any extension suffix defined by Python for current platform
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
# in principle "EXT_SUFFIX" is what we want.
# "SO" seems to be deprecated on newer python
# but: older python seems to have empty "EXT_SUFFIX", so we fall back
if not ext_suffix:
try:
ext_suffix = sysconfig.get_config_var("SO")
except Exception as e:
msg = ("Empty 'EXT_SUFFIX' encountered while building CDLL "
"filename and fallback to 'SO' variable failed "
"(%s)." % str(e))
warnings.warn(msg)
pass
if ext_suffix:
libname = libname + ext_suffix
return libname


def _load_cdll(name):
"""
Helper function to load a shared library built during ObsPy installation
Expand All @@ -85,25 +44,24 @@ def _load_cdll(name):
:param name: Name of the library to load (e.g. 'mseed').
:rtype: :class:`ctypes.CDLL`
"""
# our custom defined part of the extension file name
libname = _get_lib_name(name, add_extension_suffix=True)
errors = []
libdir = Path(__file__).parent.parent.parent / 'lib'
libpath = (libdir / libname).resolve()
try:
cdll = ctypes.CDLL(str(libpath))
except Exception as e:
dirlisting = sorted(libpath.parent.iterdir())
dirlisting = ' \n'.join(map(str, dirlisting))
msg = ['Could not load shared library "%s"' % libname,
'Path: %s' % libpath,
'Current directory: %s' % Path().resolve(),
'ctypes error message: %s' % str(e),
'Directory listing of lib directory:',
' %s' % dirlisting,
]
msg = '\n '.join(msg)
raise ImportError(msg)
return cdll
for ext in importlib.machinery.EXTENSION_SUFFIXES:
libpath = (libdir / (name + ext)).resolve()
try:
cdll = ctypes.CDLL(str(libpath))
except Exception as e:
errors.append(f' {str(e)}')
else:
return cdll
# If we got here, then none of the attempted extensions worked.
raise ImportError('\n '.join([
f'Could not load shared library "{name}"',
*errors,
'Current directory: %s' % Path().resolve(),
'Directory listing of lib directory:',
*(f' {str(d)}' for d in sorted(libpath.parent.iterdir())),
]))


if __name__ == '__main__':
Expand Down
36 changes: 0 additions & 36 deletions obspy/core/util/requirements.py

This file was deleted.

2 changes: 2 additions & 0 deletions obspy/geodetics/tests/__init__.py
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
MODULE_NAME = "obspy.geodetics"
2 changes: 2 additions & 0 deletions obspy/imaging/tests/__init__.py
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
MODULE_NAME = "obspy.imaging"
2 changes: 2 additions & 0 deletions obspy/io/nordic/tests/__init__.py
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
MODULE_NAME = "obspy.io.nordic"
17 changes: 6 additions & 11 deletions obspy/scripts/runtests.py
Expand Up @@ -45,7 +45,6 @@
GNU Lesser General Public License, Version 3
(https://www.gnu.org/copyleft/lesser.html)
"""
import re
import sys
from pathlib import Path

Expand All @@ -54,7 +53,6 @@

import obspy
from obspy.core.util.misc import change_directory
from obspy.core.util.requirements import PYTEST_REQUIRES


# URL to upload json report
Expand All @@ -67,16 +65,13 @@ def _ensure_tests_requirements_installed():

This function is intended to help less experienced users run the tests.
"""
delimiters = (" ", "=", "<", ">", "!")
patterns = '|'.join(map(re.escape, delimiters))
msg = (f"\nNot all ObsPy's test requirements are installed. You need to "
f"install them before using obspy-runtest. Example with pip: \n"
f"\t$ pip install {' '.join(PYTEST_REQUIRES)}")
for package_req in PYTEST_REQUIRES:
# strip off any requirements, just get pkg_name
pkg_name = re.split(patterns, package_req, maxsplit=1)[0]
msg = ("\nNot all ObsPy's test requirements are installed. You need to "
"install them before using obspy-runtest. Example with pip: \n"
"\t$ pip install obspy[tests]")
dist = pkg_resources.get_distribution('obspy')
for package_req in dist.requires(['tests']):
try:
pkg_resources.get_distribution(pkg_name).version
pkg_resources.get_distribution(package_req).version
except pkg_resources.DistributionNotFound:
raise ImportError(msg)

Expand Down
2 changes: 2 additions & 0 deletions obspy/taup/tests/__init__.py
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
MODULE_NAME = "obspy.taup"
1 change: 0 additions & 1 deletion pyproject.toml
Expand Up @@ -2,7 +2,6 @@
# Minimum requirements for the build system to execute.
# see PEP518: https://www.python.org/dev/peps/pep-0518/
requires = [
'numpy>=1.6.1',
'setuptools'
]
build-backend = "setuptools.build_meta"