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

Overhaul build process with setuptools_scm and written version file #197

Merged
merged 4 commits into from
Sep 20, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ nosetests.xml
.mr.developer.cfg
.project
.pydevproject

pyspectral/version.py
djhoese marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
- id: flake8
additional_dependencies: [flake8-docstrings, flake8-debugger, flake8-bugbear]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
language_version: python3
Expand Down
15 changes: 11 additions & 4 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
include pyspectral/etc/*
include pyspectral/data/e490_00a.dat
include pyspectral/data/MSG_SEVIRI_Spectral_Response_Characterisation.XLS
prune *
exclude *
graft doc
recursive-exclude doc/_build *
graft pyspectral
recursive-exclude pyspectral/data/modis *
include LICENSE.txt
include versioneer.py
include README.md
include AUTHORS.md
include CHANGELOG.md
include CHANGELOG_RSR_DATA.md
include pyspectral/version.py
global-exclude *.py[cod]
65 changes: 4 additions & 61 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
# -*- coding: utf-8 -*-
#
# Pyspectral documentation build configuration file, created by
# sphinx-quickstart on Tue Oct 15 13:31:45 2013.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
"""Sphinx documentation configuration file."""

import sys
import os
from pkg_resources import get_distribution
import sys

# PYTHONPATH = docs/source
DOC_SOURCES_DIR = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -24,62 +13,16 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(0, os.path.abspath('../pyspectral'))

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
release = get_distribution('pyspectral').version
from pyspectral import __version__ as release # noqa

# for example take major/minor
version = '.'.join(release.split('.')[:2])


class Mock(object):

"""Mock class for doc/unit testing (on Travis)"""

__all__ = []

def __init__(self, *args, **kwargs):
pass

def __call__(self, *args, **kwargs):
return Mock()

@classmethod
def __getattr__(cls, name):
if name in ('__file__', '__path__'):
return '/dev/null'
elif name[0] == name[0].upper():
mockType = type(name, (), {})
mockType.__module__ = __name__
return mockType
elif name == "inf":
return 0
else:
return Mock()


MOCK_MODULES = ['numpy', 'numpy.core',
'numpy.distutils.core', 'numpy.core.multiarray',
'dask',
'scipy', 'scipy.integrate', 'scipy.interpolate',
'scipy.interpolate.InterpolatedUnivariateSpline',
'geotiepoints', 'geotiepoints.multilinear',
'trollsift', 'trollsift.parser',
'h5py', 'tqdm', 'xlrd']

for mod_name in MOCK_MODULES:
sys.modules[mod_name] = Mock()

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# sys.path.insert(0, '/opt/lib/python2.5/site-packages')
sys.path.insert(0, os.path.abspath('../pyspectral'))


# -- General configuration -----------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down
6 changes: 6 additions & 0 deletions doc/rtd_environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ dependencies:
- sphinx
- sphinx_rtd_theme
- sphinxcontrib-apidoc
- dask
- scipy
- trollsift
- h5py
- tqdm
- xlrd
- pip:
- graphviz
- .. # relative path to the satpy project
7 changes: 4 additions & 3 deletions plot_some_band.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""Plot relative spectral responses for a list of sensors"""
"""Plot relative spectral responses for a list of sensors."""

import argparse

import matplotlib.pyplot as plt
import numpy as np

from pyspectral.rsr_reader import RelativeSpectralResponse
from pyspectral.utils import get_bandname_from_wavelength
import numpy as np

platforms = ['Himawari-8', 'GOES-16', 'Meteosat-10',
'EOS-Aqua', 'Sentinel-3A', 'Sentinel-3A',
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[build-system]
requires = ["setuptools>=60", "wheel", "setuptools_scm[toml]>=8.0"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "pyspectral/version.py"

[tool.isort]
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
profile = "black"
Expand Down
12 changes: 6 additions & 6 deletions pyspectral/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

"""Pyspectral package init."""

from pkg_resources import DistributionNotFound, get_distribution

try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
# package is not installed
pass
from pyspectral.version import version as __version__ # noqa
except ModuleNotFoundError:
raise ModuleNotFoundError(

Check warning on line 25 in pyspectral/__init__.py

View check run for this annotation

Codecov / codecov/patch

pyspectral/__init__.py#L24-L25

Added lines #L24 - L25 were not covered by tests
"No module named pyspectral.version. This could mean "
"you didn't install 'pyspectral' properly. Try reinstalling ('pip "
"install pyspectral').")
1 change: 0 additions & 1 deletion pyspectral/tests/test_rayleigh.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ def test_rayleigh_reduction(self, fake_lut_hdf5):

def test_rayleigh_getname(self):
"""Test logic for Rayleigh instrument selection."""

with pytest.raises(ValueError):
_create_rayleigh(platform='FY-4B')

Expand Down
2 changes: 1 addition & 1 deletion pyspectral/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import responses

from pyspectral import utils
from pyspectral.utils import bytes2string, check_and_adjust_instrument_name, are_instruments_identical, np2str
from pyspectral.utils import are_instruments_identical, bytes2string, check_and_adjust_instrument_name, np2str

TEST_RSR = {'20': {}, }
TEST_RSR2 = {'20': {}, }
Expand Down
3 changes: 2 additions & 1 deletion pyspectral/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ def download_luts(aerosol_types=None, dry_run=False, aerosol_type=None):

def _get_aerosol_types(aerosol_types, aerosol_type):
if aerosol_type is not None:
warnings.warn("'aerosol_type' is deprecated, use 'aerosol_types' instead.", UserWarning)
warnings.warn("'aerosol_type' is deprecated, use 'aerosol_types' instead.", UserWarning,
stacklevel=3)
if isinstance(aerosol_type, (list, tuple, set)):
aerosol_types = aerosol_type
else:
Expand Down
1 change: 0 additions & 1 deletion rsr_convert_scripts/agri_rsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def __init__(self, bandname, platform_name):
self._get_options_from_config()
self._get_bandfilenames()


LOG.debug("Filenames: %s", str(self.filenames))
if self.filenames[bandname] and os.path.exists(self.filenames[bandname]):
self.requested_band_filename = self.filenames[bandname]
Expand Down
11 changes: 6 additions & 5 deletions rsr_convert_scripts/avhrr1_rsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
Data from NOAA: AVHRR1_SRF_only.xls
"""

import logging
import os
from xlrd import open_workbook
from pyspectral.config import get_config
from pyspectral.utils import get_central_wave

import h5py
import numpy as np
import pkg_resources
import logging
import h5py
from xlrd import open_workbook

from pyspectral.config import get_config
from pyspectral.utils import get_central_wave

LOG = logging.getLogger(__name__)

Expand Down
20 changes: 11 additions & 9 deletions rsr_convert_scripts/msu_gs_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Read the Electro-L N2 MSU-GS spectral response functions.

"""Read the Electro-L N2 MSU-GS spectral response functions. Data from the NWPSAF:
Data from the NWPSAF:
https://nwp-saf.eumetsat.int/downloads/rtcoef_rttov13/ir_srf/rtcoef_electro-l_2_msugs_srf.html

"""

import logging
import os

import numpy as np
from pyspectral.utils import convert2hdf5 as tohdf5

from pyspectral.raw_reader import InstrumentRSR
import logging
from pyspectral.utils import convert2hdf5 as tohdf5

LOG = logging.getLogger(__name__)

Expand All @@ -40,12 +43,11 @@


class MsugsRSR(InstrumentRSR):
"""Container for the Electro-L N2 MSU-GS relative spectral response data"""
"""Container for the Electro-L N2 MSU-GS relative spectral response data."""

def __init__(self, bandname, platform_name):

super(MsugsRSR, self).__init__(
bandname, platform_name, MSUGS_BAND_NAMES)
"""Load files."""
super(MsugsRSR, self).__init__(bandname, platform_name, MSUGS_BAND_NAMES)

self.instrument = 'msu-gs'
self._get_options_from_config()
Expand All @@ -67,7 +69,7 @@ def __init__(self, bandname, platform_name):
self.wavespace = 'wavelength'

def _load(self, scale=10000.0):
"""Load the MSU-GS RSR data for the band requested"""
"""Load the MSU-GS RSR data for the band requested."""
data = np.genfromtxt(self.requested_band_filename,
unpack=True,
names=['wavenumber',
Expand All @@ -84,7 +86,7 @@ def _load(self, scale=10000.0):


def main():
"""Main"""
"""Run main script."""
for platform_name in ['Electro-L-N2', ]:
tohdf5(MsugsRSR, platform_name, MSUGS_BAND_NAMES)

Expand Down
6 changes: 0 additions & 6 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
[options]
setup_requires =
setuptools_scm
setuptools_scm_git_archive


[bdist_rpm]
provides=pyspectral
requires=numpy h5py python-geotiepoints dask PyYAML python-requests python-appdirs
Expand Down
14 changes: 2 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,11 @@

from setuptools import find_packages, setup

try:
# HACK: https://github.com/pypa/setuptools_scm/issues/190#issuecomment-351181286
# Stop setuptools_scm from including all repository files
import setuptools_scm.integration
setuptools_scm.integration.find_files = lambda _: []
except ImportError:
pass


description = ('Reading and manipulaing satellite sensor spectral responses and the '
'solar spectrum, to perfom various corrections to VIS and NIR band data')

try:
with open('./README', 'r') as fd:
with open('./README.md', 'r') as fd:
long_description = fd.read()
except IOError:
long_description = ''
Expand All @@ -62,8 +53,8 @@
'Topic :: Scientific/Engineering'],
url='https://github.com/pytroll/pyspectral',
long_description=long_description,
long_description_content_type="text/markdown",
license='GPLv3',

packages=find_packages(),
include_package_data=True,
package_data={
Expand Down Expand Up @@ -93,5 +84,4 @@
tests_require=test_requires,
python_requires='>=3.7',
zip_safe=False,
use_scm_version=True
)
Loading