예제 #1
0
    def spec_():
        with Conf('myconfig') as myconf:
            with Conf('some_parent'):
                with Conf('manythings'):
                    Conf('<thing>')

        return myconf
예제 #2
0
    def _inner(typ, validator):
        """Return a sample spec for the given data type.

        Args:
            typ (str):
                An arbirtrary name for this type.
            validator (str):
                A parsec validator.

        Returns:
            cylc.flow.parsec.config.ConfigNode

        """
        with Conf('/') as myconf:
            with Conf(typ):
                Conf('<item>', validator)
        return myconf
예제 #3
0
def validator_invalid_values():
    """
    Data provider or invalid values for parsec validator. All values must not
    be null (covered elsewhere), and not dict's.

    Possible invalid scenarios must include:

    - cfg[key] is a list AND a value is not in list of the possible values
    - OR
    - cfg[key] is not a list AND cfg[key] not in the list of possible values

    :return: a list with sets of tuples for the test parameters
    :rtype: list
    """

    values = []

    # variables reused throughout
    spec = None
    msg = None

    # set 1 (t, f, f, t)
    with Conf('base') as spec:
        Conf('value', VDR.V_INTEGER_LIST, default=1, options=[1, 2, 3, 4])
    cfg = OrderedDictWithDefaults()
    cfg['value'] = "1, 2, 3"
    msg = None
    values.append((spec, cfg, msg))

    # set 2 (t, t, f, t)
    with Conf('base') as spec:
        Conf('value', VDR.V_INTEGER_LIST, default=1, options=[1, 2, 3, 4])
    cfg = OrderedDictWithDefaults()
    cfg['value'] = "1, 2, 5"
    msg = '(type=option) value = [1, 2, 5]'
    values.append((spec, cfg, msg))

    # set 3 (f, f, t, f)
    with Conf('base') as spec:
        Conf('value', VDR.V_INTEGER, default=1, options=[2, 3, 4])
    cfg = OrderedDictWithDefaults()
    cfg['value'] = "2"
    msg = None
    values.append((spec, cfg, msg))

    # set 4 (f, f, t, t)
    with Conf('base') as spec:
        Conf('value', VDR.V_INTEGER, default=1, options=[1, 2, 3, 4])
    cfg = OrderedDictWithDefaults()
    cfg['value'] = "5"
    msg = '(type=option) value = 5'
    values.append((spec, cfg, msg))

    return values
예제 #4
0
def sample_spec_2():
    with Conf('myconf') as spec:
        with Conf('section'):
            Conf('name', VDR.V_STRING)
            Conf('address', VDR.V_INTEGER_LIST)
        with Conf('allow_many'):
            Conf('<user defined>', VDR.V_STRING, '')
    return spec
예제 #5
0
def test_validate():
    """
    An interesting aspect of the ParsecConfig.validate, is that if you
    have a sparse dict produced by this class, and you call the validate
    on that dict again, you may have TypeErrors.

    That occurs because the values like 'True' are validated against the
    spec and converted from Strings with quotes, to bool types. So the
    next type you run the validation if expects Strings...
    :return:
    """

    with Conf('myconf') as spec:
        with Conf('section'):
            Conf('name', VDR.V_STRING)
            Conf('address', VDR.V_STRING)

    parsec_config = config.ParsecConfig(
        spec=spec,
        upgrader=None,  # new spec
        output_fname=None,  # not going to call the loadcfg
        tvars=None,
        validator=None  # use default
    )

    sparse = OrderedDictWithDefaults()
    parsec_config.validate(sparse)  # empty dict is OK

    with pytest.raises(IllegalItemError):
        sparse = OrderedDictWithDefaults()
        sparse['name'] = 'True'
        parsec_config.validate(sparse)  # name is not valid

    sparse = OrderedDictWithDefaults()
    sparse['section'] = OrderedDictWithDefaults()
    sparse['section']['name'] = 'Wind'
    sparse['section']['address'] = 'Corner'
    parsec_config.validate(sparse)
예제 #6
0
def meta_conf():
    """A config with an inherited section."""
    with Conf('Foo') as spec:
        with Conf('<X>') as template:
            Conf('a', default='a')
            Conf('b', default='b')
        with Conf('y', meta=template) as copy:
            Conf('a', default='c')
    return spec, template, copy
