Skip to content

Commit a4a1d8a

Browse files
authored
Merge pull request #239 from European-XFEL/api-deps
Fix API dependencies
2 parents a9df3af + f51b309 commit a4a1d8a

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

damnit/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Prototype for extracting and showing metadata (AMORE project)"""
22

3-
__version__ = '0.1'
3+
__version__ = '0.1.1'
44

55
from .api import Damnit, RunVariables, VariableData

damnit/backend/supervisord.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,27 @@
88
import configparser
99
from pathlib import Path
1010

11-
from ..util import wait_until
1211
from .db import db_path, DamnitDB
1312

1413

1514
log = logging.getLogger(__name__)
1615

1716

17+
def wait_until(condition, timeout=1):
18+
"""
19+
Re-evaluate `condition()` until it either returns true or we've waited
20+
longer than `timeout`.
21+
"""
22+
slept_for = 0
23+
sleep_interval = 0.2
24+
25+
while slept_for < timeout and not condition():
26+
time.sleep(sleep_interval)
27+
slept_for += sleep_interval
28+
29+
if slept_for >= timeout:
30+
raise TimeoutError("Condition timed out")
31+
1832
def get_supervisord_address(default_port=2322):
1933
"""
2034
Find an available hostname and port for supervisord to bind to.

damnit/util.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,6 @@ class StatusbarStylesheet(Enum):
1414
ERROR = "QStatusBar {background: red; color: white; font-weight: bold;}"
1515

1616

17-
def wait_until(condition, timeout=1):
18-
"""
19-
Re-evaluate `condition()` until it either returns true or we've waited
20-
longer than `timeout`.
21-
"""
22-
slept_for = 0
23-
sleep_interval = 0.2
24-
25-
while slept_for < timeout and not condition():
26-
time.sleep(sleep_interval)
27-
slept_for += sleep_interval
28-
29-
if slept_for >= timeout:
30-
raise TimeoutError("Condition timed out")
31-
32-
3317
def timestamp2str(timestamp):
3418
if timestamp is None or pd.isna(timestamp):
3519
return None

tests/test_api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import subprocess
2+
from pathlib import Path
13
from textwrap import dedent
24

35
import pytest
@@ -109,3 +111,11 @@ def dataset(run):
109111

110112
# Datasets have a internal _damnit attribute that should be removed
111113
assert len(dataset.attrs) == 0
114+
115+
def test_api_dependencies(virtualenv):
116+
package_path = Path(__file__).parent.parent
117+
virtualenv.install_package(package_path, installer="pip install")
118+
119+
# Test that we can import the module successfully and don't accidentally
120+
# depend on other things.
121+
subprocess.run([str(virtualenv.python), "-c", "import damnit"]).check_returncode()

tests/test_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import xarray as xr
1717
import extra_data as ed
1818

19-
from damnit.util import wait_until
19+
from damnit.backend.supervisord import wait_until
2020
from damnit.context import (
2121
ContextFileErrors, ContextFile, PNGData, Results, RunData, get_proposal_path
2222
)

0 commit comments

Comments
 (0)