Skip to content

Commit a8cb731

Browse files
authored
Patch release with jpype1 moved to the extra dependencies (#365)
The `jpype1` dependency is not default anymore, and is included in the `cern` and `test` extras. The package itself is now mock-imported in the `timber_extract` module.
1 parent 601fd4c commit a8cb731

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

omc3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
__title__ = "omc3"
1212
__description__ = "An accelerator physics tools package for the OMC team at CERN."
1313
__url__ = "https://github.com/pylhc/omc3"
14-
__version__ = "0.2.3"
14+
__version__ = "0.2.4"
1515
__author__ = "pylhc"
1616
__author_email__ = "[email protected]"
1717
__license__ = "MIT"

omc3/tune_analysis/timber_extract.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import numpy as np
2121
import tfs
22-
from jpype import JException, java
2322

23+
# from jpype import JException, java
2424
from omc3.tune_analysis import constants as const
2525
from omc3.utils import logging_tools
2626
from omc3.utils.mock import cern_network_import
@@ -32,6 +32,7 @@
3232

3333
LOG = logging_tools.get_logger(__name__)
3434
pytimber = cern_network_import("pytimber")
35+
jpype = cern_network_import("jpype")
3536

3637
MAX_RETRIES = 10 # number of retries on retryable exception
3738
AcceptableTimeStamp = NewType("AcceptableTimeStamp", Union[CERNDatetime, int, float])
@@ -60,7 +61,7 @@ def extract_between_times(
6061
t_start: AcceptableTimeStamp,
6162
t_end: AcceptableTimeStamp,
6263
keys: Sequence[str] = None,
63-
names: Dict[str, str] = None
64+
names: Dict[str, str] = None,
6465
) -> tfs.TfsDataFrame:
6566
"""
6667
Extracts data for keys between ``t_start`` and ``t_end`` from ``Timber``.
@@ -90,13 +91,15 @@ def extract_between_times(
9091
try:
9192
# We use timestamps to avoid any confusion with local time
9293
extract_dict = db.get(keys, t_start.timestamp(), t_end.timestamp())
93-
except java.lang.IllegalStateException as e:
94-
raise IOError("Could not get data from Timber, user probably has no access to NXCALS") from e
95-
except JException as e: # Might be a case for retries
96-
if "RetryableException" in str(e) and (tries + 1) < MAX_RETRIES:
94+
except jpype.java.lang.IllegalStateException as java_state_error:
95+
raise IOError(
96+
"Could not get data from Timber, user probably has no access to NXCALS"
97+
) from java_state_error
98+
except jpype.JException as java_exception: # Might be a case for retries
99+
if "RetryableException" in str(java_exception) and (tries + 1) < MAX_RETRIES:
97100
LOG.warning(f"Could not get data from Timber! Trial no {tries + 1} / {MAX_RETRIES}")
98101
continue # will go to the next iteratoin of the loop, so retry
99-
raise IOError("Could not get data from timber!") from e
102+
raise IOError("Could not get data from timber!") from java_exception
100103
else:
101104
break
102105

omc3/utils/mock.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CERNNetworkMockPackage:
2020
actually installed. Designed for packages installable only from inside the CERN network,
2121
that are declared as ``cern`` extra. See module documentation.
2222
"""
23+
2324
def __init__(self, name: str):
2425
self.name = name
2526

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import setuptools
44

5-
65
# The directory containing this file
76
TOPLEVEL_DIR = pathlib.Path(__file__).parent.absolute()
87
ABOUT_FILE = TOPLEVEL_DIR / "omc3" / "__init__.py"
@@ -32,29 +31,30 @@
3231
"uncertainties>=3.1.4",
3332
"optics-functions>=0.1.0",
3433
"turn_by_turn>=0.2.0",
35-
"jpype1>=1.3.0",
3634
]
3735

3836
# Extra dependencies
3937
EXTRA_DEPENDENCIES = {
4038
"cern": [
39+
"jpype1>=1.3.0",
4140
"pytimber>=2.8.0",
4241
],
4342
"test": [
4443
"pytest>=5.2",
4544
"pytest-cov>=2.7",
4645
"pytest-timeout>=1.4",
4746
"hypothesis>=5.0.0",
47+
"jpype1>=1.3.0",
4848
"attrs>=19.2.0",
4949
],
5050
"doc": [
5151
"sphinx",
5252
"travis-sphinx",
53-
"sphinx_rtd_theme"
53+
"sphinx_rtd_theme",
5454
],
5555
}
5656
EXTRA_DEPENDENCIES.update(
57-
{'all': [elem for list_ in EXTRA_DEPENDENCIES.values() for elem in list_]}
57+
{"all": [elem for list_ in EXTRA_DEPENDENCIES.values() for elem in list_]}
5858
)
5959

6060

@@ -85,6 +85,6 @@
8585
"Topic :: Scientific/Engineering :: Visualization",
8686
],
8787
install_requires=DEPENDENCIES,
88-
tests_require=EXTRA_DEPENDENCIES['test'],
88+
tests_require=EXTRA_DEPENDENCIES["test"],
8989
extras_require=EXTRA_DEPENDENCIES,
9090
)

0 commit comments

Comments
 (0)