예제 #7
0
def sample_spec():
    with Conf('myconf') as myconf:
        with Conf('section1'):
            Conf('value1', default='')
            Conf('value2', default='what?')
        with Conf('section2'):
            Conf('enabled', VDR.V_BOOLEAN)
        with Conf('section3'):
            Conf('title', default='default', options=['1', '2'])
            Conf(
                'amounts',
                VDR.V_INTEGER_LIST,
                default=[1, 2, 3],
                # options=[[1, 2, 3]]
            )
            with Conf('entries'):
                Conf('key')
                Conf('value')
        with Conf('<whatever>'):
            Conf('section300000', default='')
            Conf('ids', VDR.V_INTEGER_LIST)
    return myconf
예제 #8
0
def many_section():
    """A config containing a user-definable section."""
    with Conf('file.cylc') as file_:
        with Conf('<section>'):
            Conf('setting')
    return file_
예제 #9
0
def many_setting():
    """A config containing a user-definable setting."""
    with Conf('file.cylc') as file_:
        Conf('<setting>')  # __MANY__
    return file_
예제 #10
0
def basic_config():
    """A basic config with a file, section and setting."""
    with Conf('file.cylc') as file_:
        with Conf('section') as section:
            setting = Conf('setting')
        return (file_, section, setting)
예제 #11
0
def sample_spec():
    """An example cylc.flow.parsec.config.ConfigNode."""
    with Conf('myconf') as myconf:
        with Conf('section1'):
            Conf('value1', VDR.V_STRING, '')
            Conf('value2', VDR.V_STRING, 'what?')
        with Conf('section2'):
            Conf('enabled', VDR.V_BOOLEAN, False)
        with Conf('section3'):
            Conf('title', VDR.V_STRING)
            with Conf('entries'):
                Conf('key', VDR.V_STRING)
                Conf('value', VDR.V_INTEGER_LIST)
    return myconf
