Exemplo n.º 1
0
    class FieldTester:
        value = fields.DeprecatedField(fields.TypedField('value', int),
                                       'value field is deprecated')
        _value = fields.TypedField('value', int)
        ro = fields.DeprecatedField(fields.TypedField('ro', int),
                                    'value field is deprecated',
                                    fields.DeprecatedField.OP_SET)
        _ro = fields.TypedField('ro', int)
        wo = fields.DeprecatedField(fields.TypedField('wo', int),
                                    'value field is deprecated',
                                    fields.DeprecatedField.OP_GET)

        def __init__(self):
            self._value = 1
            self._ro = 2
            self.wo = 3
Exemplo n.º 2
0
 def create_deprecated(cls,
                       var,
                       message,
                       kind=DEPRECATE_RDWR,
                       from_version='0.0.0'):
     ret = TestVar.__new__(TestVar)
     ret._field = fields.DeprecatedField(var.field, message, kind,
                                         from_version)
     ret._default_value = var._default_value
     return ret
Exemplo n.º 3
0
class ContainerPlatform(abc.ABC):
    '''The abstract base class of any container platform.'''

    #: The default mount location of the test case stage directory inside the
    #: container

    #: The container image to be used for running the test.
    #:
    #: :type: :class:`str` or :class:`None`
    #: :default: :class:`None`
    image = fields.TypedField(str, type(None))

    #: The command to be executed within the container.
    #:
    #: If no command is given, then the default command of the corresponding
    #: container image is going to be executed.
    #:
    #: .. versionadded:: 3.5.0
    #:    Changed the attribute name from `commands` to `command` and its type
    #:    to a string.
    #:
    #: :type: :class:`str` or :class:`None`
    #: :default: :class:`None`
    command = fields.TypedField(str, type(None))

    _commands = fields.TypedField(typ.List[str])
    #: The commands to be executed within the container.
    #:
    #: .. deprecated:: 3.5.0
    #:    Please use the `command` field instead.
    #:
    #: :type: :class:`list[str]`
    #: :default: ``[]``
    commands = fields.DeprecatedField(
        _commands,
        'The `commands` field is deprecated, please use the `command` field '
        'to set the command to be executed by the container.',
        fields.DeprecatedField.OP_SET,
        from_version='3.5.0')

    #: Pull the container image before running.
    #:
    #: This does not have any effect for the `Singularity` container platform.
    #:
    #: .. versionadded:: 3.5
    #:
    #: :type: :class:`bool`
    #: :default: ``True``
    pull_image = fields.TypedField(bool)

    #: List of mount point pairs for directories to mount inside the container.
    #:
    #: Each mount point is specified as a tuple of
    #: ``(/path/in/host, /path/in/container)``. The stage directory of the
    #: ReFrame test is always mounted under ``/rfm_workdir`` inside the
    #: container, independelty of this field.
    #:
    #: :type: :class:`list[tuple[str, str]]`
    #: :default: ``[]``
    mount_points = fields.TypedField(typ.List[typ.Tuple[str, str]])

    #: Additional options to be passed to the container runtime when executed.
    #:
    #: :type: :class:`list[str]`
    #: :default: ``[]``
    options = fields.TypedField(typ.List[str])

    #: The working directory of ReFrame inside the container.
    #:
    #: This is the directory where the test's stage directory is mounted inside
    #: the container. This directory is always mounted regardless if
    #: :attr:`mount_points` is set or not.
    #:
    #: :type: :class:`str`
    #: :default: ``/rfm_workdir``
    #:
    #: .. versionchanged:: 3.12.0
    #:    This attribute is no more deprecated.
    workdir = fields.TypedField(str, type(None))

    def __init__(self):
        self.image = None
        self.command = None

        # NOTE: Here we set the target fields directly to avoid the deprecation
        # warnings
        self._commands = []

        self.workdir = _STAGEDIR_MOUNT
        self.mount_points = []
        self.options = []
        self.pull_image = True

    @abc.abstractmethod
    def emit_prepare_commands(self, stagedir):
        '''Returns commands for preparing this container for running.

        Such a command could be for pulling the container image from a
        repository.

        .. note:

            This method is relevant only to developers of new container
            platform backends.

        :meta private:

        :arg stagedir: The stage directory of the test.
        '''

    @abc.abstractmethod
    def launch_command(self, stagedir):
        '''Returns the command for running :attr:`commands` with this container
        platform.

        .. note:
            This method is relevant only to developers of new container
            platforms.

        :meta private:

        :arg stagedir: The stage directory of the test.
        '''

    @classmethod
    def create(cls, name):
        '''Factory method to create a new container by name.'''
        name = name.capitalize()
        try:
            return globals()[name]()
        except KeyError:
            raise ValueError(f'unknown container platform: {name}') from None

    @classmethod
    def create_from(cls, name, other):
        new = cls.create(name)
        new.image = other.image
        new.command = other.command
        new.mount_points = other.mount_points
        new.options = other.options
        new.pull_image = other.pull_image
        new.workdir = other.workdir

        # Update deprecated fields
        with warn.suppress_deprecations():
            new.commands = other.commands

        return new

    @property
    def name(self):
        return type(self).__name__

    def __str__(self):
        return self.name

    def __rfm_json_encode__(self):
        return str(self)
