Esempio n. 1
0
def evaluate(expr):
    user_deprecation_warning('evaluate() is deprecated: '
                             'please use reframe.utility.sanity.evaluate')

    if isinstance(expr, _DeferredExpression):
        return expr.evaluate()
    else:
        return expr
Esempio n. 2
0
    def __init__(self, callback=None):
        """Create a basic StatefulParser
        callback -- callable to be called when matching criteria are met
        (default None, which is equivalent to reframe.utility.always_true)"""

        user_deprecation_warning(
            'Use of parsers is deprecated. Please refer to the '
            'ReFrame tutorial for the new syntax.'),

        self._is_on = False
        self._callback = callback or always_true
Esempio n. 3
0
    def launcher(self):
        '''See :attr:`launcher_type`.

        .. deprecated:: 3.2
           Please use :attr:`launcher_type` instead.
        '''

        from reframe.core.exceptions import user_deprecation_warning

        user_deprecation_warning("the 'launcher' attribute is deprecated; "
                                 "please use 'launcher_type' instead")
        return self.launcher_type
Esempio n. 4
0
    def __init__(cls, name, bases, namespace, **kwargs):
        super().__init__(name, bases, namespace, **kwargs)

        # Set up the hooks for the pipeline stages based on the _rfm_attach
        # attribute; all dependencies will be resolved first in the post-setup
        # phase if not assigned elsewhere
        hooks = {}
        fn_with_deps = []
        for v in namespace.values():
            if hasattr(v, '_rfm_attach'):
                for phase in v._rfm_attach:
                    try:
                        hooks[phase].append(v)
                    except KeyError:
                        hooks[phase] = [v]

            try:
                if v._rfm_resolve_deps:
                    fn_with_deps.append(v)
            except AttributeError:
                pass

        if fn_with_deps:
            hooks['post_setup'] = fn_with_deps + hooks.get('post_setup', [])

        cls._rfm_pipeline_hooks = hooks
        cls._rfm_disabled_hooks = set()
        cls._final_methods = {v.__name__ for v in namespace.values()
                              if hasattr(v, '_rfm_final')}

        # Add the final functions from its parents
        cls._final_methods.update(*(b._final_methods for b in bases
                                    if hasattr(b, '_final_methods')))

        if hasattr(cls, '_rfm_special_test') and cls._rfm_special_test:
            return

        for v in namespace.values():
            for b in bases:
                if not hasattr(b, '_final_methods'):
                    continue

                if callable(v) and v.__name__ in b._final_methods:
                    msg = (f"'{cls.__qualname__}.{v.__name__}' attempts to "
                           f"override final method "
                           f"'{b.__qualname__}.{v.__name__}'; "
                           f"consider using the pipeline hooks instead")
                    user_deprecation_warning(msg)
Esempio n. 5
0
    def __set__(self, obj, value):
        if value is None and self._allow_none:
            # Call directly Field's __set__() method; no need for further type
            # checking
            Field.__set__(self, obj, value)
            return

        user_deprecation_warning(
            'This syntax for sanity and performance checking is deprecated. '
            'Please have a look in the ReFrame tutorial.')

        # Check first the outer dictionary
        if not self._check_type(value, self._outer_typespec):
            raise FieldError('attempt to set a sanity pattern field '
                             'with an invalid dictionary object')

        # For the inner dictionary, we need special treatment for the '\e'
        # character
        for k, v in value.items():
            # Check the special entry '\e' first
            eof_handler = None
            if '\e' in v.keys():
                eof_handler = v['\e']
                if not callable(eof_handler):
                    raise FieldError("special key '\e' does not "
                                     "refer to a callable")

                # Remove the value temporarily
                del v['\e']

            try:
                if not self._check_type(v, self._inner_typespec):
                    raise FieldError('attempt to set a sanity pattern field'
                                     'with an invalid dictionary object')
            finally:
                # Restore '\e'
                if eof_handler is not None:
                    v['\e'] = eof_handler

        # All type checking is done; just set the value
        Field.__set__(self, obj, value)
Esempio n. 6
0
    def __set__(self, obj, value):
        self._check_type(value)
        if isinstance(value, tuple):
            user_deprecation_warning(
                "setting a timer field from a tuple is deprecated: "
                "please use a string '<days>d<hours>h<minutes>m<seconds>s'")
            h, m, s = value
            value = datetime.timedelta(hours=h, minutes=m, seconds=s)

        if isinstance(value, str):
            time_match = re.match(
                r'^((?P<days>\d+)d)?'
                r'((?P<hours>\d+)h)?'
                r'((?P<minutes>\d+)m)?'
                r'((?P<seconds>\d+)s)?$', value)
            if not time_match:
                raise ValueError('invalid format for timer field')

            value = datetime.timedelta(
                **{k: int(v)
                   for k, v in time_match.groupdict().items() if v})

        # Call Field's __set__() method, type checking is already performed
        Field.__set__(self, obj, value)
