Skip to content

Commit ee3ae63

Browse files
authored
Merge pull request #99 from Point72/tkp/cc
Switch to ccflow hostname resolver, mountoutputs respect hydra output if set
2 parents a6dce93 + 053d7e9 commit ee3ae63

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

csp_gateway/server/config/base.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ start:
1717
# https://hydra.cc/docs/configure_hydra/job/
1818
hydra:
1919
run:
20-
dir: outputs/${oc.env:HOSTNAME,localhost}_${hydra.job.name}/${now:%Y-%m-%d}/${now:%H-%M-%S}
20+
dir: outputs/${hostname:}_${hydra.job.name}/${now:%Y-%m-%d}/${now:%H-%M-%S}

csp_gateway/server/config/gateway/demo.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ port: ???
77
modules:
88
example_module:
99
_target_: csp_gateway.server.demo.simple.ExampleModule
10+
mount_outputs:
11+
_target_: csp_gateway.MountOutputsFolder
1012
mount_perspective_tables:
1113
_target_: csp_gateway.MountPerspectiveTables
1214
update_interval: 00:00:01
@@ -21,6 +23,7 @@ gateway:
2123
UI: True
2224
modules:
2325
- /modules/example_module
26+
- /modules/mount_outputs
2427
- /modules/mount_perspective_tables
2528
- /modules/mount_rest_routes
2629
channels:

csp_gateway/server/demo/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from csp_gateway import (
55
Gateway,
66
GatewaySettings,
7+
MountOutputsFolder,
78
MountPerspectiveTables,
89
MountRestRoutes,
910
)
@@ -19,6 +20,7 @@
1920
settings=GatewaySettings(),
2021
modules=[
2122
ExampleModule(),
23+
MountOutputsFolder(),
2224
MountPerspectiveTables(),
2325
MountRestRoutes(force_mount_all=True),
2426
],

csp_gateway/server/modules/web/outputs.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import os
22
import os.path
3+
from typing import Optional
34

45
from fastapi import HTTPException, Request
56
from fastapi.responses import HTMLResponse, StreamingResponse
7+
from hydra.core.hydra_config import HydraConfig
68

79
try:
810
# conditional on libmagic being installed on the machine
@@ -17,9 +19,14 @@
1719

1820

1921
class MountOutputsFolder(GatewayModule):
22+
dir: Optional[str] = None
23+
2024
def connect(self, channels: GatewayChannels) -> None:
21-
# NO-OP
22-
...
25+
if self.dir is None:
26+
if HydraConfig.initialized():
27+
self.dir = os.path.abspath(os.path.join(HydraConfig.get().runtime.output_dir, "..", "..", ".."))
28+
else:
29+
self.dir = os.path.abspath(os.path.join(os.getcwd(), "outputs"))
2330

2431
def rest(self, app: GatewayWebApp) -> None:
2532
app_router = app.get_router("app")
@@ -32,11 +39,10 @@ def browse_logs(full_path: str, request: Request):
3239
This endpoint is a small webpage for browsing the [hydra](https://github.com/facebookresearch/hydra)
3340
output logs and configuration settings of the running application.
3441
"""
35-
outputs_dir = os.path.join(os.getcwd(), "outputs")
36-
file_or_dir = outputs_dir
42+
file_or_dir = self.dir
3743
if full_path:
3844
file_or_dir = os.path.join(file_or_dir, full_path)
39-
if os.path.abspath(file_or_dir).startswith(outputs_dir) and os.path.exists(file_or_dir):
45+
if os.path.abspath(file_or_dir).startswith(self.dir) and os.path.exists(file_or_dir):
4046
if os.path.isdir(file_or_dir):
4147
files = os.listdir(file_or_dir)
4248
files_paths = sorted([f"{request.url._url}/{f}".replace("outputs//", "outputs/") for f in files])

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ develop = [
5959
]
6060
server = [
6161
"atomic-counter>=0.1.3",
62-
"ccflow>=0.5.2,<1",
62+
"ccflow>=0.5.9,<1",
6363
"colorlog",
6464
"csp>=0.8.0,<1",
6565
"deprecation",
@@ -70,7 +70,7 @@ server = [
7070
"janus",
7171
"omegaconf",
7272
"orjson",
73-
"perspective-python>=3.3,!=3.4.0,<4",
73+
"perspective-python>=3.7,<4",
7474
"psutil",
7575
"pyarrow",
7676
"pydantic>=2",

0 commit comments

Comments
 (0)