Skip to content

Commit 8755aab

Browse files
committed
fix: conda manager prints output live to shell
1 parent 69db5bd commit 8755aab

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

floatcsep/environments.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,18 @@ def run_command(self, command):
276276
cmd = [
277277
"bash",
278278
"-c",
279-
f"{self.package_manager} run -n {self.env_name} {command}",
279+
f"{self.package_manager} run --live-stream -n {self.env_name} {command}",
280280
]
281+
281282
process = subprocess.Popen(
282283
cmd,
283284
stdout=subprocess.PIPE,
284285
stderr=subprocess.STDOUT,
285286
universal_newlines=True,
286287
)
287288
for line in process.stdout:
288-
log.info(f"[{self.base_name}]: {line[:-1]}")
289+
stripped_line = line.strip()
290+
log.info(f'[{self.base_name}]: ' + stripped_line)
289291
process.wait()
290292

291293

floatcsep/model.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ def create_forecast(self, tstring: str, **kwargs) -> None:
7575
"""Creates a forecast based on the model's logic."""
7676
pass
7777

78-
def get_source(
79-
self, zenodo_id: int = None, giturl: str = None, **kwargs
80-
) -> None:
78+
def get_source(self, zenodo_id: int = None, giturl: str = None, **kwargs) -> None:
8179
"""
8280
Search, download or clone the model source in the filesystem, zenodo.
8381
@@ -108,14 +106,16 @@ def get_source(
108106
elif giturl:
109107
log.info(f"Retrieving model {self.name} from git url: " f"{giturl}")
110108
try:
111-
from_git(giturl, self.registry.dir if self.registry.fmt else self.registry("path"), **kwargs)
109+
from_git(
110+
giturl,
111+
self.registry.dir if self.registry.fmt else self.registry("path"),
112+
**kwargs,
113+
)
112114
except (git.NoSuchPathError, git.CommandError) as msg:
113115
raise git.NoSuchPathError(f"git url was not found {msg}")
114116
else:
115117
raise FileNotFoundError("Model has no path or identified")
116118

117-
118-
119119
if not os.path.exists(self.registry.dir) or not os.path.exists(self.registry("path")):
120120
raise FileNotFoundError(
121121
f"Directory '{self.registry.dir}' or file {self.registry}' do not exist. "
@@ -165,7 +165,7 @@ def iter_attr(val):
165165
]
166166

167167
dict_walk = {i: j for i, j in list_walk}
168-
dict_walk['path'] = dict_walk.pop('registry')
168+
dict_walk["path"] = dict_walk.pop("registry")
169169

170170
return {self.name: iter_attr(dict_walk)}
171171

@@ -223,17 +223,14 @@ def stage(self, timewindows: Sequence[Sequence[datetime]] = None) -> None:
223223
224224
"""
225225

226-
if self.force_stage or not self.registry.fileexists('path'):
226+
if self.force_stage or not self.registry.fileexists("path"):
227227
os.makedirs(self.registry.dir, exist_ok=True)
228228
self.get_source(self.zenodo_id, self.giturl, branch=self.repo_hash)
229229

230230
if self.store_db:
231231
self.init_db()
232232

233-
self.registry.build_tree(
234-
timewindows=timewindows,
235-
model_class=self.__class__.__name__
236-
)
233+
self.registry.build_tree(timewindows=timewindows, model_class=self.__class__.__name__)
237234

238235
def init_db(self, dbpath: str = "", force: bool = False) -> None:
239236
"""
@@ -377,7 +374,6 @@ def __init__(
377374

378375
self.registry = ForecastRegistry(kwargs.get("workdir", os.getcwd()), model_path)
379376
self.build = kwargs.get("build", None)
380-
self.run_prefix = ""
381377

382378
if self.func:
383379
self.environment = EnvironmentFactory.get_env(
@@ -393,7 +389,7 @@ def stage(self, timewindows=None) -> None:
393389
- Initialize database
394390
- Run model quality assurance (unit tests, runnable from floatcsep)
395391
"""
396-
if self.force_stage or not self.registry.fileexists('path'):
392+
if self.force_stage or not self.registry.fileexists("path"):
397393
os.makedirs(self.registry.dir, exist_ok=True)
398394
self.get_source(self.zenodo_id, self.giturl, branch=self.repo_hash)
399395

@@ -494,6 +490,7 @@ def replace_arg(arg, val, fp):
494490
replace_arg("end_date", end.isoformat(), filepath)
495491
for i, j in kwargs.items():
496492
replace_arg(i, j, filepath)
493+
497494
elif fmt == ".json":
498495
with open(filepath, "r") as file_:
499496
args = json.load(file_)

0 commit comments

Comments
 (0)