Skip to content

Commit

Permalink
update package infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Sep 18, 2024
1 parent 094511c commit b5b47a6
Show file tree
Hide file tree
Showing 15 changed files with 273 additions and 163 deletions.
28 changes: 0 additions & 28 deletions .coveragerc

This file was deleted.

30 changes: 15 additions & 15 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ jobs:
matrix:
os: [ubuntu-latest]
python-version: ['3.9', '3.10'] #, '3.11'] possible conflicts between numpy & astropy on 3.11.
astropy-version: ['<5.1', '<5.3', '<6.0']
desiutil-version: ['3.3.1', 'main']
astropy-version: ['<6.0', '<6.1', '<7.0']
desiutil-version: ['3.4.3', 'main']

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install pytest jinja2
python -m pip install numpy\<1.23
python -m pip install numpy\<2.0
python -m pip install "git+https://github.com/desihub/desiutil.git@${{ matrix.desiutil-version }}#egg=desiutil"
python -m pip install "astropy${{ matrix.astropy-version }}"
- name: Run the test
Expand All @@ -52,19 +52,19 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install pytest pytest-cov coveralls
python -m pip install numpy\<2.0
python -m pip install -r requirements.txt
python -m pip install --upgrade numpy\<1.23
- name: Run the test with coverage
run: |
pytest --cov
Expand All @@ -86,11 +86,11 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
Expand All @@ -112,15 +112,15 @@ jobs:
matrix:
os: [ubuntu-latest]
python-version: ['3.10']
desiutil-version: ['3.3.0']
desiutil-version: ['3.4.3']

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
Expand All @@ -144,11 +144,11 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
Expand Down
2 changes: 0 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@ sphinx:

# Optionally set the version of Python and requirements required to build your docs
python:
# version: 3
# system_packages: true
install:
- requirements: doc/rtd-requirements.txt
2 changes: 1 addition & 1 deletion LICENSE.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014-2022, DESI Collaboration <[email protected]>
Copyright (c) 2014-2024, DESI Collaboration <[email protected]>
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
14 changes: 2 additions & 12 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
include LICENSE.rst
include README.rst
include requirements.txt

graft bin
graft doc
graft etc

prune build
prune dist
prune htmlcov
prune doc/_build
prune .github
global-exclude .gitignore .readthedocs.yml
4 changes: 3 additions & 1 deletion doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ desidatamodel Change Log
24.10 (unreleased)
------------------

* No changes yet.
* Update package infrastructure, ... (PR `#200`_).

.. _`#200`: https://github.com/desihub/desidatamodel/pull/200

