Skip to content

Commit

Permalink
Fix some python 3.11 issues (#218)
Browse files Browse the repository at this point in the history
* Some python 3.11 fixes

* Add python 3.8 support back

* Whoops

* Add a 3.11 job to the CI

* Add changelog
  • Loading branch information
Cadair authored Feb 7, 2023
1 parent de597eb commit 7ec32ce
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
with:
envs: |
- linux: py39
- macos: py38
- macos: py311
- linux: py310-devdeps
- windows: py38-oldestdeps
coverage: 'codecov'
Expand Down
1 change: 1 addition & 0 deletions changelog/218.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for Python 3.11
9 changes: 7 additions & 2 deletions dkist/dataset/dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import sys
from pathlib import Path
from textwrap import dedent
from importlib import resources

if sys.version_info < (3, 9):
import importlib_resources
else:
import importlib.resources as importlib_resources

from jsonschema.exceptions import ValidationError

Expand Down Expand Up @@ -188,7 +193,7 @@ def from_asdf(cls, filepath):
filepath = Path(filepath).expanduser()
base_path = filepath.parent
try:
with resources.path("dkist.io", "level_1_dataset_schema.yaml") as schema_path:
with importlib_resources.as_file(importlib_resources.files("dkist.io") / "level_1_dataset_schema.yaml") as schema_path:
with asdf.open(filepath, custom_schema=schema_path.as_posix(),
lazy_load=False, copy_arrays=True) as ff:
ds = ff.tree['dataset']
Expand Down
11 changes: 8 additions & 3 deletions dkist/io/asdf/tests/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import sys
from pathlib import Path
from importlib import resources

if sys.version_info < (3, 9):
import importlib_resources
else:
import importlib.resources as importlib_resources

import numpy as np
import pytest
Expand Down Expand Up @@ -101,7 +106,7 @@ def test_asdf_tags(dataset, tmp_path):
indirect=True)
def test_save_dataset_with_file_schema(tagobj, tmpdir):
tree = {'dataset': tagobj}
with resources.path("dkist.io", "level_1_dataset_schema.yaml") as schema_path:
with importlib_resources.as_file(importlib_resources.files("dkist.io") / "level_1_dataset_schema.yaml") as schema_path:
with asdf.AsdfFile(tree, custom_schema=schema_path.as_posix()) as afile:
afile.write_to(Path(tmpdir / "test.asdf"))

Expand All @@ -115,7 +120,7 @@ def test_read_all_schema_versions(asdf_file):
This test validates that we can successfully read a full and valid Dataset
object from files with all versions of the dataset schema.
"""
with resources.path("dkist.io", "level_1_dataset_schema.yaml") as schema_path:
with importlib_resources.as_file(importlib_resources.files("dkist.io") / "level_1_dataset_schema.yaml") as schema_path:
with asdf.open(asdf_file) as afile:
dataset = afile["dataset"]
dataset.files.basepath = rootdir / "EIT"
Expand Down
4 changes: 2 additions & 2 deletions dkist/net/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import cgi
import json
import urllib.parse
import urllib.request
Expand All @@ -19,6 +18,7 @@
from sunpy.net import attrs as sattrs
from sunpy.net.base_client import (BaseClient, QueryResponseRow,
QueryResponseTable, convert_row_to_table)
from sunpy.util.net import parse_header

from dkist.utils.inventory import INVENTORY_KEY_MAP

Expand Down Expand Up @@ -170,7 +170,7 @@ def _make_filename(path: os.PathLike, row: QueryResponseRow,
if resp:
cdheader = resp.headers.get("Content-Disposition", None)
if cdheader:
_, params = cgi.parse_header(cdheader)
_, params = parse_header(cdheader)
name = params.get('filename', "")

return str(path).format(file=name, **row.response_block_map)
Expand Down
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ install_requires =
gwcs>=0.18.0
matplotlib>=3.1
ndcube[plotting,reproject]>=2.0
numpy>=1.17
numpy>=1.21
parfive[ftp]>=1.3
sunpy[net,asdf]>=4
importlib-resources; python_version<"3.9"
setup_requires = setuptools_scm

[options.extras_require]
Expand Down Expand Up @@ -115,6 +116,8 @@ filterwarnings =
ignore:ASDF functionality for astropy is being moved out of the astropy package to the new asdf-astropy package
ignore:FLIP_TOP_BOTTOM is deprecated and will be removed in Pillow.*
ignore::ResourceWarning
# Zeep relies on deprecated cgi in Python 3.11
ignore:'cgi' is deprecated and slated for removal in Python 3.13:DeprecationWarning:zeep.utils
# Oldestdeps below here
ignore:`np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself.::dask.array
ignore:leap-second auto-update failed due to the following exception
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ deps =
oldestdeps: gwcs<0.19
oldestdeps: matplotlib<3.3
oldestdeps: ndcube<2.1
oldestdeps: numpy<1.19
oldestdeps: numpy<1.22
oldestdeps: parfive[ftp]<1.3
oldestdeps: sunpy[net,asdf]<4.0.1
oldestdeps: sunpy[net,asdf]<4.0.8 # py3.11 support added in .7
oldestdeps: setuptools<60 # Use older setuptools to prevent distutils warning

[testenv:build_docs]
Expand Down

0 comments on commit 7ec32ce

Please sign in to comment.