Esempio n. 7
0
def make_deferrable(a):
    user_deprecation_warning('make_deferrable() is deprecated: '
                             'please use reframe.utility.sanity.defer')
    return a
Esempio n. 8
0
    def load_from_dict(self, site_config):
        if not isinstance(site_config, collections.abc.Mapping):
            raise TypeError('site configuration is not a dict')

        # We do all the necessary imports here and not on the top, because we
        # want to remove import time dependencies
        import reframe.core.environments as m_env
        from reframe.core.systems import System, SystemPartition

        sysconfig = site_config.get('systems', None)
        envconfig = site_config.get('environments', None)
        modes = site_config.get('modes', {})

        if not sysconfig:
            raise ValueError('no entry for systems was found')

        if not envconfig:
            raise ValueError('no entry for environments was found')

        # Convert envconfig to a ScopedDict
        try:
            envconfig = fields.ScopedDict(envconfig)
        except TypeError:
            raise TypeError('environments configuration '
                            'is not a scoped dictionary') from None

        # Convert modes to a `ScopedDict`; note that `modes` will implicitly
        # converted to a scoped dict here, since `self._modes` is a
        # `ScopedDictField`.
        try:
            self._modes = modes
        except TypeError:
            raise TypeError('modes configuration '
                            'is not a scoped dictionary') from None

        def create_env(system, partition, name):
            # Create an environment instance
            try:
                config = envconfig['%s:%s:%s' % (system, partition, name)]
            except KeyError as e:
                raise ConfigError("could not find a definition for `%s'" %
                                  name) from None

            if not isinstance(config, collections.abc.Mapping):
                raise TypeError("config for `%s' is not a dictionary" % name)

            try:
                envtype = m_env.__dict__[config['type']]
                return envtype(name, **config)
            except KeyError:
                raise ConfigError("no type specified for environment `%s'" %
                                  name) from None

        # Populate the systems directory
        for sys_name, config in sysconfig.items():
            if not isinstance(config, dict):
                raise TypeError('system configuration is not a dictionary')

            if not isinstance(config['partitions'], collections.abc.Mapping):
                raise TypeError('partitions must be a dictionary')

            sys_descr = config.get('descr', sys_name)
            sys_hostnames = config.get('hostnames', [])

            # The System's constructor provides also reasonable defaults, but
            # since we are going to set them anyway from the values provided by
            # the configuration, we should set default values here. The stage,
            # output and log directories default to None, since they are going
            # to be set dynamically by the runtime.
            sys_prefix = config.get('prefix', '.')
            sys_stagedir = config.get('stagedir', None)
            sys_outputdir = config.get('outputdir', None)
            sys_perflogdir = config.get('perflogdir', None)
            sys_logdir = config.get('logdir', None)
            sys_resourcesdir = config.get('resourcesdir', '.')
            sys_modules_system = config.get('modules_system', None)

            # Expand variables
            if sys_prefix:
                sys_prefix = os.path.expandvars(sys_prefix)

            if sys_stagedir:
                sys_stagedir = os.path.expandvars(sys_stagedir)

            if sys_outputdir:
                sys_outputdir = os.path.expandvars(sys_outputdir)

            if sys_logdir:
                user_deprecation_warning(
                    "`logdir' attribute in system config is deprecated; "
                    "please use `perflogdir' instead")
                sys_perflogdir = os.path.expandvars(sys_logdir)

            if sys_perflogdir:
                sys_perflogdir = os.path.expandvars(sys_perflogdir)

            if sys_resourcesdir:
                sys_resourcesdir = os.path.expandvars(sys_resourcesdir)

            system = System(name=sys_name,
                            descr=sys_descr,
                            hostnames=sys_hostnames,
                            prefix=sys_prefix,
                            stagedir=sys_stagedir,
                            outputdir=sys_outputdir,
                            perflogdir=sys_perflogdir,
                            resourcesdir=sys_resourcesdir,
                            modules_system=sys_modules_system)
            for part_name, partconfig in config.get('partitions', {}).items():
                if not isinstance(partconfig, collections.abc.Mapping):
                    raise TypeError("partition `%s' not configured "
                                    "as a dictionary" % part_name)

                part_descr = partconfig.get('descr', part_name)
                part_scheduler, part_launcher = self.get_schedsystem_config(
                    partconfig.get('scheduler', 'local+local'))
                part_local_env = m_env.Environment(
                    name='__rfm_env_%s' % part_name,
                    modules=partconfig.get('modules', []),
                    variables=partconfig.get('variables', {}).items())
                part_environs = [
                    create_env(sys_name, part_name, e)
                    for e in partconfig.get('environs', [])
                ]
                part_access = partconfig.get('access', [])
                part_resources = partconfig.get('resources', {})
                part_max_jobs = partconfig.get('max_jobs', 1)
                system.add_partition(
                    SystemPartition(name=part_name,
                                    descr=part_descr,
                                    scheduler=part_scheduler,
                                    launcher=part_launcher,
                                    access=part_access,
                                    environs=part_environs,
                                    resources=part_resources,
                                    local_env=part_local_env,
                                    max_jobs=part_max_jobs))

            self._systems[sys_name] = system