Exemplo n.º 4
0
 class FieldTester:
     x = fields.DeprecatedField(fields.TypedField(int), 'deprecated',
                                from_version=str(next_version))
Exemplo n.º 5
0
 class FieldTester:
     value = fields.DeprecatedField(fields.IntegerField('value'),
                                    'value field is deprecated')
Exemplo n.º 6
0
class ProgEnvironment(Environment):
    """A class representing a programming environment.

    This type of environment adds also attributes for setting the compiler and
    compilation flags.

    If compilation flags are set to :class:`None` (the default, if not set
    otherwise in ReFrame's `configuration
    <configure.html#environments-configuration>`__), they are not passed to the
    ``make`` invocation.

    If you want to disable completely the propagation of the compilation flags
    to the ``make`` invocation, even if they are set, you should set the
    :attr:`propagate` attribute to :class:`False`.
    """

    #: The C compiler of this programming environment.
    #:
    #: :type: :class:`str`
    cc = fields.DeprecatedField(
        fields.TypedField('cc', str), 'setting this field is deprecated; '
        'please set it through a build system', fields.DeprecatedField.OP_SET)
    _cc = fields.TypedField('cc', str)

    #: The C++ compiler of this programming environment.
    #:
    #: :type: :class:`str` or :class:`None`
    cxx = fields.DeprecatedField(
        fields.TypedField('cxx', str, type(None)),
        'setting this field is deprecated; '
        'please set it through a build system', fields.DeprecatedField.OP_SET)
    _cxx = fields.TypedField('cxx', str, type(None))

    #: The Fortran compiler of this programming environment.
    #:
    #: :type: :class:`str` or :class:`None`
    ftn = fields.DeprecatedField(
        fields.TypedField('ftn', str, type(None)),
        'setting this field is deprecated; '
        'please set it through a build system', fields.DeprecatedField.OP_SET)
    _ftn = fields.TypedField('ftn', str, type(None))

    #: The preprocessor flags of this programming environment.
    #:
    #: :type: :class:`str` or :class:`None`
    cppflags = fields.DeprecatedField(
        fields.TypedField('cppflags', str, type(None)),
        'setting this field is deprecated; '
        'please set it through a build system', fields.DeprecatedField.OP_SET)
    _cppflags = fields.TypedField('cppflags', str, type(None))

    #: The C compiler flags of this programming environment.
    #:
    #: :type: :class:`str` or :class:`None`
    cflags = fields.DeprecatedField(
        fields.TypedField('cflags', str, type(None)),
        'setting this field is deprecated; '
        'please set it through a build system', fields.DeprecatedField.OP_SET)
    _cflags = fields.TypedField('cflags', str, type(None))

    #: The C++ compiler flags of this programming environment.
    #:
    #: :type: :class:`str` or :class:`None`
    cxxflags = fields.DeprecatedField(
        fields.TypedField('cxxflags', str, type(None)),
        'setting this field is deprecated; '
        'please set it through a build system', fields.DeprecatedField.OP_SET)
    _cxxflags = fields.TypedField('cxxflags', str, type(None))

    #: The Fortran compiler flags of this programming environment.
    #:
    #: :type: :class:`str` or :class:`None`
    fflags = fields.DeprecatedField(
        fields.TypedField('fflags', str, type(None)),
        'setting this field is deprecated; '
        'please set it through a build system', fields.DeprecatedField.OP_SET)
    _fflags = fields.TypedField('fflags', str, type(None))

    #: The linker flags of this programming environment.
    #:
    #: :type: :class:`str` or :class:`None`
    ldflags = fields.DeprecatedField(
        fields.TypedField('ldflags', str, type(None)),
        'setting this field is deprecated; '
        'please set it through a build system', fields.DeprecatedField.OP_SET)
    _ldflags = fields.TypedField('ldflags', str, type(None))

    #: The include search path of this programming environment.
    #:
    #: :type: :class:`list` of :class:`str`
    #: :default: ``[]``
    include_search_path = fields.DeprecatedField(
        fields.TypedField('include_search_path', typ.List[str]),
        'setting this field is deprecated; '
        'please set it through a build system', fields.DeprecatedField.OP_SET)
    _include_search_path = fields.TypedField('include_search_path',
                                             typ.List[str])

    #: Propagate the compilation flags to the ``make`` invocation.
    #:
    #: :type: :class:`bool`
    #: :default: :class:`True`
    propagate = fields.DeprecatedField(
        fields.TypedField('propagate', bool),
        'setting this field is deprecated; '
        'please set it through a build system', fields.DeprecatedField.OP_SET)
    _propagate = fields.TypedField('propagate', bool)

    def __init__(self,
                 name,
                 modules=[],
                 variables={},
                 cc='cc',
                 cxx='CC',
                 ftn='ftn',
                 nvcc='nvcc',
                 cppflags=None,
                 cflags=None,
                 cxxflags=None,
                 fflags=None,
                 ldflags=None,
                 **kwargs):
        super().__init__(name, modules, variables)
        self._cc = cc
        self._cxx = cxx
        self._ftn = ftn
        self._nvcc = nvcc
        self._cppflags = cppflags
        self._cflags = cflags
        self._cxxflags = cxxflags
        self._fflags = fflags
        self._ldflags = ldflags
        self._include_search_path = []
        self._propagate = True

    @property
    def nvcc(self):
        return self._nvcc