Skip to content

Commit

Permalink
Merge pull request #1685 from pypeit/pkgrsrc
Browse files Browse the repository at this point in the history
Tests pass
```
Test Summary
--------------------------------------------------------
--- PYTEST PYPEIT UNIT TESTS PASSED  239 passed, 70 warnings in 549.16s (0:09:09) ---
--- PYTEST UNIT TESTS PASSED  133 passed, 171 warnings in 1006.59s (0:16:46) ---
--- PYTEST VET TESTS PASSED  58 passed, 68 warnings in 1070.66s (0:17:50) ---
--- PYPEIT DEVELOPMENT SUITE PASSED 231/231 TESTS  ---
Testing Started at 2023-10-02T21:32:49.404150
Testing Completed at 2023-10-03T14:51:06.930614
Total Time: 17:18:17.526464
```
  • Loading branch information
kbwestfall authored Oct 3, 2023
2 parents a82aa78 + d47e370 commit b23ec14
Show file tree
Hide file tree
Showing 21 changed files with 255 additions and 309 deletions.
8 changes: 4 additions & 4 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

1.14.1dev
---------

PLEASE ADD TO doc/releases/1.14.1dev.rst!
****************************************************************************
USE OF THIS FILE IS NOW DEPRECATED. CHANGES SHOULD BE ADDED TO THE RELEVANT
RELEASE FILE IN doc/releases
****************************************************************************


1.14.0 (18 Sep 2023)
Expand Down
15 changes: 8 additions & 7 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import os
import sys
from pkg_resources import get_distribution
from configparser import ConfigParser
from importlib import metadata
import pathlib

# Get configuration information from setup.cfg
from configparser import ConfigParser
conf = ConfigParser()

conf.read([os.path.join(os.path.dirname(__file__), '..', 'setup.cfg')])
conf.read([pathlib.Path(__file__).resolve().parents[1] / 'setup.cfg'])
setup_cfg = dict(conf.items('metadata'))

#
## 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.
#import sys
#sys.path.insert(0, os.path.abspath('../pypeit'))

# -- General configuration ------------------------------------------------
Expand Down Expand Up @@ -99,7 +98,9 @@
# built documents.

# The full version, including alpha/beta/rc tags.
version = get_distribution(setup_cfg['name']).version
#from pkg_resources import get_distribution
#version = get_distribution(setup_cfg['name']).version
version = metadata.version(setup_cfg['name'])

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion doc/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ same in bash) that will locate a test spec1D file and attempt to use

.. code-block:: console
python -c "from pkg_resources import resource_filename; print(resource_filename('pypeit', 'tests/files/spec1d_r153-J0025-0312_KASTr_20150123T025323.850.fits'))" | xargs -I {} pypeit_show_1dspec {}
python -c "from importlib import resources; print(resources.files('pypeit') / 'tests/files/spec1d_r153-J0025-0312_KASTr_20150123T025323.850.fits')" | xargs -I {} pypeit_show_1dspec {}
If ``pyqt6`` or another Qt backend is correctly installed, this should show a test
spectrum from the Shane/KAST spectrograph.
Expand Down
224 changes: 107 additions & 117 deletions doc/pypeit_par.rst

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions doc/releases/1.14.1dev.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Version 1.14.1dev
Dependency Changes
------------------

- Removes use of deprecated ``pkg_resources``.

Functionality/Performance Improvements and Additions
----------------------------------------------------

Expand Down
5 changes: 2 additions & 3 deletions doc/scripts/build_afterburn_datamodels_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Dynamically build the rst documentation for the Calibration Images
"""

from pathlib import Path
from pkg_resources import resource_filename
from importlib import resources

import numpy

Expand Down Expand Up @@ -142,7 +141,7 @@ def telluric_datamodel(output_root):

if __name__ == '__main__':
# Set the output directory
output_root = Path(resource_filename('pypeit', '')).resolve().parent / 'doc' / 'include'
output_root = resources.files('pypeit').parent / 'doc' / 'include'

# Sensitivity file
sens_datamodel(output_root)
Expand Down
13 changes: 6 additions & 7 deletions doc/scripts/build_bitmask_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Dynamically build tables for the bitmasks.
"""

import os
from importlib import resources
import time

import numpy

from pkg_resources import resource_filename
from pypeit.utils import to_string, string_table

from IPython import embed
Expand All @@ -15,7 +15,7 @@

def write_bitmask_table(obj, path):
bm = obj()
ofile = os.path.join(path, '{0}_table.rst'.format(obj.__name__.lower()))
ofile = path / f'{obj.__name__.lower()}_table.rst'

data_table = numpy.empty((bm.nbits+1, 4), dtype=object)
data_table[0,:] = ['Bit Name', 'Bit Number', 'Decimal Value', 'Description']
Expand All @@ -34,10 +34,9 @@ def write_bitmask_table(obj, path):
if __name__ == '__main__':
t = time.perf_counter()

pypeit_root = os.path.dirname(resource_filename('pypeit', ''))
path = os.path.join(pypeit_root, 'doc', 'include')
if not os.path.isdir(path):
os.makedirs(path)
path = resources.files('pypeit').parent / 'doc' / 'include'
if not path.is_dir():
path.mkdir(parents=True)

from pypeit.images.imagebitmask import ImageBitMask
write_bitmask_table(ImageBitMask, path)
Expand Down
5 changes: 2 additions & 3 deletions doc/scripts/build_calib_images_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Dynamically build the rst documentation for the Calibration Images
"""

from pathlib import Path
from pkg_resources import resource_filename
from importlib import resources

import numpy

Expand Down Expand Up @@ -287,7 +286,7 @@ def flatfield_datamodel(output_root):

if __name__ == '__main__':
# Set the output directory
output_root = Path(resource_filename('pypeit', '')).resolve().parent / 'doc' / 'include'
output_root = resources.files('pypeit').parent / 'doc' / 'include'

# Simple datamodels for Arc, Bias, Dark, Tiltimg
for obj in [buildimage.ArcImage, buildimage.BiasImage, buildimage.DarkImage,
Expand Down
5 changes: 2 additions & 3 deletions doc/scripts/build_datacontainer_datamodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
Dynamically build the rst documentation for the Calibration Images
"""

from pathlib import Path
from pkg_resources import resource_filename
from importlib import resources

from IPython import embed

Expand Down Expand Up @@ -59,7 +58,7 @@ def build_datamodel_tbl(obj):
if __name__ == '__main__':

# Set the output directory
output_root = Path(resource_filename('pypeit', '')).resolve().parent / 'doc' / 'include'
output_root = resources.files('pypeit').parent / 'doc' / 'include'

# All DataContainer objects
# TODO: automate this?
Expand Down
19 changes: 9 additions & 10 deletions doc/scripts/build_dependency_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
Construct an rst table with the dependencies
"""

from IPython import embed
import os
import configparser
from pkg_resources import resource_filename
from importlib import resources

import numpy

from pypeit.utils import string_table

from IPython import embed


def write_dependency_table(setup_file, path):
ofile = os.path.join(path, 'dependencies_table.rst')
ofile = path / 'dependencies_table.rst'

setup = configparser.ConfigParser()
setup.read(setup_file)
Expand All @@ -34,14 +34,13 @@ def write_dependency_table(setup_file, path):


def main():
output_root = os.path.join(os.path.split(os.path.abspath(resource_filename('pypeit', '')))[0],
'doc', 'include')
if not os.path.isdir(output_root):
pypeit_root = resources.files('pypeit').parent
output_root = pypeit_root / 'doc' / 'include'
if not output_root.is_dir():
raise NotADirectoryError(f'{output_root} does not exist!')

setup_file = os.path.join(os.path.split(os.path.abspath(resource_filename('pypeit', '')))[0],
'setup.cfg')
if not os.path.isfile(setup_file):
setup_file = pypeit_root / 'setup.cfg'
if not setup_file.is_file():
raise FileNotFoundError(f'{setup_file} does not exist!')
write_dependency_table(setup_file, output_root)

Expand Down
17 changes: 8 additions & 9 deletions doc/scripts/build_detector_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
Construct an rst table with the detector properties
"""

from IPython import embed
import os
from pkg_resources import resource_filename
from importlib import resources

import numpy

from pypeit.utils import string_table
from pypeit.spectrographs import spectrograph_classes
from pypeit.images.detector_container import DetectorContainer

from IPython import embed

#def write_detector_datamodel(ofile):
# from pypeit.images.detector_container import DetectorContainer
# det_dm = DetectorContainer.datamodel
# keys = numpy.sort(list(det_dm.keys()))
# nkeys = len(keys)
Expand Down Expand Up @@ -72,15 +72,14 @@ def write_detector_table(ofile):


def main():
output_root = os.path.join(os.path.split(os.path.abspath(resource_filename('pypeit', '')))[0],
'doc', 'include')
if not os.path.isdir(output_root):
output_root = resources.files('pypeit').parent / 'doc' / 'include'
if not output_root.is_dir():
raise NotADirectoryError(f'{output_root} does not exist!')

# ofile = os.path.join(output_root, 'datamodel_detector.rst')
# ofile = output_root / 'datamodel_detector.rst'
# write_detector_datamodel(ofile)

ofile = os.path.join(output_root, 'inst_detector_table.rst')
ofile = output_root / 'inst_detector_table.rst'
write_detector_table(ofile)


Expand Down
16 changes: 7 additions & 9 deletions doc/scripts/build_imgproc_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
Construct an rst table with the dependencies
"""

from IPython import embed
import os
from pkg_resources import resource_filename
from importlib import resources

import numpy

from pypeit.utils import string_table
from pypeit.par.pypeitpar import ProcessImagesPar, PypeItPar
from pypeit.spectrographs import spectrograph_classes

from IPython import embed


def write_imgproc_def_table(ofile, spec=None):
Expand Down Expand Up @@ -73,17 +72,16 @@ def write_imgproc_def_table(ofile, spec=None):


def main():
output_root = os.path.join(os.path.split(os.path.abspath(resource_filename('pypeit', '')))[0],
'doc', 'include')
if not os.path.isdir(output_root):
output_root = resources.files('pypeit').parent / 'doc' / 'include'
if not output_root.is_dir():
raise NotADirectoryError(f'{output_root} does not exist!')

ofile = os.path.join(output_root, 'imgproc_defaults_table.rst')
ofile = output_root / 'imgproc_defaults_table.rst'
write_imgproc_def_table(ofile)

# allspec = spectrograph_classes()
# for key, spec_c in allspec.items():
# ofile = os.path.join(output_root, f'imgproc_{key}_table.rst')
# ofile = output_root / f'imgproc_{key}_table.rst'
# write_imgproc_def_table(ofile, spec=spec_c())

if __name__ == '__main__':
Expand Down
15 changes: 6 additions & 9 deletions doc/scripts/build_par_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@
Dynamically build the rst documentation of the pypeit parameters.
"""

import os
from importlib import resources
import time
import textwrap

from IPython import embed

import numpy

from pkg_resources import resource_filename
from pypeit.par import pypeitpar
from pypeit.par.parset import ParSet
from pypeit.spectrographs.util import load_spectrograph
from pypeit.spectrographs import available_spectrographs

from IPython import embed

#-----------------------------------------------------------------------------
#def class_name(p):
# return '.'.join([type(p).__module__, type(p).__name__])
Expand Down Expand Up @@ -48,8 +45,8 @@ def par_hierarchy(p, indent_level=0, key=''):

# Read the baseline file that is not changed and must be edited by
# the person building the documentation as necessary.
pypeit_root = os.path.dirname(resource_filename('pypeit', ''))
input_base = os.path.join(pypeit_root, 'doc', 'scripts', 'base_par.rst')
pypeit_root = resources.files('pypeit').parent
input_base = pypeit_root / 'doc' / 'scripts' / 'base_par.rst'
with open(input_base, 'r') as f:
lines = [ l.replace('\n','') for l in f.readlines() ]
lines += ['']
Expand Down Expand Up @@ -99,7 +96,7 @@ def par_hierarchy(p, indent_level=0, key=''):
lines += ['']
lines += ['']

output_rst = os.path.join(pypeit_root, 'doc', 'pypeit_par.rst')
output_rst = pypeit_root / 'doc' / 'pypeit_par.rst'
with open(output_rst, 'w') as f:
f.write('\n'.join(lines))

Expand Down
9 changes: 4 additions & 5 deletions doc/scripts/build_specobj_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Dynamically build the rst documentation for the specobj and spec2dobj objects
"""

import os
from importlib import resources
import time

import numpy

from pkg_resources import resource_filename
from pypeit.utils import to_string, string_table
from pypeit import specobj
from pypeit import spec2dobj
Expand All @@ -20,13 +20,12 @@
t = time.perf_counter()

# Set the output directory
output_root = os.path.join(os.path.split(os.path.abspath(resource_filename('pypeit', '')))[0],
'doc', 'include')
output_root = resources.files('pypeit').parent / 'doc' / 'include'

# Iterate through all the specobj classes
for obj in [specobj.SpecObj, spec2dobj.Spec2DObj, coadd1d.OneSpec]:

ofile = os.path.join(output_root, 'datamodel_{0}.rst'.format(obj.__name__.lower()))
ofile = output_root / f'datamodel_{obj.__name__.lower()}.rst'

lines = []
lines += ['']
Expand Down
Loading

0 comments on commit b23ec14

Please sign in to comment.