Esempio n. 9
0
 def deprecation_warning(self):
     user_deprecation_warning('feature foo is deprecated')
Esempio n. 10
0
    def __get__(self, obj, objtype):
        if self._op & DeprecatedField.OP_GET:
            user_deprecation_warning(self._message)

        return self._target_field.__get__(obj, objtype)
Esempio n. 11
0
    def __set__(self, obj, value):
        if self._op & DeprecatedField.OP_SET:
            user_deprecation_warning(self._message)

        self._target_field.__set__(obj, value)
Esempio n. 12
0
    def compile(self, **compile_opts):
        """The compilation phase of the regression test pipeline.

        :arg compile_opts: Extra options to be passed to the programming
            environment for compiling the source code of the test.
        :raises reframe.core.exceptions.ReframeError: In case of errors.
        """
        if not self._current_environ:
            raise PipelineError('no programming environment set')

        # Copy the check's resources to the stage directory
        if self.sourcesdir:
            try:
                commonpath = os.path.commonpath(
                    [self.sourcesdir, self.sourcepath])
            except ValueError:
                commonpath = None

            if commonpath:
                self.logger.warn(
                    "sourcepath `%s' seems to be a subdirectory of "
                    "sourcesdir `%s', but it will be interpreted "
                    "as relative to it." % (self.sourcepath, self.sourcesdir))

            if os_ext.is_url(self.sourcesdir):
                self._clone_to_stagedir(self.sourcesdir)
            else:
                self._copy_to_stagedir(
                    os.path.join(self._prefix, self.sourcesdir))

        # Verify the sourcepath and determine the sourcepath in the stagedir
        if (os.path.isabs(self.sourcepath)
                or os.path.normpath(self.sourcepath).startswith('..')):
            raise PipelineError(
                'self.sourcepath is an absolute path or does not point to a '
                'subfolder or a file contained in self.sourcesdir: ' +
                self.sourcepath)

        staged_sourcepath = os.path.join(self._stagedir, self.sourcepath)
        self.logger.debug('Staged sourcepath: %s' % staged_sourcepath)
        if os.path.isdir(staged_sourcepath):
            if not self.build_system:
                # Try to guess the build system
                cmakelists = os.path.join(staged_sourcepath, 'CMakeLists.txt')
                configure_ac = os.path.join(staged_sourcepath, 'configure.ac')
                configure_in = os.path.join(staged_sourcepath, 'configure.in')
                if os.path.exists(cmakelists):
                    self.build_system = 'CMake'
                    self.build_system.builddir = 'rfm_build'
                elif (os.path.exists(configure_ac)
                      or os.path.exists(configure_in)):
                    self.build_system = 'Autotools'
                    self.build_system.builddir = 'rfm_build'
                else:
                    self.build_system = 'Make'

                self.build_system.srcdir = self.sourcepath
        else:
            if not self.build_system:
                self.build_system = 'SingleSource'

            self.build_system.srcfile = self.sourcepath
            self.build_system.executable = self.executable

        if compile_opts:
            user_deprecation_warning(
                'passing options to the compile() method is deprecated; '
                'please use a build system.')

            # Remove source and executable from compile_opts
            compile_opts.pop('source', None)
            compile_opts.pop('executable', None)
            try:
                self.build_system.makefile = compile_opts['makefile']
                self.build_system.options = compile_opts['options']
            except KeyError:
                pass

        # Prepare build job
        build_commands = [
            *self.prebuild_cmd,
            *self.build_system.emit_build_commands(self._current_environ),
            *self.postbuild_cmd
        ]
        environs = [
            self._current_partition.local_env, self._current_environ,
            self._user_environ
        ]
        self._build_job = getscheduler('local')(
            name='rfm_%s_build' % self.name,
            launcher=getlauncher('local')(),
            workdir=self._stagedir)

        with os_ext.change_dir(self._stagedir):
            try:
                self._build_job.prepare(build_commands,
                                        environs,
                                        trap_errors=True)
            except OSError as e:
                raise PipelineError('failed to prepare build job') from e

            self._build_job.submit()
Esempio n. 13
0
 def __get__(self, obj, objtype):
     user_deprecation_warning(self._message)
     return self._target_field.__get__(obj, objtype)
Esempio n. 14
0
 def __set__(self, obj, value):
     user_deprecation_warning(self._message)
     self._target_field.__set__(obj, value)