Skip to content

Commit

Permalink
Merge pull request #2107 from cta-observatory/py311
Browse files Browse the repository at this point in the history
Support python 3.11
  • Loading branch information
kosack authored May 11, 2023
2 parents 062fd96 + c82bc6a commit da82fa3
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jobs:
install-method: mamba
extra-args: ["codecov"]

- os: ubuntu-latest
python-version: "3.11"
install-method: pip

- os: ubuntu-latest
python-version: "3.10"
install-method: pip
Expand Down
17 changes: 17 additions & 0 deletions ctapipe/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Module for python version compatibility
"""
import sys

__all__ = [
"StrEnum",
]


if sys.version_info >= (3, 11):
from enum import StrEnum
else:
from enum import Enum

class StrEnum(str, Enum):
"""Compatibility backfill of StrEnum for python < 3.11"""
3 changes: 2 additions & 1 deletion ctapipe/instrument/optics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy as np
from astropy.table import QTable

from ..compat import StrEnum
from ..utils import get_table_dataset

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -37,7 +38,7 @@ class FocalLengthKind(Enum):


@unique
class SizeType(str, Enum):
class SizeType(StrEnum):
"""
Enumeration of different telescope sizes (LST, MST, SST)
"""
Expand Down
4 changes: 2 additions & 2 deletions ctapipe/reco/reconstructor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import weakref
from abc import abstractmethod
from enum import Enum

import astropy.units as u
import joblib
Expand All @@ -11,6 +10,7 @@
from ctapipe.core import Provenance, QualityQuery, TelescopeComponent
from ctapipe.core.traits import List

from ..compat import StrEnum
from ..coordinates import shower_impact_distance

__all__ = [
Expand All @@ -22,7 +22,7 @@
]


class ReconstructionProperty(str, Enum):
class ReconstructionProperty(StrEnum):
"""
Primary particle properties estimated by a `Reconstructor`
Expand Down
9 changes: 9 additions & 0 deletions ctapipe/tests/test_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from ctapipe.compat import StrEnum


def test_str_enum():
class Foo(StrEnum):
A = "A"
B = "B"

assert f"{Foo.A}" == "A"
1 change: 1 addition & 0 deletions docs/changes/2107.maintenance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for python 3.11.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def setup(app):
("py:class", "astropy.coordinates.baseframe.BaseCoordinateFrame"),
("py:class", "astropy.table.table.Table"),
("py:class", "eventio.simtel.simtelfile.SimTelFile"),
("py:class", "ctapipe.compat.StrEnum"),
]

# The suffix(es) of source filenames.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ install_requires=
importlib_metadata ; python_version < "3.10"
joblib
matplotlib ~=3.0
numba ~=0.56.0
numba >=0.56
numpy ~=1.16
psutil
pyyaml >=5.1
Expand Down

0 comments on commit da82fa3

Please sign in to comment.