Skip to content

Commit

Permalink
Backport PR #14784 on branch v5.3.x (TST: Test against Python 3.12 pr…
Browse files Browse the repository at this point in the history
…e-prelease) (#15370)

* Backport PR #14784: TST: Test against Python 3.12 pre-prelease

* cosmology changed a lot

* DOC: main has no more setup.cfg but that is irrelevant for v5.3.x so we just stop cross-ref.
  • Loading branch information
pllim committed Sep 22, 2023
1 parent 544714a commit e91d9af
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 17 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci_workflows.yml
Expand Up @@ -103,8 +103,9 @@ jobs:
- language-pack-de
- tzdata
envs: |
- name: (Allowed Failure) Python 3.11 with remote data and dev version of key dependencies
linux: py311-test-devdeps
- name: (Allowed Failure) Python 3.12 with remote data and dev version of key dependencies
linux: py312-test-devdeps
python-version: '3.12-dev'
posargs: --remote-data=any
# parallel_and_32bit removed because it is incompatible with numpy 1.26.
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/publish.yml
Expand Up @@ -54,16 +54,19 @@ jobs:
- cp39-manylinux_x86_64
- cp310-manylinux_x86_64
- cp311-manylinux_x86_64
- cp312-manylinux_x86_64
# Note that following wheels are not currently tested:
- cp39-manylinux_aarch64
- cp310-manylinux_aarch64
- cp311-manylinux_aarch64
- cp312-manylinux_aarch64
- cp39-musllinux_x86_64
- cp310-musllinux_x86_64
- cp311-musllinux_x86_64
- cp312-musllinux_x86_64
# MacOS X wheels - as noted in https://github.com/astropy/astropy/pull/12379 we deliberately
# do not build universal2 wheels. Note that the arm64 wheels are not actually tested so we
Expand All @@ -72,20 +75,24 @@ jobs:
- cp39*macosx_x86_64
- cp310*macosx_x86_64
- cp311*macosx_x86_64
- cp312*macosx_x86_64
- cp39*macosx_arm64
- cp310*macosx_arm64
- cp311*macosx_arm64
- cp312*macosx_arm64
# Windows wheels
- cp39*win32
- cp310*win32
- cp311*win32
- cp312*win32
- cp39*win_amd64
- cp310*win_amd64
- cp311*win_amd64
- cp312*win_amd64
secrets:
pypi_token: ${{ secrets.pypi_token }}
Expand Down
5 changes: 3 additions & 2 deletions astropy/nddata/mixins/ndslicing.py
Expand Up @@ -102,8 +102,9 @@ def _slice_uncertainty(self, item):
return None
try:
return self.uncertainty[item]
except TypeError:
except (TypeError, KeyError):
# Catching TypeError in case the object has no __getitem__ method.
# Catching KeyError for Python 3.12.
# But let IndexError raise.
log.info("uncertainty cannot be sliced.")
return self.uncertainty
Expand All @@ -113,7 +114,7 @@ def _slice_mask(self, item):
return None
try:
return self.mask[item]
except TypeError:
except (TypeError, KeyError):
log.info("mask cannot be sliced.")
return self.mask

Expand Down
13 changes: 9 additions & 4 deletions astropy/table/tests/test_table.py
Expand Up @@ -2893,14 +2893,19 @@ def test_table_attribute_ecsv():


def test_table_attribute_fail():
# Code raises ValueError(f'{attr} not allowed as TableAttribute') but in this
# context it gets re-raised as a RuntimeError during class definition.
with pytest.raises(RuntimeError, match="Error calling __set_name__"):
if sys.version_info[:2] >= (3, 12):
ctx = pytest.raises(ValueError, match=".* not allowed as TableAttribute")
else:
# Code raises ValueError(f'{attr} not allowed as TableAttribute') but in this
# context it gets re-raised as a RuntimeError during class definition.
ctx = pytest.raises(RuntimeError, match="Error calling __set_name__")

with ctx:

class MyTable2(Table):
descriptions = TableAttribute() # Conflicts with init arg

with pytest.raises(RuntimeError, match="Error calling __set_name__"):
with ctx:

class MyTable3(Table):
colnames = TableAttribute() # Conflicts with built-in property
Expand Down
1 change: 1 addition & 0 deletions docs/changes/14784.other.rst
@@ -0,0 +1 @@
Compatibility with Python 3.12.
3 changes: 1 addition & 2 deletions docs/development/codeguide.rst
Expand Up @@ -13,8 +13,7 @@ Interface and Dependencies
==========================

* All code must be compatible with the versions of Python indicated by the
``python_requires`` key in the `setup.cfg
<https://github.com/astropy/astropy/blob/main/setup.cfg>`_ file of the
``python_requires`` key in the ``setup.cfg`` file of the
core package.

* Usage of ``six``, ``__future__``, and ``2to3`` is no longer acceptable.
Expand Down
4 changes: 2 additions & 2 deletions docs/time/index.rst
Expand Up @@ -512,7 +512,7 @@ Example
To infer input format::

>>> from datetime import datetime
>>> from datetime import datetime, timezone
>>> t = Time(datetime(2010, 1, 2, 1, 2, 3))
>>> t.format
'datetime'
Expand Down Expand Up @@ -717,7 +717,7 @@ The current time can be determined as a |Time| object using the
`~astropy.time.Time.now` class method::

>>> nt = Time.now()
>>> ut = Time(datetime.utcnow(), scale='utc')
>>> ut = Time(datetime.now(tz=timezone.utc), scale='utc')

The two should be very close to each other.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
@@ -1,7 +1,7 @@
[build-system]
requires = ["setuptools",
"setuptools_scm>=6.2",
"cython==0.29.34",
"cython==0.29.36",
"numpy>=1.25,<2",
"extension-helpers"]
build-backend = 'setuptools.build_meta'
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Expand Up @@ -161,6 +161,9 @@ filterwarnings =
doctest_norecursedirs =
*/setup_package.py
doctest_subpackage_requires =
astropy/cosmology/io/mapping.py = python<3.12 # PYTHON_LT_3_12 (PR 14784)
astropy/cosmology/io/table.py = python<3.12 # PYTHON_LT_3_12 (PR 14784)
astropy/table/table.py = python<3.12 # PYTHON_LT_3_12 (PR 14784)
astropy/io/misc/asdf/* = asdf
astropy/table/mixins/dask.py = dask
docs/io/fits/index.rst = numpy<1.25 # NUMPY_LT_1_25 (Issue 14545)
Expand Down
8 changes: 4 additions & 4 deletions tox.ini
@@ -1,6 +1,6 @@
[tox]
envlist =
py{39,310,311,dev}-test{,-recdeps,-alldeps,-oldestdeps,-devdeps,-devinfra,-predeps,-numpy121,-numpy122,-numpy123,-mpl334}{,-cov}{,-clocale}{,-fitsio}
py{39,310,311,312,dev}-test{,-recdeps,-alldeps,-oldestdeps,-devdeps,-devinfra,-predeps,-numpy121,-numpy122,-numpy123,-mpl334}{,-cov}{,-clocale}{,-fitsio}
# Only these two exact tox environments have corresponding figure hash files.
py39-test-image-mpl334-cov
py39-test-image-mpldev-cov
Expand All @@ -25,6 +25,7 @@ setenv =
clocale: LC_CTYPE = C.ascii
clocale: LC_ALL = C
devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
mpldev: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
fitsio: ASTROPY_ALWAYS_TESTS_FITSIO = "true"

# Run the tests in a temporary directory to make sure that we don't import
Expand Down Expand Up @@ -90,6 +91,8 @@ deps =
devdeps: git+https://github.com/asdf-format/asdf.git#egg=asdf
devdeps: git+https://github.com/liberfa/pyerfa.git#egg=pyerfa

mpldev: matplotlib>=0.0.dev0

# Latest developer version of infrastructure packages.
devinfra: git+https://github.com/pytest-dev/pytest.git
devinfra: git+https://github.com/astropy/extension-helpers.git
Expand All @@ -104,15 +107,12 @@ deps =
# The following indicates which extras_require from setup.cfg will be installed
extras =
test: test
devdeps: test_all
recdeps: recommended
recdeps: test_all
alldeps: all
alldeps: test_all

commands =
mpldev: pip install -U --pre -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple matplotlib

pip freeze
!cov-!double: pytest --pyargs astropy {toxinidir}/docs {env:MPLFLAGS} {posargs}
cov-!double: pytest --pyargs astropy {toxinidir}/docs {env:MPLFLAGS} --cov astropy --cov-config={toxinidir}/pyproject.toml --cov-report xml:{toxinidir}/coverage.xml {posargs}
Expand Down

0 comments on commit e91d9af

Please sign in to comment.