Skip to content

Commit 6eefe6d

Browse files
authored
Merge pull request #2838 from bsipocz/CI_add_py312
MAINT: Fixing python 3.12 compatibility
2 parents 72510b4 + f4287da commit 6eefe6d

File tree

15 files changed

+49
-37
lines changed

15 files changed

+49
-37
lines changed

.github/workflows/ci_crontests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050

5151
steps:
5252
- name: Checkout code
53-
uses: actions/checkout@v3
53+
uses: actions/checkout@v4
5454
with:
5555
fetch-depth: 0
5656
- name: Set up Python

.github/workflows/ci_devtests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ jobs:
3232
include:
3333
- name: dev dependencies with all dependencies with coverage
3434
os: ubuntu-latest
35-
python: '3.11'
36-
toxenv: py311-test-alldeps-devdeps-cov
35+
python: '3.12-dev'
36+
toxenv: py312-test-alldeps-devdeps-cov
3737
toxargs: -v
3838

3939
steps:
4040
- name: Checkout code
41-
uses: actions/checkout@v3
41+
uses: actions/checkout@v4
4242
with:
4343
fetch-depth: 0
4444
- name: Set up Python

.github/workflows/ci_tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
name: ${{ matrix.name }}
2828
runs-on: ${{ matrix.os }}
2929
strategy:
30-
fail-fast: true
30+
fail-fast: false
3131
matrix:
3232
include:
3333

@@ -56,7 +56,7 @@ jobs:
5656

5757
steps:
5858
- name: Checkout code
59-
uses: actions/checkout@v3
59+
uses: actions/checkout@v4
6060
with:
6161
fetch-depth: 0
6262
- name: Set up Python
@@ -78,7 +78,7 @@ jobs:
7878
runs-on: ubuntu-latest
7979
steps:
8080
- name: Checkout code
81-
uses: actions/checkout@v3
81+
uses: actions/checkout@v4
8282
with:
8383
fetch-depth: 0
8484
- name: Set up Python

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "astropy_helpers"]
22
path = astropy_helpers
3-
url = https://github.com/astropy/astropy-helpers.git
3+
url = https://github.com/bsipocz/astropy-helpers.git

astroquery/alma/tests/test_alma_remote.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2-
from datetime import datetime
2+
from datetime import datetime, timezone
33
import os
44
from pathlib import Path
55
from urllib.parse import urlparse
@@ -139,7 +139,7 @@ def test_data_proprietary(self, alma):
139139
# public
140140
assert not alma.is_proprietary('uid://A001/X12a3/Xe9')
141141
IVOA_DATE_FORMAT = "%Y-%m-%dT%H:%M:%S.%f"
142-
now = datetime.utcnow().strftime(IVOA_DATE_FORMAT)[:-3]
142+
now = datetime.now(timezone.utc).strftime(IVOA_DATE_FORMAT)[:-3]
143143
query = "select top 1 member_ous_uid from ivoa.obscore where " \
144144
"obs_release_date > '{}'".format(now)
145145
result = alma.query_tap(query)

astroquery/cadc/tests/test_cadctap_remote.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import os
1010
import requests
1111
from pathlib import Path
12-
from datetime import datetime
12+
from datetime import datetime, timezone
1313
from astropy.coordinates import SkyCoord
1414
from astropy.io import fits
1515
from astropy import units as u
@@ -99,7 +99,7 @@ def test_query(self):
9999
assert 1000 < result[0][0]
100100

101101
# test that no proprietary results are returned when not logged in
102-
now = datetime.utcnow()
102+
now = datetime.now(timezone.utc)
103103
query = "select top 1 * from caom2.Plane where " \
104104
"metaRelease>'{}'".format(now.strftime('%Y-%m-%dT%H:%M:%S.%f'))
105105
result = cadc.exec_sync(query)
@@ -121,7 +121,7 @@ def test_login_with_user_password(self):
121121
for auth_session in [None, authsession.AuthSession(),
122122
requests.Session()]:
123123
cadc = Cadc(auth_session=auth_session)
124-
now = datetime.utcnow()
124+
now = datetime.now(timezone.utc)
125125
query = \
126126
"select top 1 * from caom2.Plane where metaRelease>'{}'".\
127127
format(now.strftime('%Y-%m-%dT%H:%M:%S.%f'))
@@ -152,7 +152,7 @@ def test_login_with_user_password(self):
152152
def test_login_with_cert(self):
153153
for auth_session in [requests.Session()]:
154154
cadc = Cadc(auth_session=auth_session)
155-
now = datetime.utcnow()
155+
now = datetime.now(timezone.utc)
156156
query = \
157157
"select top 1 * from caom2.Plane where metaRelease>'{}'".\
158158
format(now.strftime('%Y-%m-%dT%H:%M:%S.%f'))
@@ -181,14 +181,14 @@ def test_authsession(self):
181181
auth_session = requests.Session()
182182
auth_session.cert = os.environ['CADC_CERT']
183183
cadc = Cadc(auth_session=auth_session)
184-
now = datetime.utcnow()
184+
now = datetime.now(timezone.utc)
185185
query = "select top 1 * from caom2.Plane where " \
186186
"metaRelease>'{}'".format(now.strftime('%Y-%m-%dT%H:%M:%S.%f'))
187187
result = cadc.exec_sync(query)
188188
assert len(result) == 1
189189
annon_session = requests.Session()
190190
cadc = Cadc(auth_session=annon_session)
191-
now = datetime.utcnow()
191+
now = datetime.now(timezone.utc)
192192
query = "select top 1 * from caom2.Plane where " \
193193
"metaRelease>'{}'".format(now.strftime('%Y-%m-%dT%H:%M:%S.%f'))
194194
result = cadc.exec_sync(query)