예제 #12
0
with Conf('global.cylc',
          desc='''
    The global configuration which defines default Cylc Flow settings
    for a user or site.

    To view your global config run::

       $ cylc get-global-config --sparse

    Cylc will attempt to load the global configuration (``global.cylc``) from a
    hierarchy of locations, including the site directory (defaults to
    ``/etc/cylc/flow/``) and the user directory (``~/.cylc/flow/``). E.g. for
    Cylc version 8.0.1, the hierarchy would be, in order of ascending priority:

    * ``${CYLC_SITE_CONF_PATH}/global.cylc``
    * ``${CYLC_SITE_CONF_PATH}/8/global.cylc``
    * ``${CYLC_SITE_CONF_PATH}/8.0/global.cylc``
    * ``${CYLC_SITE_CONF_PATH}/8.0.1/global.cylc``
    * ``~/.cylc/flow/global.cylc``
    * ``~/.cylc/flow/8/global.cylc``
    * ``~/.cylc/flow/8.0/global.cylc``
    * ``~/.cylc/flow/8.0.1/global.cylc``

    A setting in a file lower down in the list will override the same setting
    from those higher up (but if a setting is present in a file higher up and
    not in any files lower down, it will not be overridden).

    Setting the ``CYLC_SITE_CONF_PATH`` environment variable overrides the
    default value of ``/etc/cylc/flow/``.

    To override the entire hierarchy, set the ``CYLC_CONF_PATH`` environment
    variable to the directory containing your ``global.cylc`` file.

    .. note::

       The ``global.cylc`` file can be templated using Jinja2 variables.
       See :ref:`Jinja`.

    .. note::

       Prior to Cylc 8, ``global.cylc`` was named ``global.rc``, but that name
       is no longer supported.
''') as SPEC:
예제 #13
0
with Conf('global.cylc',
          desc='''
    The global configuration which defines default Cylc Flow settings
    for a user or site.

    To view your global config run::

       $ cylc config

    Cylc will attempt to load the global configuration (``global.cylc``) from a
    hierarchy of locations, including the site directory (defaults to
    ``/etc/cylc/flow/``) and the user directory (``~/.cylc/flow/``). For
    example at Cylc version 8.0.1, the hierarchy would be, in order of
    ascending priority:

    .. code-block:: sub

       <site-conf-path>/flow/global.cylc
       <site-conf-path>/flow/8/global.cylc
       <site-conf-path>/flow/8.0/global.cylc
       <site-conf-path>/flow/8.0.1/global.cylc
       ~/.cylc/flow/global.cylc
       ~/.cylc/flow/8/global.cylc
       ~/.cylc/flow/8.0/global.cylc
       ~/.cylc/flow/8.0.1/global.cylc

    Where ``<site-conf-path>`` is ``/etc/cylc/flow/`` by default but can be
    changed by :envvar:`CYLC_SITE_CONF_PATH`.

    A setting in a file lower down in the list will override the same setting
    from those higher up (but if a setting is present in a file higher up and
    not in any files lower down, it will not be overridden).

    The following environment variables can change the files which are loaded:

    .. envvar:: CYLC_CONF_PATH

       If set this bypasses the default site/user configuration hierarchy used
       to load the Cylc Flow global configuration.

       This should be set to a directory containing a :cylc:conf:`global.cylc`
       file.

    .. envvar:: CYLC_SITE_CONF_PATH

       By default the site configuration is located in ``/etc/cylc/``. For
       installations where this is not convenient, this path can be overridden
       by setting ``CYLC_SITE_CONF_PATH`` to point at another location.

       Configuration for different Cylc components should be in sub-directories
       within this location.

       For example to configure Cylc Flow you could do the following::

          $CYLC_SITE_CONF_PATH/
          `-- flow/
              `-- global.cylc

    .. note::

       The ``global.cylc`` file can be templated using Jinja2 variables.
       See :ref:`Jinja`.

    .. note::

       Prior to Cylc 8, ``global.cylc`` was named ``global.rc``, but that name
       is no longer supported.
''') as SPEC:
예제 #14
0
with Conf('global.cylc',
          desc='''
    The global configuration which defines default Cylc Flow settings
    for a user or site.

    To view your global config run::

       $ cylc config --sparse

    Cylc will attempt to load the global configuration (``global.cylc``) from a
    hierarchy of locations, including the site directory (defaults to
    ``/etc/cylc/flow/``) and the user directory (``~/.cylc/flow/``). E.g. for
    Cylc version 8.0.1, the hierarchy would be, in order of ascending priority:

    .. code-block:: sub

       <site-conf-path>/flow/global.cylc
       <site-conf-path>/flow/8/global.cylc
       <site-conf-path>/flow/8.0/global.cylc
       <site-conf-path>/flow/8.0.1/global.cylc
       ~/.cylc/flow/global.cylc
       ~/.cylc/flow/8/global.cylc
       ~/.cylc/flow/8.0/global.cylc
       ~/.cylc/flow/8.0.1/global.cylc

    Where ``<site-conf-path>`` is ``/etc/cylc/flow/`` by default but can be
    changed by :envvar:`CYLC_SITE_CONF_PATH`.

    A setting in a file lower down in the list will override the same setting
    from those higher up (but if a setting is present in a file higher up and
    not in any files lower down, it will not be overridden).

    The following environment variables can change the files which are loaded:

    .. envvar:: CYLC_CONF_PATH

       If set this bypasses the default site/user configuration hierarchy used
       to load the Cylc Flow global configuration.

       This should be set to a directory containing a :cylc:conf:`global.cylc`
       file.

    .. envvar:: CYLC_SITE_CONF_PATH

       By default the site configuration is located in ``/etc/cylc/``. For
       installations where this is not convenient, this path can be overridden
       by setting ``CYLC_SITE_CONF_PATH`` to point at another location.

       Configuration for different Cylc components should be in sub-directories
       within this location.

       For example to configure Cylc Flow you could do the following::

          $CYLC_SITE_CONF_PATH/
          `-- flow/
              `-- global.cylc

    .. note::

       The ``global.cylc`` file can be templated using Jinja2 variables.
       See :ref:`Jinja`.

    .. note::

       Prior to Cylc 8, ``global.cylc`` was named ``global.rc``, but that name
       is no longer supported.
''') as SPEC: