diff --git a/.gitmodules b/.gitmodules index 6a20fa6..985beb7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1 @@ -[submodule "astropy_helpers"] - path = astropy_helpers - url = https://github.com/astropy/astropy-helpers.git +# This file is intentionally left empty after removing astropy-helpers diff --git a/MANIFEST.in b/MANIFEST.in index 9b9a931..90b1971 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,9 +2,9 @@ include README.rst include CHANGES.rst include LONG_DESCRIPTION.rst -include ez_setup.py -include ah_bootstrap.py include setup.cfg +include pyproject.toml +include tox.ini recursive-include hips *.pyx *.c *.pxd recursive-include docs * @@ -16,26 +16,4 @@ prune build prune docs/_build prune docs/api - -# the next few stanzas are for astropy_helpers. It's derived from the -# astropy_helpers/MANIFEST.in, but requires additional includes for the actual -# package directory and egg-info. - -include astropy_helpers/README.rst -include astropy_helpers/CHANGES.rst -include astropy_helpers/LICENSE.rst -recursive-include astropy_helpers/licenses * - -include astropy_helpers/ez_setup.py -include astropy_helpers/ah_bootstrap.py - -recursive-include astropy_helpers/astropy_helpers *.py *.pyx *.c *.h -recursive-include astropy_helpers/astropy_helpers.egg-info * -# include the sphinx stuff with "*" because there are css/html/rst/etc. -recursive-include astropy_helpers/astropy_helpers/sphinx * - -prune astropy_helpers/build -prune astropy_helpers/astropy_helpers/tests - - global-exclude *.pyc *.o diff --git a/docs/conf.py b/docs/conf.py index c6293ce..3565b6b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -29,18 +29,6 @@ import os import sys -try: - import astropy_helpers -except ImportError: - # Building from inside the docs/ directory? - if os.path.basename(os.getcwd()) == 'docs': - a_h_path = os.path.abspath(os.path.join('..', 'astropy_helpers')) - if os.path.isdir(a_h_path): - sys.path.insert(1, a_h_path) - -# Load all of the global Astropy configuration -from astropy_helpers.sphinx.conf import * - # Get configuration information from setup.cfg from configparser import ConfigParser conf = ConfigParser() @@ -50,28 +38,48 @@ # -- General configuration ---------------------------------------------------- - -del intersphinx_mapping['scipy'] -del intersphinx_mapping['h5py'] -intersphinx_mapping['astropy-healpix'] = ('https://astropy-healpix.readthedocs.io/en/latest/', None) +# Add any Sphinx extension module names here, as strings +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', + 'sphinx.ext.todo', + 'sphinx.ext.coverage', + 'sphinx.ext.inheritance_diagram', + 'sphinx.ext.viewcode', + 'sphinx.ext.mathjax', + 'sphinx.ext.napoleon', + 'sphinx_automodapi.automodapi', + 'sphinx_automodapi.smart_resolver', + 'matplotlib.sphinxext.plot_directive', +] + +# Intersphinx mappings +intersphinx_mapping = { + 'python': ('https://docs.python.org/3/', None), + 'numpy': ('https://numpy.org/doc/stable/', None), + 'astropy': ('https://docs.astropy.org/en/stable/', None), + 'astropy-healpix': ('https://astropy-healpix.readthedocs.io/en/latest/', None), +} # By default, highlight as Python 3. highlight_language = 'python3' -# If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.2' +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' -# To perform a Sphinx version check that needs to be more specific than -# major.minor, call `check_sphinx_version("x.y.z")` here. -# check_sphinx_version("1.2.1") +# The master toctree document. +master_doc = 'index' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns.append('_templates') +exclude_patterns = ['_build', '_templates'] # This is added to the end of RST files - a good place to put substitutions to # be used globally. -rst_epilog += """ +rst_epilog = """ """ # -- Project information ------------------------------------------------------ @@ -112,12 +120,8 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. To override the custom theme, set this to the # name of a builtin theme or the name of a custom theme in html_theme_path. -#html_theme = None - html_theme = "sphinx_rtd_theme" - - # Custom sidebar templates, maps document names to template names. #html_sidebars = {} diff --git a/hips/_astropy_init.py b/hips/_astropy_init.py index f9e7c9c..63b5eb9 100644 --- a/hips/_astropy_init.py +++ b/hips/_astropy_init.py @@ -111,29 +111,34 @@ def test(package=None, test_path=None, args=None, plugins=None, if not _ASTROPY_SETUP_: # noqa import os from warnings import warn - from astropy.config.configuration import ( - update_default_config, - ConfigurationDefaultMissingError, - ConfigurationDefaultMissingWarning) - - # add these here so we only need to cleanup the namespace at the end - config_dir = None - - if not os.environ.get('ASTROPY_SKIP_CONFIG_UPDATE', False): - config_dir = os.path.dirname(__file__) - config_template = os.path.join(config_dir, __package__ + ".cfg") - if os.path.isfile(config_template): - try: - update_default_config( - __package__, config_dir, version=__version__) - except TypeError as orig_error: + + # Check if we have a config file and update it if needed + # This is compatible with both older and newer astropy versions + try: + from astropy.config.configuration import update_default_config, ConfigurationDefaultMissingError, ConfigurationDefaultMissingWarning + + # add these here so we only need to cleanup the namespace at the end + config_dir = None + + if not os.environ.get('ASTROPY_SKIP_CONFIG_UPDATE', False): + config_dir = os.path.dirname(__file__) + config_template = os.path.join(config_dir, __package__ + ".cfg") + if os.path.isfile(config_template): try: - update_default_config(__package__, config_dir) - except ConfigurationDefaultMissingError as e: - wmsg = (e.args[0] + - " Cannot install default profile. If you are " - "importing from source, this is expected.") - warn(ConfigurationDefaultMissingWarning(wmsg)) - del e - except Exception: - raise orig_error + update_default_config( + __package__, config_dir, version=__version__) + except TypeError as orig_error: + try: + update_default_config(__package__, config_dir) + except ConfigurationDefaultMissingError as e: + wmsg = (e.args[0] + + " Cannot install default profile. If you are " + "importing from source, this is expected.") + warn(ConfigurationDefaultMissingWarning(wmsg)) + del e + except Exception: + raise orig_error + except ImportError: + # Newer versions of astropy might have a different configuration system + # or the update_default_config might be moved elsewhere + pass diff --git a/hips/conftest.py b/hips/conftest.py index a337c02..8c9ae60 100644 --- a/hips/conftest.py +++ b/hips/conftest.py @@ -2,7 +2,22 @@ # by importing them here in conftest.py they are discoverable by py.test # no matter how it is invoked within the source tree. -from astropy.tests.pytest_plugins import * +import os +import pytest +try: + # For astropy 4.0 and later + from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS +except ImportError: + try: + # For astropy 3.0 and later + from astropy.tests.plugins.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS + except ImportError: + # For astropy < 3.0 + try: + from astropy.tests.pytest_plugins import PYTEST_HEADER_MODULES, TESTED_VERSIONS + except ImportError: + PYTEST_HEADER_MODULES = {} + TESTED_VERSIONS = {} ## Uncomment the following line to treat all DeprecationWarnings as ## exceptions @@ -28,7 +43,5 @@ except ImportError: version = 'dev' -import os - packagename = os.path.basename(os.path.dirname(__file__)) TESTED_VERSIONS[packagename] = version diff --git a/hips/draw/tests/test_healpix.py b/hips/draw/tests/test_healpix.py index 0a16ab4..72dd44e 100644 --- a/hips/draw/tests/test_healpix.py +++ b/hips/draw/tests/test_healpix.py @@ -48,7 +48,7 @@ def test_healpix_to_hips(tmpdir, file_format): for idx, val in enumerate(desired): filename = str(tmpdir / f"Norder1/Dir0/Npix{idx}.{file_format}") - if file_format is "fits": + if file_format == "fits": data = fits.getdata(filename) data = np.rot90(data, k=-1) else: diff --git a/hips/draw/tests/test_paint.py b/hips/draw/tests/test_paint.py index dfb2db8..12f8f9f 100644 --- a/hips/draw/tests/test_paint.py +++ b/hips/draw/tests/test_paint.py @@ -2,7 +2,7 @@ import pytest from numpy.testing import assert_allclose from astropy.coordinates import SkyCoord -from astropy.tests.helper import remote_data +from ...tests.helper import remote_data from ...utils.testing import requires_hips_extra from ...utils.wcs import WCSGeometry from ...tiles import HipsSurveyProperties diff --git a/hips/draw/tests/test_ui.py b/hips/draw/tests/test_ui.py index 786f3d2..ac3465e 100644 --- a/hips/draw/tests/test_ui.py +++ b/hips/draw/tests/test_ui.py @@ -2,7 +2,7 @@ import pytest import numpy as np from numpy.testing import assert_allclose -from astropy.tests.helper import remote_data +from ...tests.helper import remote_data from ...utils.testing import make_test_wcs_geometry from ...tiles import HipsSurveyProperties from ..ui import make_sky_image diff --git a/hips/tiles/tests/test_allsky.py b/hips/tiles/tests/test_allsky.py index 908f95c..3ffedc0 100644 --- a/hips/tiles/tests/test_allsky.py +++ b/hips/tiles/tests/test_allsky.py @@ -1,7 +1,7 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst from pathlib import Path import pytest -from astropy.tests.helper import remote_data +from ...tests.helper import remote_data from numpy.testing import assert_equal, assert_allclose from ...utils.testing import get_hips_extra_file, requires_hips_extra from ..tile import HipsTileMeta diff --git a/hips/tiles/tests/test_fetch.py b/hips/tiles/tests/test_fetch.py index 2b55f4d..6fa9e98 100644 --- a/hips/tiles/tests/test_fetch.py +++ b/hips/tiles/tests/test_fetch.py @@ -1,6 +1,6 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst import pytest -from astropy.tests.helper import remote_data +from ...tests.helper import remote_data from numpy.testing import assert_allclose from ..fetch import fetch_tiles from ..survey import HipsSurveyProperties diff --git a/hips/tiles/tests/test_survey.py b/hips/tiles/tests/test_survey.py index 733ed1c..ef1d81e 100644 --- a/hips/tiles/tests/test_survey.py +++ b/hips/tiles/tests/test_survey.py @@ -2,7 +2,7 @@ import pytest from numpy.testing import assert_allclose from astropy.utils.data import get_pkg_data_filename -from astropy.tests.helper import remote_data +from ...tests.helper import remote_data from ...utils.testing import get_hips_extra_file, requires_hips_extra from ..tile import HipsTileMeta from ..survey import HipsSurveyProperties, HipsSurveyPropertiesList diff --git a/hips/tiles/tests/test_tile.py b/hips/tiles/tests/test_tile.py index 2af0472..6f6c665 100644 --- a/hips/tiles/tests/test_tile.py +++ b/hips/tiles/tests/test_tile.py @@ -1,7 +1,7 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst from pathlib import Path import pytest -from astropy.tests.helper import remote_data +from ...tests.helper import remote_data import numpy as np from numpy.testing import assert_allclose, assert_equal from ...utils.testing import get_hips_extra_file, requires_hips_extra diff --git a/hips/utils/tests/test_wcs.py b/hips/utils/tests/test_wcs.py index 26cf46f..9f9e69e 100644 --- a/hips/utils/tests/test_wcs.py +++ b/hips/utils/tests/test_wcs.py @@ -1,12 +1,12 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst -from astropy.tests.helper import remote_data +from ...tests.helper import remote_data from numpy.testing import assert_allclose from astropy.coordinates import SkyCoord from ..wcs import WCSGeometry class TestWCSGeometry: - def setup(self): + def setup_method(self): self.geometry = WCSGeometry.create( skydir=SkyCoord(0, 0, unit='deg', frame='galactic'), width=2000, height=1000, fov='3 deg', @@ -33,8 +33,8 @@ def test_celestial_frame(self): assert c.frame.name == 'icrs' assert_allclose(c.ra.deg, 359.99, atol=1e-2) assert_allclose(c.dec.deg, 0.00075, atol=1e-2) - assert_allclose(self.geometry.wcs.wcs.crpix, [1000., 500.]) - assert_allclose(self.geometry.wcs.wcs.cdelt, [-0.0015, 0.0015]) + assert_allclose(geometry.wcs.wcs.crpix, [1000., 500.]) + assert_allclose(geometry.wcs.wcs.cdelt, [-0.0015, 0.0015]) @remote_data def test_create_from_dict(self): @@ -46,5 +46,5 @@ def test_create_from_dict(self): assert c.frame.name == 'galactic' assert_allclose(c.l.deg, 184.55, atol=1e-2) assert_allclose(c.b.deg, -5.78, atol=1e-2) - assert_allclose(self.geometry.wcs.wcs.crpix, [1000., 500.]) - assert_allclose(self.geometry.wcs.wcs.cdelt, [-0.0015, 0.0015]) + assert_allclose(geometry.wcs.wcs.crpix, [1000., 500.]) + assert_allclose(geometry.wcs.wcs.cdelt, [-0.0015, 0.0015]) diff --git a/setup.cfg b/setup.cfg index 3d3c7d1..a4e2e91 100644 --- a/setup.cfg +++ b/setup.cfg @@ -13,9 +13,6 @@ norecursedirs = build docs/_build doctest_plus = enabled doctest_norecursedirs = docs/*.py -[ah_bootstrap] -auto_use = True - [pycodestyle] # E101 - mix of tabs and spaces # W191 - use of tabs @@ -40,8 +37,7 @@ license = BSD 3-Clause url = https://github.com/hipspy/hips edit_on_github = False github_project = hipspy/hips -# version should be PEP386 compatible (http://www.python.org/dev/peps/pep-0386) -version = 0.3.dev +# Using setuptools_scm for version management [entry_points] diff --git a/setup.py b/setup.py index 71b8af7..9a00e0d 100644 --- a/setup.py +++ b/setup.py @@ -3,19 +3,8 @@ import glob import os - -import ah_bootstrap -from setuptools import setup - -# A dirty hack to get around some early import/configurations ambiguities -import builtins - -builtins._ASTROPY_SETUP_ = True - -from astropy_helpers.setup_helpers import (register_commands, get_debug_option, - get_package_info) -from astropy_helpers.git_helpers import get_git_devstr -from astropy_helpers.version_helpers import generate_version_py +import sys +from setuptools import setup, find_packages, Command # Get some values from the setup.cfg from configparser import ConfigParser @@ -34,41 +23,67 @@ with open('LONG_DESCRIPTION.rst') as f: LONG_DESCRIPTION = f.read() -# Store the package name in a built-in variable so it's easy -# to get from other parts of the setup infrastructure -builtins._ASTROPY_PACKAGE_NAME_ = PACKAGENAME - -# VERSION should be PEP440 compatible (http://www.python.org/dev/peps/pep-0440) -VERSION = metadata.get('version') - -# Indicates if this version is a release version -RELEASE = 'dev' not in VERSION - -if not RELEASE: - VERSION += get_git_devstr(False) - -# Populate the dict of setup command overrides; this should be done before -# invoking any other functionality from distutils since it can potentially -# modify distutils' behavior. -cmdclassd = register_commands(PACKAGENAME, VERSION, RELEASE) - -# Freeze build information in version.py -generate_version_py(PACKAGENAME, VERSION, RELEASE, - get_debug_option(PACKAGENAME)) +# Custom commands to provide helpful messages to users +class TestCommand(Command): + description = "Run tests using pytest" + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + print(""" +Note: running tests is no longer done using 'python setup.py test', but +instead you will need to run the following command: + + tox -e test + +If you don't already have tox installed, you can install it with: + + pip install tox + +For more information, see https://docs.astropy.org +""") + sys.exit(1) + +class BuildDocsCommand(Command): + description = "Build the documentation" + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + print(""" +Note: building the documentation is no longer done using 'python setup.py build_docs', +but instead you will need to run the following command: + + tox -e build_docs + +If you don't already have tox installed, you can install it with: + + pip install tox + +For more information, see https://docs.astropy.org +""") + sys.exit(1) + +# Define custom commands +cmdclassd = { + 'test': TestCommand, + 'build_docs': BuildDocsCommand, +} # Treat everything in scripts except README* as a script to be installed scripts = [fname for fname in glob.glob(os.path.join('scripts', '*')) if not os.path.basename(fname).startswith('README')] -# Get configuration information from all of the various subpackages. -# See the docstring for setup_helpers.update_package_files for more -# details. -package_info = get_package_info() - -# Add the project-global data -package_info['package_data'].setdefault(PACKAGENAME, []) -package_info['package_data'][PACKAGENAME].append('data/*') - # Define entry points for command-line scripts entry_points = {'console_scripts': []} @@ -78,6 +93,10 @@ entry_points['console_scripts'].append('{0} = {1}'.format( entry_point[0], entry_point[1])) +# Get package data +package_data = {} +package_data[PACKAGENAME] = ['data/*'] + # Include all .c files, recursively, including those generated by # Cython, since we can not do this in MANIFEST.in with a "dynamic" # directory name. @@ -88,11 +107,8 @@ c_files.append( os.path.join( os.path.relpath(root, PACKAGENAME), filename)) -package_info['package_data'][PACKAGENAME].extend(c_files) - -# Note that requires and provides should not be included in the call to -# ``setup``, since these are now deprecated. See this link for more details: -# https://groups.google.com/forum/#!topic/astropy-dev/urYO8ckB2uM +if c_files: + package_data[PACKAGENAME].extend(c_files) install_requires = [ 'numpy>=1.11', @@ -131,7 +147,6 @@ setup( name=PACKAGENAME, - version=VERSION, description=DESCRIPTION, scripts=scripts, install_requires=install_requires, @@ -142,9 +157,11 @@ url=URL, long_description=LONG_DESCRIPTION, classifiers=classifiers, - cmdclass=cmdclassd, + packages=find_packages(), + package_data=package_data, zip_safe=False, use_2to3=False, entry_points=entry_points, - **package_info + cmdclass=cmdclassd, + use_scm_version=True, )