diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml
index 3017f07..fe94e2c 100644
--- a/.github/workflows/python-package.yml
+++ b/.github/workflows/python-package.yml
@@ -19,7 +19,7 @@ jobs:
os: [ubuntu-latest]
python-version: ['3.10'] # There are still issues with Numpy <1.23 and 3.11.
numpy-version: ['<1.23', '<1.24', '<2.0']
- astropy-version: ['<5.1', '<6.0', '<7.0']
+ astropy-version: ['<6.0', '<6.1', '<7.0']
steps:
- name: Checkout code
@@ -89,7 +89,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
- run: python -m pip install --upgrade pip setuptools wheel Sphinx\<7 sphinx-rtd-theme
+ run: python -m pip install --upgrade pip setuptools wheel Sphinx sphinx-rtd-theme
- name: Test the documentation
run: sphinx-build -W --keep-going -b html doc doc/_build/html
diff --git a/doc/changes.rst b/doc/changes.rst
index f5f4d0e..0f02a34 100644
--- a/doc/changes.rst
+++ b/doc/changes.rst
@@ -15,8 +15,12 @@ Change Log
------------------
* Check input bounds in :func:`~desiutil.names.radec_to_desiname` (PR `#207`_).
+* Allow for a greater diversity of version strings in
+ :func:`~desiutil.setup.get_version` (PR `#208`_, `#209`_).
.. _`#207`: https://github.com/desihub/desiutil/pull/207
+.. _`#208`: https://github.com/desihub/desiutil/pull/208
+.. _`#209`: https://github.com/desihub/desiutil/pull/209
3.4.2 (2023-11-29)
------------------
diff --git a/doc/index.rst b/doc/index.rst
index 2c0b887..1a30988 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -32,6 +32,11 @@ need:
* `matplotlib `_
* `healpy `_
+If you want to work with the dust utilities in :mod:`desiutil.dust`, you will
+need:
+
+* `SciPy `
+
Contents
========
diff --git a/py/desiutil/setup.py b/py/desiutil/setup.py
index d41be34..be416af 100644
--- a/py/desiutil/setup.py
+++ b/py/desiutil/setup.py
@@ -28,6 +28,12 @@
from .modules import configure_module, process_module, default_module
+_match_version_line = re.compile(r"""__version__\s*=\s* # opening part of the line, allow any amount of whitespace including none
+ (?P['"]) # match any opening quote and give it the label oq = opening quote
+ (?P[^'"]+) # any character not a quote, one or more times, label v = version
+ (?P=oq) # match the same opening quote""", re.VERBOSE)
+
+
class DesiAPI(Command):
"""Generate an api.rst file.
"""
@@ -295,9 +301,9 @@ def get_version(productname):
update_version(productname)
with open(version_file, "r") as f:
for line in f.readlines():
- mo = re.match("__version__ = ('|\")(.*)('|\")", line)
+ mo = _match_version_line.match(line)
if mo:
- ver = mo.group(2)
+ ver = mo.group('v')
return ver
diff --git a/py/desiutil/test/test_setup.py b/py/desiutil/test/test_setup.py
index 40db724..bb2f866 100644
--- a/py/desiutil/test/test_setup.py
+++ b/py/desiutil/test/test_setup.py
@@ -154,6 +154,31 @@ def test_get_version(self):
v = get_version('desiutil')
self.assertEqual(v, desiutil_version)
+ def test_get_version_corner_cases(self):
+ """Test parsing a _version.py file with 'by-hand' formatting.
+ """
+ corner_cases = ("__version__ = '1.2.3'\n", # default format
+ '__version__ = "1.2.3"\n', # alternate quotes
+ '__version__="1.2.3"\n', # no whitespace
+ '__version__\t=\t"1.2.3"\n', # alternate whitespace
+ "__version__= \t\t '1.2.3'\n", # really alternate whitespace
+ """__version__ = "1.2.3'\n""") # mismatched quotes, should fail.
+ p = os.path.join(self.setup_dir, self.fake_name)
+ os.makedirs(p)
+ os.chdir(self.setup_dir)
+ version_file = os.path.join(p, '_version.py')
+ for case in corner_cases:
+ with open(version_file, 'w') as v:
+ v.write(case)
+ version = get_version(self.fake_name)
+ if case == """__version__ = "1.2.3'\n""":
+ self.assertEqual(version, 'unknown')
+ else:
+ self.assertEqual(version, '1.2.3')
+ os.remove(os.path.join(p, '_version.py'))
+ os.rmdir(p)
+ os.chdir(self.original_dir)
+
def test_update_version(self):
"""Test creating and updating a _version.py file.
"""
diff --git a/setup.cfg b/setup.cfg
index a1f0c4c..d8995d4 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -58,7 +58,9 @@ scripts =
[options.extras_require]
test =
pytest
+ scipy
coverage =
+ scipy
pytest-cov
coveralls
doc =