diff --git a/main.py b/main.py index 56ce50c3..b158a089 100644 --- a/main.py +++ b/main.py @@ -3,18 +3,21 @@ from qgate.uc.uc101 import UC101 from qgate.uc import ucsetup, ucoutput - -if __name__ == '__main__': - +def test(): setup= ucsetup.UCSetup("0-size-100", ["qgate-sln-mlrun-private.env", "qgate-sln-mlrun.env"]) ucoutput.UCOutput(setup) aa=UC101(setup) + aa.exec() - # sln = qgate.Solution("0-size-100", - # ["qgate-sln-mlrun-private.env", "qgate-sln-mlrun.env"]) - # try: - # sln.create(force=True) - # finally: - # sln.delete() +if __name__ == '__main__': + +# test() + + sln = qgate.Solution("0-size-100", + ["qgate-sln-mlrun-private.env", "qgate-sln-mlrun.env"]) + try: + sln.create(force=True) + finally: + sln.delete() diff --git a/qgate/__init__.py b/qgate/__init__.py index 35c7ab00..2bd13033 100644 --- a/qgate/__init__.py +++ b/qgate/__init__.py @@ -1 +1,2 @@ -# info \ No newline at end of file +# info +from .version import __version__ \ No newline at end of file diff --git a/qgate/__pycache__/__init__.cpython-39.pyc b/qgate/__pycache__/__init__.cpython-39.pyc index 15b4bfd3..07749e24 100644 Binary files a/qgate/__pycache__/__init__.cpython-39.pyc and b/qgate/__pycache__/__init__.cpython-39.pyc differ diff --git a/qgate/uc/__init__.py b/qgate/uc/__init__.py index 35c7ab00..a22946c0 100644 --- a/qgate/uc/__init__.py +++ b/qgate/uc/__init__.py @@ -1 +1,2 @@ -# info \ No newline at end of file +# info +from ..version import __version__ diff --git a/qgate/uc/uc101.py b/qgate/uc/uc101.py index 3fdd62df..e874556d 100644 --- a/qgate/uc/uc101.py +++ b/qgate/uc/uc101.py @@ -22,7 +22,7 @@ def desc(self): def exec(self): # create projects - dir=os.path.join(os.getcwd(), self._model_definition, "01-model", "01-project", "*.json") + dir=os.path.join(os.getcwd(), self.setup.model_definition, "01-model", "01-project", "*.json") for file in glob.glob(dir): with open(file, "r") as json_file: json_content = json.load(json_file) diff --git a/qgate/uc/ucbase.py b/qgate/uc/ucbase.py index 6813a6c3..35560b88 100644 --- a/qgate/uc/ucbase.py +++ b/qgate/uc/ucbase.py @@ -22,10 +22,21 @@ def __init__(self, setup: UCSetup, name): self._setup=setup self._name=name + @property + def setup(self): + return self._setup + @property def desc(self): raise NotImplemented() + @property + def name(self): + return self._name + + def exec(self): + raise NotImplemented() + def _get_json_header(self, json_content): """ Get common header from config files @@ -40,10 +51,6 @@ def _get_json_header(self, json_content): lbls = None if json_content.get('labels') is None else json_content.get('labels') return name, desc, lbls, kind - @property - def name(self): - return self._name - @staticmethod def str2bool(v): return v.lower() in ("yes", "true", "t", "1") diff --git a/qgate/uc/ucoutput.py b/qgate/uc/ucoutput.py index 134d6949..b7c0b078 100644 --- a/qgate/uc/ucoutput.py +++ b/qgate/uc/ucoutput.py @@ -1,7 +1,10 @@ import datetime +import multiprocessing import os, platform, sys import mlrun from qgate.uc.ucsetup import UCSetup +from contextlib import suppress +from qgate.version import __version__ class Singleton (type): _instances = {} @@ -26,24 +29,53 @@ def __init__(self, setup: UCSetup): self._file = open(os.path.join(self._setup.model_output, "qgate-sln-mlrun.txt"), 'w+t') self._headr() + self._footer() def __del__(self): + self._footer() self._file.close() def _headr(self): - self._print(datetime.datetime.now().isoformat()) - self._print() - - self._print("MLRun: " + mlrun.get_version() + " (https://docs.mlrun.org/en/latest/change-log/index.html)") - self._print("Python: " + sys.version) - self._print("System: " + platform.system() + " " + platform.version() + " (" + platform.platform() + ")") + self._print("QGate version: " + __version__) + self._print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')) + + def _footer(self): + total, free = self._memory() + self._print("Host: " + self._host()) + self._print("RAM total/free: " + total + "/" + free) + self._print("CPU: " + str(multiprocessing.cpu_count())) + self._print("-----------------------") + self._print("MLRun: " + mlrun.get_version() + " (https://docs.mlrun.org/en/latest/change-log/index.html)") + self._print("Python: " + sys.version) + self._print("System: " + platform.system() + " " + platform.version() + " (" + platform.platform() + ")") self._print("Platform: " + platform.machine()+ " (" + platform.processor() + ")") + self._print("-----------------------") - self._print() - - self._print("DIR = " + os.getcwd()) + self._print("DIR: '" + os.getcwd() + "'") self._print(str(self._setup).replace('\n',"\n" + UCOutput.COMMENT)) + def _memory(self): + + mem_total, mem_free = "", "" + with suppress(Exception): + import psutil + + values = psutil.virtual_memory() + mem_total = f"{round(values.total / (1073741824), 1)} GB" + mem_free = f"{round(values.free / (1073741824), 1)} GB" + return mem_total, mem_free + + def _host(self): + """ Return information about the host in format (host_name/ip addr)""" + + host = "" + with suppress(Exception): + import socket + + host_name = socket.gethostname() + ip = socket.gethostbyname(host_name) + host = f"{host_name}/{ip}" + return host def print(self, uc_name, *args, **kwargs): self._print(uc_name + str.format(args, kwargs), False) diff --git a/qgate/uc/ucsetup.py b/qgate/uc/ucsetup.py index 24f508c8..88af57fd 100644 --- a/qgate/uc/ucsetup.py +++ b/qgate/uc/ucsetup.py @@ -25,9 +25,13 @@ def __init__(self, data_size, mlrun_env_file: list[str]): def __str__(self): ret="" for key in self._variables.keys(): - ret+=key+ " = "+ "'" + self._variables[key] + "'\n" - return ret + ret+=key+ ": "+ "'" + self._variables[key] + "'\n" + return ret[:-1] @property def model_output(self): - return self._model_output \ No newline at end of file + return self._model_output + + @property + def model_definition(self): + return self._model_definition \ No newline at end of file diff --git a/qgate/version.py b/qgate/version.py new file mode 100644 index 00000000..d0d640ee --- /dev/null +++ b/qgate/version.py @@ -0,0 +1,3 @@ +# Store the version here so: + +__version__ = '0.0.4' \ No newline at end of file