24.9 (2024-09-12)
-----------------
Expand Down
2 changes: 1 addition & 1 deletion py/desidatamodel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
This package provides support for the DESI_ Data Model.
.. _DESI: http://desi.lbl.gov
.. _DESI: https://www.desi.lbl.gov
"""
#
# Set version string.
Expand Down
14 changes: 7 additions & 7 deletions py/desidatamodel/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,16 @@ def extract_metadata(self, error=False):
spanend = int(g[1])
log.debug('Detected range specification from HDU %d to HDU %d',
spanstart, spanend)
spanref = [l for l in section if l.startswith('Data:')][0]
spanref = [ln for ln in section if ln.startswith('Data:')][0]
spanext = spanref[spanref.lower().index('see') + 4:].replace('.', '')
try:
spanmeta = self.hdumeta[spanext]
except KeyError:
m = "Cannot find EXTNAME = '%s' which is supposed to define HDU %d to HDU %d!"
log.critical(m, spanext, spanstart, spanend)
raise DataModelError(m % (spanext, spanstart, spanend))
spanname = [l.split('=')[1].strip() for l in section
if l.startswith('EXTNAME = ')][0]
spanname = [ln.split('=')[1].strip() for ln in section
if ln.startswith('EXTNAME = ')][0]
extnames = [p.strip() for p in spanname.split(',')]
if len(range(spanstart, spanend+1)) == len(extnames):
for i, l in enumerate(range(spanstart, spanend+1)):
Expand All @@ -357,7 +357,7 @@ def extract_metadata(self, error=False):
meta = dict()
meta['number'] = k
meta['title'] = section[0]
hdu_cross_ref = [l for l in section if l.startswith('See `')]
hdu_cross_ref = [ln for ln in section if ln.startswith('See `')]
if hdu_cross_ref:
log.debug("Found HDU cross-reference: %s", hdu_cross_ref[0])
hcr = self._cross_reference(hdu_cross_ref[0]).split('#')
Expand All @@ -372,7 +372,7 @@ def extract_metadata(self, error=False):
if 'Empty HDU.' in section:
meta['extension'] = 'IMAGE'
meta['format'] = 'Empty HDU.'
image_data = [l for l in section if l.startswith('Data:')]
image_data = [ln for ln in section if ln.startswith('Data:')]
if image_data:
meta['extension'] = 'IMAGE'
meta['format'] = image_data[0]
Expand Down Expand Up @@ -439,8 +439,8 @@ def extract_metadata(self, error=False):
# the detailed policy on EXTNAME.
#
try:
meta['extname'] = [l.split()[2] for l in section
if l.startswith('EXTNAME = ')][0]
meta['extname'] = [ln.split()[2] for ln in section
if ln.startswith('EXTNAME = ')][0]
except IndexError:
meta['extname'] = 'HDU{0:02d}'.format(k)
if (k > 0 or (k == 0 and meta['format'] != 'Empty HDU.')):
Expand Down
7 changes: 5 additions & 2 deletions py/desidatamodel/test/datamodeltestcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ def assertInLog(self, logger, message=''):
def badUnitMessage(self, unit):
"""Returns a string that can be used to match errors related to bad units.
"""
m = "'{0}' did not parse as fits unit: At col {1:d}, Unit 'ergs' not supported by the FITS standard. Did you mean erg?".format(unit, unit.index('ergs'))
m = ("'{0}' did not parse as fits unit: At col {1:d}, Unit 'ergs' not " +
"supported by the FITS standard. Did you mean erg?").format(unit, unit.index('ergs'))
if self.astropyVersion >= version.parse('4.0'):
m += " If this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file reader or other code, enable it with 'u.add_enabled_units'. For details, see http://docs.astropy.org/en/latest/units/combining_and_defining.html"
m += (" If this is meant to be a custom unit, define it with 'u.def_unit'. " +
"To have it recognized inside a file reader or other code, enable it with " +
"'u.add_enabled_units'. For details, see http://docs.astropy.org/en/latest/units/combining_and_defining.html")
if self.astropyVersion >= version.parse('4.0.2'):
m = m.replace('http', 'https')
return m
19 changes: 14 additions & 5 deletions py/desidatamodel/test/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ def test_validate_prototype_hdu_mismatch(self):
foo = f.extract_metadata()
f.hdumeta['foobar'] = 'baz'
f.validate_prototype(error=True)
self.assertLog(log, -2, "{0} has the wrong number of sections (HDUs) according to {1}, skipping to next candidate.".format(str(modelfile).replace('.rst', '.fits'), modelfile))
self.assertLog(log, -2, ("{0} has the wrong number of sections (HDUs) " +
"according to {1}, skipping to next " +
"candidate.").format(str(modelfile).replace('.rst', '.fits'), modelfile))
self.assertLog(log, -1, "No useful prototype files found for {0}!".format(modelfile))

def test_validate_prototype_hdu_keyword_mismatch(self):
Expand All @@ -484,7 +486,8 @@ def test_validate_prototype_hdu_keyword_mismatch(self):
f.validate_prototype()
f._stub_meta[0]['keywords'].append(('BUNIT', 'erg', 'str', 'This is a test.'))
f.validate_prototype(error=True)
self.assertLog(log, -1, "Prototype file {0} has these keywords in HDU0 missing from model: {{'BUNIT'}}".format(str(modelfile).replace('.rst', '.fits')))
self.assertLog(log, -1, ("Prototype file {0} has these keywords " +
"in HDU0 missing from model: {{'BUNIT'}}").format(str(modelfile).replace('.rst', '.fits')))

def test_validate_prototype_hdu_keyword_type_mismatch(self):
"""Test the data model validation method with a keyword type mismatch.
Expand All @@ -496,7 +499,9 @@ def test_validate_prototype_hdu_keyword_type_mismatch(self):
f.extract_metadata()
f.hdumeta['PRIMARY']['keywords'][2] = ('BSCALE', '1.2', 'float', '')
f.validate_prototype()
self.assertLog(log, -1, "File %s HDU%d keyword %s has different keyword type according to %s (%s != %s)." % (f.prototype, 0, 'BSCALE', modelfile, 'int', 'float'))
self.assertLog(log, -1, ("File %s HDU%d keyword %s has different keyword " +
"type according to %s (%s != %s).") %
(f.prototype, 0, 'BSCALE', modelfile, 'int', 'float'))

