Skip to content

Commit 589fce7

Browse files
committed
Replaced 'router.url_path_for()' instances in client with use of our 'url_path_for()' function instead; this will keep server and client-side dependencies separate
1 parent 55e71d8 commit 589fce7

File tree

7 files changed

+83
-107
lines changed

7 files changed

+83
-107
lines changed

src/murfey/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from murfey.client.instance_environment import MurfeyInstanceEnvironment
2727
from murfey.client.tui.app import MurfeyTUI
2828
from murfey.client.tui.status_bar import StatusBar
29-
from murfey.server.api.session_control import router as session_router
29+
from murfey.util.api import url_path_for
3030
from murfey.util.client import authorised_requests, read_config
3131
from murfey.util.models import Visit
3232

@@ -38,7 +38,7 @@
3838
def _get_visit_list(api_base: ParseResult, instrument_name: str):
3939
proxy_path = api_base.path.rstrip("/")
4040
get_visits_url = api_base._replace(
41-
path=f"{proxy_path}{session_router.url_path_for('get_current_visits', instrument_name=instrument_name)}"
41+
path=f"{proxy_path}{url_path_for('session_control.router', 'get_current_visits', instrument_name=instrument_name)}"
4242
)
4343
server_reply = requests.get(get_visits_url.geturl())
4444
if server_reply.status_code != 200:

src/murfey/client/contexts/spa.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
MurfeyID,
1616
MurfeyInstanceEnvironment,
1717
)
18-
from murfey.server.api.file_manip import router as file_manip_router
19-
from murfey.server.api.session_control import router as session_router
20-
from murfey.server.api.session_control import spa_router as session_spa_router
21-
from murfey.server.api.workflow import spa_router as workflow_spa_router
18+
from murfey.util.api import url_path_for
2219
from murfey.util.client import (
2320
authorised_requests,
2421
capture_get,
@@ -266,7 +263,7 @@ def gather_metadata(
266263
binning_factor = 1
267264
if environment:
268265
server_config_response = capture_get(
269-
f"{str(environment.url.geturl())}{session_router.url_path_for('machine_info_by_instrument', instrument_name=environment.instrument_name)}"
266+
f"{str(environment.url.geturl())}{url_path_for('session_control.router', 'machine_info_by_instrument', instrument_name=environment.instrument_name)}"
270267
)
271268
if server_config_response is None:
272269
return None
@@ -430,7 +427,7 @@ def _position_analysis(
430427
local_atlas_path,
431428
grid_square=str(grid_square),
432429
)[str(grid_square)]
433-
gs_url = f"{str(environment.url.geturl())}{session_spa_router.url_path_for('register_grid_square', session_id=environment.murfey_session, gsid=grid_square)}"
430+
gs_url = f"{str(environment.url.geturl())}{url_path_for('session_control.spa_router', 'register_grid_square', session_id=environment.murfey_session, gsid=grid_square)}"
434431
gs = grid_square_data(
435432
grid_square_metadata_file,
436433
grid_square,
@@ -471,7 +468,7 @@ def _position_analysis(
471468
)
472469
foil_hole = foil_hole_from_file(transferred_file)
473470
if foil_hole not in self._foil_holes[grid_square]:
474-
fh_url = f"{str(environment.url.geturl())}{session_spa_router.url_path_for('register_foil_hole', session_id=environment.murfey_session, gs_name=grid_square)}"
471+
fh_url = f"{str(environment.url.geturl())}{url_path_for('session_control.spa_router', 'register_foil_hole', session_id=environment.murfey_session, gs_name=grid_square)}"
475472
if environment.murfey_session is not None:
476473
fh = foil_hole_data(
477474
grid_square_metadata_file,
@@ -584,7 +581,7 @@ def post_transfer(
584581
eer_fractionation_file = None
585582
if file_transferred_to.suffix == ".eer":
586583
response = capture_post(
587-
f"{str(environment.url.geturl())}{file_manip_router.url_path_for('write_eer_fractionation_file', visit_name=environment.visit, session_id=environment.murfey_session)}",
584+
f"{str(environment.url.geturl())}{url_path_for('file_manip.router', 'write_eer_fractionation_file', visit_name=environment.visit, session_id=environment.murfey_session)}",
588585
json={
589586
"eer_path": str(file_transferred_to),
590587
"fractionation": environment.data_collection_parameters[
@@ -613,7 +610,7 @@ def post_transfer(
613610
)
614611
foil_hole = None
615612

616-
preproc_url = f"{str(environment.url.geturl())}{workflow_spa_router.url_path_for('request_spa_preprocessing', visit_name=environment.visit, session_id=environment.murfey_session)}"
613+
preproc_url = f"{str(environment.url.geturl())}{url_path_for('workflow.spa_router', 'request_spa_preprocessing', visit_name=environment.visit, session_id=environment.murfey_session)}"
617614
preproc_data = {
618615
"path": str(file_transferred_to),
619616
"description": "",

src/murfey/client/contexts/spa_metadata.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
from murfey.client.context import Context
99
from murfey.client.contexts.spa import _file_transferred_to, _get_source
1010
from murfey.client.instance_environment import MurfeyInstanceEnvironment, SampleInfo
11-
from murfey.server.api.session_control import spa_router as session_spa_router
12-
from murfey.server.api.workflow import router as workflow_router
11+
from murfey.util.api import url_path_for
1312
from murfey.util.client import (
1413
authorised_requests,
1514
capture_post,
@@ -168,7 +167,7 @@ def post_transfer(
168167
environment.samples[source] = SampleInfo(
169168
atlas=Path(partial_path), sample=sample
170169
)
171-
url = f"{str(environment.url.geturl())}{workflow_router.url_path_for('register_dc_group', visit_name=environment.visit, session_id=environment.murfey_session)}"
170+
url = f"{str(environment.url.geturl())}{url_path_for('workflow.router', 'register_dc_group', visit_name=environment.visit, session_id=environment.murfey_session)}"
172171
dcg_search_dir = "/".join(
173172
p for p in transferred_file.parent.parts if p != environment.visit
174173
)
@@ -204,7 +203,7 @@ def post_transfer(
204203
for gs, pos_data in gs_pix_positions.items():
205204
if pos_data:
206205
capture_post(
207-
f"{str(environment.url.geturl())}{session_spa_router.url_path_for('register_grid_square', session_id=environment.murfey_session, gsid=gs)}",
206+
f"{str(environment.url.geturl())}{url_path_for('session_control.spa_router', 'register_grid_square', session_id=environment.murfey_session, gsid=gs)}",
208207
json={
209208
"tag": dcg_tag,
210209
"x_location": pos_data[0],
@@ -223,7 +222,7 @@ def post_transfer(
223222
and environment
224223
):
225224
# Make sure we have a data collection group before trying to register grid square
226-
url = f"{str(environment.url.geturl())}{workflow_router.url_path_for('register_dc_group', visit_name=environment.visit, session_id=environment.murfey_session)}"
225+
url = f"{str(environment.url.geturl())}{url_path_for('workflow.router', 'register_dc_group', visit_name=environment.visit, session_id=environment.murfey_session)}"
227226
dcg_search_dir = "/".join(
228227
p
229228
for p in transferred_file.parent.parent.parts
@@ -272,7 +271,7 @@ def post_transfer(
272271
visitless_source = str(visitless_source_images_dirs[-1])
273272

274273
if fh_positions:
275-
gs_url = f"{str(environment.url.geturl())}{session_spa_router.url_path_for('register_grid_square', session_id=environment.murfey_session, gsid=gs_name)}"
274+
gs_url = f"{str(environment.url.geturl())}{url_path_for('session_control.spa_router', 'register_grid_square', session_id=environment.murfey_session, gsid=gs_name)}"
276275
gs_info = grid_square_data(
277276
transferred_file,
278277
int(gs_name),
@@ -297,7 +296,7 @@ def post_transfer(
297296

298297
for fh, fh_data in fh_positions.items():
299298
capture_post(
300-
f"{str(environment.url.geturl())}{session_spa_router.url_path_for('register_foil_hole', session_id=environment.murfey_session, gs_name=gs_name)}",
299+
f"{str(environment.url.geturl())}{url_path_for('session_control.spa_router', 'register_foil_hole', session_id=environment.murfey_session, gs_name=gs_name)}",
301300
json={
302301
"name": fh,
303302
"x_location": fh_data.x_location,

src/murfey/client/contexts/tomo.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
MurfeyID,
1818
MurfeyInstanceEnvironment,
1919
)
20-
from murfey.server.api.file_manip import router as file_manip_router
21-
from murfey.server.api.session_control import router as session_router
22-
from murfey.server.api.workflow import router as workflow_router
23-
from murfey.server.api.workflow import tomo_router as workflow_tomo_router
20+
from murfey.util.api import url_path_for
2421
from murfey.util.client import (
2522
authorised_requests,
2623
capture_post,
@@ -113,7 +110,7 @@ def register_tomography_data_collections(
113110
)
114111
return
115112
try:
116-
dcg_url = f"{str(environment.url.geturl())}{workflow_router.url_path_for('register_dc_group', visit_name=environment.visit, session_id=environment.murfey_session)}"
113+
dcg_url = f"{str(environment.url.geturl())}{url_path_for('workflow.router', 'register_dc_group', visit_name=environment.visit, session_id=environment.murfey_session)}"
117114
dcg_data = {
118115
"experiment_type": "tomo",
119116
"experiment_type_id": 36,
@@ -125,7 +122,7 @@ def register_tomography_data_collections(
125122

126123
for tilt_series in self._tilt_series.keys():
127124
if tilt_series not in self._tilt_series_with_pjids:
128-
dc_url = f"{str(environment.url.geturl())}{workflow_router.url_path_for('start_dc', visit_name=environment.visit, session_id=environment.murfey_session)}"
125+
dc_url = f"{str(environment.url.geturl())}{url_path_for('workflow.router', 'start_dc', visit_name=environment.visit, session_id=environment.murfey_session)}"
129126
dc_data = {
130127
"experiment_type": "tomography",
131128
"file_extension": file_extension,
@@ -161,7 +158,7 @@ def register_tomography_data_collections(
161158
)
162159
capture_post(dc_url, json=dc_data)
163160

164-
proc_url = f"{str(environment.url.geturl())}{workflow_router.url_path_for('register_proc', visit_name=environment.visit, session_id=environment.murfey_session)}"
161+
proc_url = f"{str(environment.url.geturl())}{url_path_for('workflow.router', 'register_proc', visit_name=environment.visit, session_id=environment.murfey_session)}"
165162
for recipe in ("em-tomo-preprocess", "em-tomo-align"):
166163
capture_post(
167164
proc_url,
@@ -266,7 +263,7 @@ def _add_tilt(
266263
f"Tilt series {tilt_series} was previously thought complete but now {file_path} has been seen"
267264
)
268265
self._completed_tilt_series.remove(tilt_series)
269-
rerun_url = f"{str(environment.url.geturl())}{workflow_tomo_router.url_path_for('register_tilt_series_for_rerun', visit_name=environment.visit)}"
266+
rerun_url = f"{str(environment.url.geturl())}{url_path_for('workflow.tomo_router', 'register_tilt_series_for_rerun', visit_name=environment.visit)}"
270267
rerun_data = {
271268
"session_id": environment.murfey_session,
272269
"tag": tilt_series,
@@ -280,7 +277,7 @@ def _add_tilt(
280277
if not self._tilt_series.get(tilt_series):
281278
logger.info(f"New tilt series found: {tilt_series}")
282279
self._tilt_series[tilt_series] = [file_path]
283-
ts_url = f"{str(environment.url.geturl())}{workflow_tomo_router.url_path_for('register_tilt_series', visit_name=environment.visit)}"
280+
ts_url = f"{str(environment.url.geturl())}{url_path_for('workflow.tomo_router', 'register_tilt_series', visit_name=environment.visit)}"
284281
ts_data = {
285282
"session_id": environment.murfey_session,
286283
"tag": tilt_series,
@@ -309,7 +306,7 @@ def _add_tilt(
309306
self._tilt_series[tilt_series].append(file_path)
310307

311308
if environment:
312-
tilt_url = f"{str(environment.url.geturl())}{workflow_tomo_router.url_path_for('register_tilt', visit_name=environment.visit, session_id=environment.murfey_session)}"
309+
tilt_url = f"{str(environment.url.geturl())}{url_path_for('workflow.tomo_router', 'register_tilt', visit_name=environment.visit, session_id=environment.murfey_session)}"
313310
tilt_data = {
314311
"movie_path": str(file_transferred_to),
315312
"tilt_series_tag": tilt_series,
@@ -320,7 +317,7 @@ def _add_tilt(
320317
eer_fractionation_file = None
321318
if environment.data_collection_parameters.get("num_eer_frames"):
322319
response = requests.post(
323-
f"{str(environment.url.geturl())}{file_manip_router.url_path_for('write_eer_fractionation_file', visit_name=environment.visit, session_id=environment.murfey_session)}",
320+
f"{str(environment.url.geturl())}{url_path_for('file_manip.router', 'write_eer_fractionation_file', visit_name=environment.visit, session_id=environment.murfey_session)}",
324321
json={
325322
"num_frames": environment.data_collection_parameters[
326323
"num_eer_frames"
@@ -335,7 +332,7 @@ def _add_tilt(
335332
},
336333
)
337334
eer_fractionation_file = response.json()["eer_fractionation_file"]
338-
preproc_url = f"{str(environment.url.geturl())}{workflow_tomo_router.url_path_for('request_tomography_preprocessing', visit_name=environment.visit, session_id=environment.murfey_session)}"
335+
preproc_url = f"{str(environment.url.geturl())}{url_path_for('workflow.tomo_router', 'request_tomography_preprocessing', visit_name=environment.visit, session_id=environment.murfey_session)}"
339336
preproc_data = {
340337
"path": str(file_transferred_to),
341338
"description": "",
@@ -495,7 +492,7 @@ def post_transfer(
495492

496493
# Always update the tilt series length in the database after an mdoc
497494
if environment.murfey_session is not None:
498-
length_url = f"{str(environment.url.geturl())}{workflow_tomo_router.url_path_for('register_tile_series_length', session_id=environment.murfey_session)}"
495+
length_url = f"{str(environment.url.geturl())}{url_path_for('workflow.tomo_router', 'register_tile_series_length', session_id=environment.murfey_session)}"
499496
capture_post(
500497
length_url,
501498
json={
@@ -512,7 +509,7 @@ def post_transfer(
512509
f"The following tilt series are considered complete: {completed_tilts} "
513510
f"after {transferred_file}"
514511
)
515-
complete_url = f"{str(environment.url.geturl())}{workflow_tomo_router.url_path_for('register_completed_tilt_series', visit_name=environment.visit, session_id=environment.murfey_session)}"
512+
complete_url = f"{str(environment.url.geturl())}{url_path_for('workflow.tomo_router', 'register_completed_tilt_series', visit_name=environment.visit, session_id=environment.murfey_session)}"
516513
capture_post(
517514
complete_url,
518515
json={
@@ -596,7 +593,7 @@ def gather_metadata(
596593
binning_factor = 1
597594
if environment:
598595
server_config = requests.get(
599-
f"{str(environment.url.geturl())}{session_router.url_path_for('machine_info_by_instrument', instrument_name=environment.instrument_name)}"
596+
f"{str(environment.url.geturl())}{url_path_for('session_control.router', 'machine_info_by_instrument', instrument_name=environment.instrument_name)}"
600597
).json()
601598
if (
602599
server_config.get("superres")

0 commit comments

Comments
 (0)