Skip to content

Commit 17cdbf9

Browse files
committed
Use uppercase for enums
1 parent 1f6f460 commit 17cdbf9

File tree

5 files changed

+60
-36
lines changed

5 files changed

+60
-36
lines changed

celerpy/conf/settings.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
# Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
22
# See the top-level LICENSE file for details.
33
# SPDX-License-Identifier: Apache-2.0
4-
from enum import StrEnum
54
from typing import Optional
65

76
from pydantic import DirectoryPath
87
from pydantic_settings import BaseSettings, SettingsConfigDict
98

10-
11-
class LogLevel(StrEnum):
12-
"""Minimum verbosity level for logging."""
13-
14-
debug = "debug"
15-
info = "info"
16-
warning = "warning"
17-
error = "error"
18-
critical = "critical"
9+
from celerpy.model import LogLevel
1910

2011

2112
class Settings(BaseSettings):
22-
"""Global settings for Celeritas front end.
13+
"""Global environment settings for Celeritas front end.
2314
2415
Settings can be changed by setting environment variables such as
2516
``CELER_PREFIX_PATH`` (case insensitive).
@@ -45,10 +36,10 @@ class Settings(BaseSettings):
4536
g4org_verbose: bool = False
4637
"Filename base to export converted Geant4 geometry"
4738

48-
log: LogLevel = LogLevel.info
39+
log: LogLevel = LogLevel.INFO
4940
"World log level"
5041

51-
log_local: LogLevel = LogLevel.warning
42+
log_local: LogLevel = LogLevel.WARNING
5243
"Self log level"
5344

5445
prefix_path: Optional[DirectoryPath] = None

celerpy/model.py

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44
"""Manage models used for JSON I/O with Celeritas."""
55

6-
from enum import Enum
6+
from enum import StrEnum, auto
77
from typing import Annotated, Literal, Optional
88

99
from pydantic import (
@@ -30,28 +30,53 @@ class _Model(BaseModel):
3030
model_config = ConfigDict(use_attribute_docstrings=True)
3131

3232

33-
# celer-geo/Types.hh
34-
class GeometryEngine(Enum):
35-
"""Geometry model implementation for execution and rendering."""
33+
# corecel/Types.hh
34+
class MemSpace(StrEnum):
35+
"""Memory/execution space."""
3636

37-
geant4 = "geant4"
38-
vecgeom = "vecgeom"
39-
orange = "orange"
37+
HOST = auto() # CPU
38+
DEVICE = auto() # GPU
39+
40+
# Backward compatibility
41+
host = HOST
42+
device = DEVICE
4043

4144

4245
# corecel/Types.hh
43-
class MemSpace(Enum):
44-
"""Memory/execution space."""
46+
class UnitSystem(StrEnum):
47+
CGS = auto()
48+
SI = auto()
49+
CLHEP = auto()
4550

46-
host = "host" # CPU
47-
device = "device" # GPU
51+
# Backward compatibility
52+
cgs = CGS
53+
si = SI
54+
clhep = CLHEP
4855

4956

50-
# corecel/Types.hh
51-
class UnitSystem(Enum):
52-
cgs = "cgs"
53-
si = "si"
54-
clhep = "clhep"
57+
# corecel/io/LoggerTypes.hh
58+
class LogLevel(StrEnum):
59+
"""Minimum verbosity level for logging."""
60+
61+
DEBUG = auto()
62+
INFO = auto()
63+
WARNING = auto()
64+
ERROR = auto()
65+
CRITICAL = auto()
66+
67+
68+
# celer-geo/Types.hh
69+
class GeometryEngine(StrEnum):
70+
"""Geometry model implementation for execution and rendering."""
71+
72+
GEANT4 = auto()
73+
VECGEOM = auto()
74+
ORANGE = auto()
75+
76+
# Backward compatibility
77+
geant4 = GEANT4
78+
vecgeom = VECGEOM
79+
orange = ORANGE
5580

5681

5782
# celer-geo/GeoInput.hh

celerpy/visualize.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def _register_cmaps():
6868

6969

7070
UNIT_LENGTH = {
71-
model.UnitSystem.cgs: "cm",
72-
model.UnitSystem.clhep: "mm",
73-
model.UnitSystem.si: "m",
71+
model.UnitSystem.CGS: "cm",
72+
model.UnitSystem.CLHEP: "mm",
73+
model.UnitSystem.SI: "m",
7474
}
7575

7676

test/test_model.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
from celerpy import model
88

99

10+
def test_enum_lowercase():
11+
# NOTE: no deprecation warning issued :'(
12+
result = model.GeometryEngine.geant4
13+
assert result == model.GeometryEngine.GEANT4
14+
15+
assert model.GeometryEngine("geant4") == model.GeometryEngine.GEANT4
16+
17+
1018
def test_model_setup(tmp_path):
1119
gdml_file = tmp_path / "foo.gdml"
1220
gdml_file.write_text("<gdml />")

test/test_visualize.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
settings.prefix_path = local_path / "mock-prefix"
1616

1717
settings.prefix_path = Path(__file__).parent / "mock-prefix"
18-
settings.log = LogLevel.debug
19-
settings.log_local = LogLevel.warning
2018
settings.g4org_verbose = True
19+
settings.log = LogLevel.DEBUG
20+
settings.log_local = LogLevel.WARNING
2121

2222

2323
def test_CelerGeo():
@@ -27,12 +27,12 @@ def test_CelerGeo():
2727
cg.trace()
2828
(result, img) = cg.trace(
2929
model.ImageInput(upper_right=[1, 1, 0], vertical_pixels=4),
30-
geometry=model.GeometryEngine.orange,
30+
geometry=model.GeometryEngine.ORANGE,
3131
)
3232
assert isinstance(result, model.TraceOutput)
3333
assert img.shape == (4, 4)
3434
assert img.dtype == np.int32
35-
(result, img) = cg.trace(geometry=model.GeometryEngine.orange)
35+
(result, img) = cg.trace(geometry=model.GeometryEngine.ORANGE)
3636
assert isinstance(result, model.TraceOutput)
3737
assert img.shape == (4, 4)
3838
(result, img) = cg.trace(geometry=model.GeometryEngine.geant4)

0 commit comments

Comments
 (0)