def test_validate_prototype_hdu_wrong_keyword(self):
"""Test the data model validation method with wrong HDU keyword names.
Expand All @@ -521,7 +526,9 @@ def test_validate_prototype_hdu_extension_type(self):
f.validate_prototype()
f._stub_meta[1]['extension'] = 'IMAGE'
f.validate_prototype(error=True)
self.assertLog(log, -1, "Prototype file {0} has an extension type mismatch in HDU1 (IMAGE != BINTABLE) according to {1}.".format(str(modelfile).replace('.rst', '.fits'), modelfile))
self.assertLog(log, -1, ("Prototype file {0} has an extension type " +
"mismatch in HDU1 (IMAGE != BINTABLE) according " +
"to {1}.").format(str(modelfile).replace('.rst', '.fits'), modelfile))
# f._stub_meta[1]['extname'] = ''
# f.validate_prototype(error=True)
# self.assertLog(log, -1, "Prototype file {0} has no EXTNAME in HDU1.".format(str(modelfile).replace('.rst', '.fits')))
Expand All @@ -536,7 +543,9 @@ def test_validate_prototype_hdu_extension_name(self):
f.validate_prototype()
f._stub_meta[1]['extname'] = 'GALAXY'
f.validate_prototype(error=True)
self.assertLog(log, -1, "Prototype file {0} has an EXTNAME mismatch in HDU1 (GALAXY != Galaxies) according to {1}.".format(str(modelfile).replace('.rst', '.fits'), modelfile))
self.assertLog(log, -1, ("Prototype file {0} has an EXTNAME mismatch in " +
"HDU1 (GALAXY != Galaxies) according to " +
"{1}.").format(str(modelfile).replace('.rst', '.fits'), modelfile))
f._stub_meta[1]['extname'] = ''
f.validate_prototype(error=True)
self.assertLog(log, -2, "Prototype file {0} has no EXTNAME in HDU1.".format(str(modelfile).replace('.rst', '.fits')))
Expand Down
31 changes: 24 additions & 7 deletions py/desidatamodel/test/test_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,30 @@ def test_union_metadata(self, mock_update, mock_mark):
foo = model.get_regexp('/desi/spectro/data')
union_metadata(model, stubs)
mock_mark.assert_called_once()
mock_update.assert_has_calls([call(0, [('NAXIS1', '100', 'int', ''), ('NAXIS2', '100', 'int', ''), ('BSCALE', '1', 'int', ''), ('BZERO', '32768', 'int', 'Data are really unsigned 16-bit int.')]),
call(1, [('NAXIS1', '32', 'int', 'length of dimension 1'), ('NAXIS2', '3', 'int', 'length of dimension 2')]),
call(1, [('Name', 'Type', 'Units', 'Description'), ('target', 'char[20]', '', ''), ('V_mag', 'float32', 'mag', ''), ('vdisp', 'float64', 'km/s', '')], columns=True),
call(0, [('NAXIS1', '100', 'int', ''), ('NAXIS2', '100', 'int', ''), ('BSCALE', '1', 'int', ''), ('BZERO', '32768', 'int', 'Data are really unsigned 16-bit int.')]),
call(1, [('NAXIS1', '32', 'int', 'length of dimension 1'), ('NAXIS2', '3', 'int', 'length of dimension 2')]),
call(1, [('Name', 'Type', 'Units', 'Description'), ('target', 'char[20]', '', ''), ('V_mag', 'float32', 'mag', ''), ('vdisp', 'float64', 'km/s', '')], columns=True),
call(0, [('NAXIS1', '100', 'int', ''), ('NAXIS2', '100', 'int', ''), ('BSCALE', '1', 'int', ''), ('BZERO', '32768', 'int', 'Data are really unsigned 16-bit int.')])])
mock_update.assert_has_calls([call(0, [('NAXIS1', '100', 'int', ''),
('NAXIS2', '100', 'int', ''),
('BSCALE', '1', 'int', ''),
('BZERO', '32768', 'int', 'Data are really unsigned 16-bit int.')]),
call(1, [('NAXIS1', '32', 'int', 'length of dimension 1'),
('NAXIS2', '3', 'int', 'length of dimension 2')]),
call(1, [('Name', 'Type', 'Units', 'Description'),
('target', 'char[20]', '', ''),
('V_mag', 'float32', 'mag', ''),
('vdisp', 'float64', 'km/s', '')], columns=True),
call(0, [('NAXIS1', '100', 'int', ''),
('NAXIS2', '100', 'int', ''),
('BSCALE', '1', 'int', ''),
('BZERO', '32768', 'int', 'Data are really unsigned 16-bit int.')]),
call(1, [('NAXIS1', '32', 'int', 'length of dimension 1'),
('NAXIS2', '3', 'int', 'length of dimension 2')]),
call(1, [('Name', 'Type', 'Units', 'Description'),
('target', 'char[20]', '', ''),
('V_mag', 'float32', 'mag', ''),
('vdisp', 'float64', 'km/s', '')], columns=True),
call(0, [('NAXIS1', '100', 'int', ''),
('NAXIS2', '100', 'int', ''),
('BSCALE', '1', 'int', ''),
('BZERO', '32768', 'int', 'Data are really unsigned 16-bit int.')])])

@patch('sys.argv', ['deep_scan_metadata', '--verbose', '--number', '1000', 'DESI_SPECTRO_DATA/NIGHT/EXPID/desi-EXPID.rst', '/desi/spectro/data'])
def test_options(self):
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build-system]
requires = ["setuptools",
"wheel"]
build-backend = 'setuptools.build_meta'
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
astropy
sphinx-toolbox
jinja2
git+https://github.com/desihub/desiutil.git@3.3.1#egg=desiutil
git+https://github.com/desihub/desiutil.git@3.4.3#egg=desiutil
Loading

0 comments on commit b5b47a6

Please sign in to comment.