Skip to content

Commit

Permalink
ft: Created environments module, which handle the creation, staging o…
Browse files Browse the repository at this point in the history
…f conda/pip/docker environments, as well as the running a source code within.

tests: added tests for EnvironmentHandler class and subclasses
build: added packaging as requirement. Harmonized requirements.txt and requirements_dev.txt
  • Loading branch information
pabloitu committed Jul 30, 2024
1 parent c836683 commit 6fa419a
Show file tree
Hide file tree
Showing 10 changed files with 861 additions and 25 deletions.
Empty file.
469 changes: 469 additions & 0 deletions floatcsep/environments.py

Large diffs are not rendered by default.

34 changes: 13 additions & 21 deletions floatcsep/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import json
import logging
import sys
import os
import subprocess
import hashlib
import shutil
import venv
import configparser

from abc import ABC, abstractmethod
from datetime import datetime
from typing import List, Callable, Union, Mapping, Sequence
Expand Down Expand Up @@ -124,9 +130,7 @@ def get_source(
elif giturl:
log.info(f"Retrieving model {self.name} from git url: " f"{giturl}")
try:
from_git(
giturl, self.dir if self.path.fmt else self.path("path"), **kwargs
)
from_git(giturl, self.dir if self.path.fmt else self.path("path"), **kwargs)
except (git.NoSuchPathError, git.CommandError) as msg:
raise git.NoSuchPathError(f"git url was not found {msg}")
else:
Expand Down Expand Up @@ -177,9 +181,7 @@ def iter_attr(val):
return _get_value(val)

list_walk = [
(i, j)
for i, j in sorted(self.__dict__.items())
if not i.startswith("_") and j
(i, j) for i, j in sorted(self.__dict__.items()) if not i.startswith("_") and j
]

dict_walk = {i: j for i, j in list_walk}
Expand Down Expand Up @@ -223,9 +225,7 @@ class TimeIndependentModel(Model):
store_db (bool): flag to indicate whether to store the model in a database.
"""

def __init__(
self, name: str, model_path: str, forecast_unit=1, store_db=False, **kwargs
):
def __init__(self, name: str, model_path: str, forecast_unit=1, store_db=False, **kwargs):
super().__init__(name, model_path, **kwargs)
self.forecast_unit = forecast_unit
self.store_db = store_db
Expand Down Expand Up @@ -289,9 +289,7 @@ def stage(self, timewindows: Union[str, List[datetime]] = None) -> None:

def get_forecast(
self, tstring: Union[str, list] = None, region=None
) -> Union[
GriddedForecast, CatalogForecast, List[GriddedForecast], List[CatalogForecast]
]:
) -> Union[GriddedForecast, CatalogForecast, List[GriddedForecast], List[CatalogForecast]]:
"""
Wrapper that just returns a forecast when requested.
"""
Expand Down Expand Up @@ -333,9 +331,7 @@ def create_forecast(self, tstring: str, **kwargs) -> None:
start_date, end_date = str2timewindow(tstring)
self.forecast_from_file(start_date, end_date, **kwargs)

def forecast_from_file(
self, start_date: datetime, end_date: datetime, **kwargs
) -> None:
def forecast_from_file(self, start_date: datetime, end_date: datetime, **kwargs) -> None:
"""
Generates a forecast from a file, by parsing and scaling it to.
Expand Down Expand Up @@ -461,9 +457,7 @@ def stage(self, timewindows=None) -> None:

def get_forecast(
self, tstring: Union[str, list] = None, region=None
) -> Union[
GriddedForecast, CatalogForecast, List[GriddedForecast], List[CatalogForecast]
]:
) -> Union[GriddedForecast, CatalogForecast, List[GriddedForecast], List[CatalogForecast]]:
"""Wrapper that just returns a forecast, hiding the access method under the hood"""

if isinstance(tstring, str):
Expand Down Expand Up @@ -511,9 +505,7 @@ def create_forecast(self, tstring: str, **kwargs) -> None:
else:
log.info(f"Forecast of {tstring} of model {self.name} already " f"exists")

def forecast_from_func(
self, start_date: datetime, end_date: datetime, **kwargs
) -> None:
def forecast_from_func(self, start_date: datetime, end_date: datetime, **kwargs) -> None:

self.prepare_args(start_date, end_date, **kwargs)
log.info(
Expand Down
3 changes: 1 addition & 2 deletions floatcsep/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ def build_tree(

# set forecast names
fc_files = {
win: join(dirtree["forecasts"], f"{prefix}_{win}.csv")
for win in windows
win: join(dirtree["forecasts"], f"{prefix}_{win}.csv") for win in windows
}

fc_exists = {
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ build-backend = "setuptools.build_meta"
addopts = "--cov=floatcsep"
testpaths = [
"tests",
]
]

[tool.black]
line-length = 96
skip-string-normalization = false
target-version = ["py39", "py310", "py311"]
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ flake8
gitpython
h5py
matplotlib
packaging
pandas
pycsep
pyshp
pyyaml
Expand Down
3 changes: 2 additions & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
numpy
cartopy
black
dateparser
docker
flake8
Expand All @@ -10,9 +11,9 @@ matplotlib
mercantile
mypy
obspy
packaging
pandas
pillow
pyblack
pycsep
pydocstringformatter
pyproj
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ install_requires =
gitpython
h5py
matplotlib
packaging
pandas
pycsep
pyshp
pyyaml
Expand Down Expand Up @@ -55,6 +57,7 @@ dev =
mercantile
mypy
obspy
packaging
pandas
pillow
pycsep
Expand Down
Empty file.
Loading

0 comments on commit 6fa419a

Please sign in to comment.