Skip to content

Commit

Permalink
change import to after os.environ
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshawkes committed Jan 24, 2024
1 parent df57b95 commit 0367e1b
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions polytope_server/common/datasource/polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import os
import subprocess

import pygribjump
os.environ["GRIBJUMP_HOME"] = "/opt/fdb-gribjump"

import polytope
import tempfile
from polytope_mars.api import PolytopeMars
from polytope_mars.api import features
from pathlib import Path
import yaml

Expand All @@ -47,24 +46,27 @@ def __init__(self, config):
# still need to set up fdb
self.fdb_config = self.config["fdb-config"]

self.non_sliceable = self.config.get("non-sliceable", None)
assert self.non_sliceable is not None

self.check_schema()

# os.environ["FDB5_CONFIG"] = json.dumps(self.fdb_config)
# os.environ["FDB5_HOME"] = self.config.get("fdb_home", "/opt/fdb-gribjump")
os.environ["GRIBJUMP_HOME"] = "/opt/fdb/gribjump"
os.environ["FDB5_CONFIG"] = json.dumps(self.fdb_config)
os.environ["FDB5_HOME"] = self.config.get("fdb_home", "/opt/fdb-gribjump")
# forced change

# if "spaces" in self.fdb_config:
# for space in self.fdb_config["spaces"]:
# for root in space["roots"]:
# os.makedirs(root["path"], exist_ok=True)
if "spaces" in self.fdb_config:
for space in self.fdb_config["spaces"]:
for root in space["roots"]:
os.makedirs(root["path"], exist_ok=True)

# Set up gribjump
self.gribjump_config = self.config["gribjump-config"]
os.makedirs("/home/polytope/gribjump/", exist_ok=True)
with open("/home/polytope/gribjump/config.yaml", "w") as f:
json.dump(self.gribjump_config, f)
os.environ["GRIBJUMP_CONFIG_FILE"] = "/home/polytope/gribjump/config.yaml"
self.gj = pygribjump.GribJump()
# self.gj = pygribjump.GribJump()

# Set up polytope feature extraction library
self.polytope_options = {
Expand All @@ -73,6 +75,7 @@ def __init__(self, config):
},
"date": {"merge": {"with": "time", "linkers": ["T", "00"]}},
"step": {"type_change": "int"},
"number": {"type_change": "int"},
}

logging.info("Set up gribjump")
Expand Down Expand Up @@ -118,7 +121,7 @@ def check_schema(self):

self.fdb_config["schema"] = str(local_path)

@cache(lifetime=500)
@cache(lifetime=5000000)
def git_download_schema(self, remote, branch, git_dir, git_file):
call = "git archive --remote {} {}:{} {} | tar -xO {}".format(
remote, branch, str(git_dir), str(git_file), str(git_file)
Expand All @@ -139,13 +142,15 @@ def retrieve(self, request):

# We take the static config from the match rules of the datasource
self.polytope_config = {}
for k, v in self.match_rules.items():
self.polytope_config[k] = isinstance(v, list) and v[0] or v
for k in self.non_sliceable:
self.polytope_config[k] = r[k]

assert len(self.polytope_config) > 0

logging.info(self.polytope_config)
logging.info(self.polytope_options)
from polytope_mars.api import PolytopeMars
p = PolytopeMars(self.polytope_config, self.polytope_options)
logging.info(p)

self.output = p.extract(r)
self.output = json.dumps(self.output).encode("utf-8")
Expand Down

0 comments on commit 0367e1b

Please sign in to comment.