astroquery/esa/jwst/core.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import gzip
1414
import os
1515
import shutil
16-
import tarfile
16+
import tarfile as esatar
1717
import zipfile
18-
from datetime import datetime
18+
from datetime import datetime, timezone
1919
from urllib.parse import urlencode
2020

2121
from astropy import log
@@ -39,6 +39,12 @@
3939
__all__ = ['Jwst', 'JwstClass']
4040

4141

42+
# We do trust the ESA tar files, this is to avoid the new to Python 3.12 deprecation warning
43+
# https://docs.python.org/3.12/library/tarfile.html#tarfile-extraction-filter
44+
if hasattr(esatar, "fully_trusted_filter"):
45+
esatar.TarFile.extraction_filter = staticmethod(esatar.fully_trusted_filter)
46+
47+
4248
class JwstClass(BaseQuery):
4349

4450
"""
@@ -1037,8 +1043,8 @@ def __check_file_number(self, output_dir, output_file_name,
10371043
files.append(os.path.join(r, file))
10381044

10391045
def __extract_file(self, output_file_full_path, output_dir, files):
1040-
if tarfile.is_tarfile(output_file_full_path):
1041-
with tarfile.open(output_file_full_path) as tar_ref:
1046+
if esatar.is_tarfile(output_file_full_path):
1047+
with esatar.open(output_file_full_path) as tar_ref:
10421048
tar_ref.extractall(path=output_dir)
10431049
elif zipfile.is_zipfile(output_file_full_path):
10441050
with zipfile.ZipFile(output_file_full_path, 'r') as zip_ref:
@@ -1050,7 +1056,7 @@ def __extract_file(self, output_file_full_path, output_dir, files):
10501056

10511057
def __set_dirs(self, output_file, observation_id):
10521058
if output_file is None:
1053-
now = datetime.now()
1059+
now = datetime.now(timezone.utc)
10541060
formatted_now = now.strftime("%Y%m%d_%H%M%S")
10551061
output_dir = os.getcwd() + os.sep + "temp_" + \
10561062
formatted_now

astroquery/esa/xmm_newton/core.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import re
1212
import shutil
1313
from pathlib import Path
14-
import tarfile
14+
import tarfile as esatar
1515
import os
1616
import configparser
1717
from email.message import Message
@@ -29,6 +29,12 @@
2929
__all__ = ['XMMNewton', 'XMMNewtonClass']
3030

3131

32+
# We do trust the ESA tar files, this is to avoid the new to Python 3.12 deprecation warning
33+
# https://docs.python.org/3.12/library/tarfile.html#tarfile-extraction-filter
34+
if hasattr(esatar, "fully_trusted_filter"):
35+
esatar.TarFile.extraction_filter = staticmethod(esatar.fully_trusted_filter)
36+
37+
3238
class XMMNewtonClass(BaseQuery):
3339
data_url = conf.DATA_ACTION
3440
data_aio_url = conf.DATA_ACTION_AIO
@@ -406,7 +412,7 @@ def get_epic_spectra(self, filename, source_number, *,
406412
if path != "" and os.path.exists(path):
407413
_path = path
408414
try:
409-
with tarfile.open(filename, "r") as tar:
415+
with esatar.open(filename, "r") as tar:
410416
ret = {}
411417
for member in tar.getmembers():
412418
paths = os.path.split(member.name)
@@ -552,7 +558,7 @@ def get_epic_images(self, filename, band=[], instrument=[],
552558
log.warning("Invalid instrument %s" % inst)
553559
instrument.remove(inst)
554560
try:
555-
with tarfile.open(filename, "r") as tar:
561+
with esatar.open(filename, "r") as tar:
556562
ret = {}
557563
for member in tar.getmembers():
558564
paths = os.path.split(member.name)
@@ -728,7 +734,7 @@ def get_epic_lightcurve(self, filename, source_number, *,
728734
_path = path
729735

730736
try:
731-
with tarfile.open(filename, "r") as tar:
737+
with esatar.open(filename, "r") as tar:
732738
ret = {}
733739
for member in tar.getmembers():
734740
paths = os.path.split(member.name)

astroquery/gaia/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""
1616
import zipfile
1717
import os
18-
from datetime import datetime
18+
from datetime import datetime, timezone
1919
import shutil
2020
from collections.abc import Iterable
2121

@@ -221,7 +221,7 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL',
221221
-------
222222
A table object
223223
"""
224-
now = datetime.now()
224+
now = datetime.now(timezone.utc)
225225
now_formatted = now.strftime("%Y%m%d_%H%M%S")
226226
temp_dirname = "temp_" + now_formatted
227227
downloadname_formated = "download_" + now_formatted

0 commit comments

Comments
 (0)