def __configure_core_element__(self, kwargs): # type: (dict) -> None """ Include the registering info related to @constraint. IMPORTANT! Updates self.kwargs[CORE_ELEMENT_KEY]. :param kwargs: Current keyword arguments to be updated with the core element information. :return: None """ if __debug__: logger.debug("Configuring @constraint core element.") if CORE_ELEMENT_KEY in kwargs: # Core element has already been created in a higher level decorator # (e.g. @implements and @compss) kwargs[CORE_ELEMENT_KEY].set_impl_constraints(self.kwargs) else: # @constraint is in the top of the decorators stack. # Instantiate a new core element object, update it and include # it into kwarg core_element = CE() core_element.set_impl_constraints(self.kwargs) kwargs[CORE_ELEMENT_KEY] = core_element # Set as configured self.core_element_configured = True
def software_f(*args, **kwargs): # type: (*typing.Any, **typing.Any) -> typing.Any if not self.scope or not context.in_master(): # Execute the software as with PyCOMPSs so that sequential # execution performs as parallel. # To disable: raise Exception(not_in_pycompss(BINARY)) return user_function(*args, **kwargs) if __debug__: logger.debug("Executing software_f wrapper.") if self.constraints is not None: core_element = CE() core_element.set_impl_constraints(self.constraints) kwargs[CORE_ELEMENT_KEY] = core_element if self.container is not None: _func = str(user_function.__name__) impl_type = IMPL_CONTAINER impl_signature = '.'.join((impl_type, _func)) ce = kwargs.get(CORE_ELEMENT_KEY, CE()) impl_args = [self.container[ENGINE], # engine self.container[IMAGE], # image UNASSIGNED, # internal_type UNASSIGNED, # internal_binary UNASSIGNED, # internal_func UNASSIGNED, # working_dir UNASSIGNED] # fail_by_ev ce.set_impl_type(impl_type) ce.set_impl_signature(impl_signature) ce.set_impl_type_args(impl_args) kwargs[CORE_ELEMENT_KEY] = ce if self.decor: decorator = self.decor def decor_f(): def f(): ret = decorator(**self.config_args) return ret(user_function)(*args, **kwargs) return f() return decor_f() else: # It's a PyCOMPSs task with only @task and @software decorators return user_function(*args, **kwargs)
def test_core_element(): signature = "my_signature" impl_signature = "my_impl_signature" impl_constraints = "impl_constraints" impl_type = "impl_type" impl_io = "impl_io" impl_type_args = "impl_type_args" core_element = CE(signature, impl_signature, impl_constraints, impl_type, impl_io, impl_type_args) # Check signature result = core_element.get_ce_signature() assert result == signature, ERROR_SIGNATURE new_signature = "my_new_signature" core_element.set_ce_signature(new_signature) result = core_element.get_ce_signature() assert result == new_signature, ERROR_SIGNATURE # Check impl_signature result = core_element.get_impl_signature() assert result == impl_signature, ERROR_IMPL_SIGNATURE new_impl_signature = "my_new_impl_signature" core_element.set_impl_signature(new_impl_signature) result = core_element.get_impl_signature() assert result == new_impl_signature, ERROR_IMPL_SIGNATURE # Check impl_constraints result = core_element.get_impl_constraints() assert result == impl_constraints, ERROR_IMPL_CONSTRAINTS new_impl_constraints = {"my_new_impl_constraints": "value"} core_element.set_impl_constraints(new_impl_constraints) result = core_element.get_impl_constraints() assert result == new_impl_constraints, ERROR_IMPL_CONSTRAINTS # Check impl_type result = core_element.get_impl_type() assert result == impl_type, ERROR_IMPL_TYPE new_impl_type = "my_new_impl_type" core_element.set_impl_type(new_impl_type) result = core_element.get_impl_type() assert result == new_impl_type, ERROR_IMPL_TYPE # Check impl_io result = core_element.get_impl_io() assert result == impl_io, ERROR_IMPL_IO new_impl_io = "my_new_impl_io" core_element.set_impl_io(new_impl_io) result = core_element.get_impl_io() assert result == new_impl_io, ERROR_IMPL_IO # Check impl_type_args result = core_element.get_impl_type_args() assert result == impl_type_args, ERROR_IMPL_TYPE_ARGS new_impl_type_args = "my_new_impl_type_args" core_element.set_impl_type_args(new_impl_type_args) result = core_element.get_impl_type_args() assert result == new_impl_type_args, ERROR_IMPL_TYPE_ARGS # Check representation representation = core_element.__repr__() assert isinstance(representation, str), "ERROR: Received wrong representation type." # noqa: E501 expected = "CORE ELEMENT: \n" \ "\t - CE signature : my_new_signature\n" \ "\t - Impl. signature : my_new_impl_signature\n" \ "\t - Impl. constraints: my_new_impl_constraints:value;\n" \ "\t - Impl. type : my_new_impl_type\n" \ "\t - Impl. io : my_new_impl_io\n" \ "\t - Impl. type args : my_new_impl_type_args" assert representation == expected, "ERROR: Wrong representation." # Reset core_element.reset() # Check again representation representation = core_element.__repr__() assert isinstance(representation, str), "ERROR: Received wrong representation type." # noqa: E501 expected = "CORE ELEMENT: \n" \ "\t - CE signature : None\n" \ "\t - Impl. signature : None\n" \ "\t - Impl. constraints: None\n" \ "\t - Impl. type : None\n" \ "\t - Impl. io : None\n" \ "\t - Impl. type args : None" assert representation == expected, "ERROR: Wrong empty representation."