Source code for sloop


__version__ = "0.1.0"

import os
import re

#: Directory of the python library
SLOOP_PYTHON_DIR = os.path.dirname(__file__)

#: Main sloop dir
SLOOP_DIR = os.path.realpath(os.path.join(SLOOP_PYTHON_DIR, '..'))

#: Root directory of the fortran sources
SLOOP_SRC_DIR = os.path.join(SLOOP_DIR, 'src')

#: Root directory of the templates
SLOOP_TPL_DIR = os.path.join(SLOOP_DIR, 'templates')

#: Sloop data directory
SLOOP_DATA_DIR=os.path.join(SLOOP_DIR,'sloop/data')

_REQUIREMENTS_FILE = os.path.join(
    os.path.dirname(__file__), "..", "requirements.txt"
)

WORKFLOW_INI = os.path.join(
    SLOOP_PYTHON_DIR, "workflow.ini"
)

[docs]class SloopError(Exception): pass
def _parse_requirements_(reqfile): re_match_specs_match = re.compile(r"^(\w+)(\W+.+)?$").match reqs = {} with open(reqfile) as f: for line in f: line = line.strip().strip("\n") if line and not line.startswith("#"): m = re_match_specs_match(line) if m: reqs[m.group(1)] = m.group(2) return reqs
[docs]def show_versions(): """Print the versions of sloop and of some dependencies """ from pkg_resources import get_distribution, DistributionNotFound print("- sloop:", __version__) for package in _parse_requirements_(_REQUIREMENTS_FILE): try: version = get_distribution(package).version except DistributionNotFound: version = "NOT INSTALLED or UKNOWN" print(f"- {package}: {version}")
[docs]def show_sloop_paths(): """Print some internal sloop paths """ for label, path in [("main dir", SLOOP_DIR), ("python lib dir", SLOOP_PYTHON_DIR), ("model src dir", SLOOP_SRC_DIR)]: print("-", label+":", path)
[docs]def show_info(opt_specs=True, exp_dir=None): """Print sloop related info """ print("# VERSIONS") show_versions() print("\n# SLOOP PATHS") show_sloop_paths() if exp_dir: from .env import show_exp_info print("\n# EXPERIMENT DIRECTORY") show_exp_info(exp_dir)