Skip to content

Commit

Permalink
Add repr to classes, add stage_args support
Browse files Browse the repository at this point in the history
  • Loading branch information
janhybs committed Dec 18, 2018
1 parent 49669b2 commit 0bfc187
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 12 deletions.
8 changes: 7 additions & 1 deletion cihpc/cfg/cfgutil.py
Expand Up @@ -227,7 +227,13 @@ def configure_string(value, vars):
value = str(value)
for key, dtype in matches:
orig = '<%s%s>' % (key, dtype)
value = _configure_object_dict.get(dtype[1:], str)(value.replace(orig, str(_get_property(vars, key))))
func = _configure_object_dict.get(dtype[1:], str)
val = value.replace(orig, str(_get_property(vars, key)))

try:
value = func(val)
except:
value = func()
return value


Expand Down
2 changes: 2 additions & 0 deletions cihpc/core/processing/stage.py
Expand Up @@ -54,6 +54,8 @@ def create(cls, project, stage, variables=None):
return []

variables = variables or project.global_args
variables['__stage__'] = stage.stage_args

if stage.smart_repeat.is_complex() and global_configuration.project_git:
from cihpc.artifacts.modules import CIHPCReportGit

Expand Down
6 changes: 5 additions & 1 deletion cihpc/core/structures/a_project.py
Expand Up @@ -10,4 +10,8 @@ def __bool__(self):
return self._enabled

def __repr__(self):
return '{self.__class__.__name__}{on}'.format(self=self, on='+' if self else '-')
return '{self._enable_str}{self.__class__.__name__}'.format(self=self)

@property
def _enable_str(self):
return '[T]' if self else '[F]'
8 changes: 8 additions & 0 deletions cihpc/core/structures/project.py
Expand Up @@ -39,6 +39,11 @@ def __getattr__(self, attr):
fmt = attr[len(prefix):]
return ('{:%s}' % fmt).format(self.next)

def __repr__(self):
return 'CNT({self.value})'.format(
self=self
)


class EnvGetter(object):

Expand All @@ -48,6 +53,9 @@ def __deepcopy__(self, memo):
def __getattr__(self, attr):
return os.environ.get(attr, None)

def __repr__(self):
return '<ENV>'


class Project(object):
"""
Expand Down
12 changes: 12 additions & 0 deletions cihpc/core/structures/project_stage.py
Expand Up @@ -104,3 +104,15 @@ def __repr__(self):
@property
def repeat(self):
return self.smart_repeat.value

@property
def stage_args(self):
return dict(
name=self.name,
desc=self.description,
repeat=self.smart_repeat,
parallel=self.parallel,
container=self.container,
collect=self.collect,
variables=self.variables,
)
8 changes: 6 additions & 2 deletions cihpc/core/structures/project_step_container.py
Expand Up @@ -20,8 +20,7 @@ def __init__(self, kwargs):
lines to load container module and to exec singularity/docker
"""
super(ProjectStepContainer, self).__init__(kwargs)
if self:
self.exec = self._parse_exec_value(kwargs)
self.exec = self._parse_exec_value(kwargs) if self else None

@staticmethod
def _parse_exec_value(value):
Expand Down Expand Up @@ -51,3 +50,8 @@ def _parse_exec_value(value):

# we assume the docker image name was given
return 'docker run --rm -v $(pwd):$(pwd) -w $(pwd) %s %%s' % value.strip()

def __repr__(self):
return '{self._enable_str}Container({self.exec})'.format(
self=self
)
5 changes: 5 additions & 0 deletions cihpc/core/structures/project_step_parallel.py
Expand Up @@ -26,3 +26,8 @@ def __init__(self, kwargs=False):
self.cpus = determine_cpus(
kwargs.get('cpus', 1)
)

def __repr__(self):
return 'Parallel(cpus={self.cpus}, prop={self.prop})'.format(
self=self
)
5 changes: 5 additions & 0 deletions cihpc/core/structures/project_step_repeat.py
Expand Up @@ -109,3 +109,8 @@ def value(self):

def is_complex(self):
return self.dynamic_value is not None

def __repr__(self):
return 'Repeat(fixed={self.fixed_value}, dynamic={self.dynamic_value})'.format(
self=self
)
16 changes: 8 additions & 8 deletions cihpc/core/structures/project_step_variables.py
Expand Up @@ -4,30 +4,30 @@
import logging
import itertools

from cihpc.core.structures.a_project import ComplexClass


logger = logging.getLogger(__name__)


class ProjectStepVariables(object):
class ProjectStepVariables(ComplexClass):
def __init__(self, kwargs):
if not kwargs:
self._enabled = False
super(ProjectStepVariables, self).__init__(kwargs)

if not self:
values = list()

# single matrix or table
elif isinstance(kwargs, dict):
self._enabled = True
values = [kwargs]

elif isinstance(kwargs, list):
self._enabled = True
values = kwargs
else:
raise ValueError('kwargs must be list or dict')

self.values = values.copy()

def __bool__(self):
return self._enabled

@staticmethod
def _expand_variables(section):
def extract_first(iterator):
Expand Down

0 comments on commit 0bfc187

Please sign in to comment.