Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand comma separated lists in global.cylc:[install][symlink dirs] #6475

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes.d/6475.feat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow definition of `install targets` in `global.cylc` using comma separated lists.
57 changes: 51 additions & 6 deletions cylc/flow/cfgspec/globalcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,40 @@
'''
}

COMMA_SEPARATED_SECTION_NOTE = '''


.. note::

This section can be a comma separated list.

.. spoiler:: Example

For example:

.. code-block:: cylc

[a, b]
setting = x
[a]
another_setting = y

Will become:

.. code-block:: cylc

[a]
setting = x
[b]
setting = x
[a]
another_setting = y

Which will then be combined according to
:ref:`the rules for Cylc config syntax<syntax>`.

'''

# ----------------------------------------------------------------------------


Expand Down Expand Up @@ -1131,8 +1165,9 @@

.. versionadded:: 8.0.0
"""):
with Conf('<install target>', desc="""
with Conf('<install target>', desc=f"""
:ref:`Host <Install targets>` on which to create the symlinks.
{COMMA_SEPARATED_SECTION_NOTE}
"""):
Conf('run', VDR.V_STRING, None, desc="""
Alternative location for the run dir.
Expand Down Expand Up @@ -1209,7 +1244,7 @@

.. versionadded:: 8.0.0
'''):
with Conf('<platform name>', desc='''
with Conf('<platform name>', desc=f'''
Configuration defining a platform.

Many of these settings have replaced those of the same name from
Expand All @@ -1219,7 +1254,7 @@
Platform names can be regular expressions: If you have a set of
compute resources such as ``bigmachine1, bigmachine2`` or
``desktop0000, .., desktop9999`` one would define platforms with
names ``[[bigmachine[12]]]`` and ``[[desktop[0-9]{4}]]``.
names ``[[bigmachine[12]]]`` and ``[[desktop[0-9]{{4}}]]``.

Cylc searches for a matching platform in the reverse
of the definition order to allow user defined platforms
Expand Down Expand Up @@ -1254,6 +1289,8 @@
platform configurations.

.. versionadded:: 8.0.0

{COMMA_SEPARATED_SECTION_NOTE}
''') as Platform:
with Conf('meta', desc=PLATFORM_META_DESCR):
Conf('<custom metadata>', VDR.V_STRING, '', desc='''
Expand Down Expand Up @@ -2018,6 +2055,7 @@
self.dense.clear()
LOG.debug("Loading site/user config files")
conf_path_str = os.getenv("CYLC_CONF_PATH")

if conf_path_str:
# Explicit config file override.
fname = os.path.join(conf_path_str, self.CONF_BASENAME)
Expand All @@ -2030,7 +2068,7 @@

# Expand platforms needs to be performed first because it
# manipulates the sparse config.
self._expand_platforms()
self._expand_commas()

Check warning on line 2071 in cylc/flow/cfgspec/globalcfg.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/cfgspec/globalcfg.py#L2071

Added line #L2071 was not covered by tests

# Flesh out with defaults
self.expand()
Expand Down Expand Up @@ -2074,8 +2112,8 @@
msg += f'\n * {name}'
raise GlobalConfigError(msg)

def _expand_platforms(self):
"""Expand comma separated platform names.
def _expand_commas(self):
"""Expand comma separated section headers.

E.G. turn [platforms][foo, bar] into [platforms][foo] and
platforms[bar].
Expand All @@ -2084,6 +2122,13 @@
self.sparse['platforms'] = expand_many_section(
oliver-sanders marked this conversation as resolved.
Show resolved Hide resolved
self.sparse['platforms']
)
if (

Check warning on line 2125 in cylc/flow/cfgspec/globalcfg.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/cfgspec/globalcfg.py#L2125

Added line #L2125 was not covered by tests
self.sparse.get("install")
and self.sparse["install"].get("symlink dirs")
):
self.sparse["install"]["symlink dirs"] = expand_many_section(
self.sparse["install"]["symlink dirs"]
)

def platform_dump(
self,
Expand Down
24 changes: 20 additions & 4 deletions tests/unit/cfgspec/test_globalcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,19 @@ def test_dump_platform_details(capsys, mock_global_config):
assert expected == out


def test_expand_platforms(tmp_path: Path, mock_global_config: Callable):
"""It should expand comma separated platform definitions."""
def test_expand_commas(tmp_path: Path, mock_global_config: Callable):
"""It should expand comma separated platform and install target
definitions."""
glblcfg: GlobalConfig = mock_global_config('''
[install]
[[symlink dirs]]
[[[foo, bar]]]
run = /x
[[[foo]]]
share = /y
[[[bar]]]
share = /z

[platforms]
[[foo]]
[[[meta]]]
Expand All @@ -91,7 +101,7 @@ def test_expand_platforms(tmp_path: Path, mock_global_config: Callable):
[[[meta]]]
x = 4
''')
glblcfg._expand_platforms()
glblcfg._expand_commas()

# ensure the definition order is preserved
assert glblcfg.get(['platforms']).keys() == [
Expand All @@ -102,12 +112,18 @@ def test_expand_platforms(tmp_path: Path, mock_global_config: Callable):
'pub',
]

# ensure sections are correctly deep-merged
# ensure platform sections are correctly deep-merged
assert glblcfg.get(['platforms', 'foo', 'meta', 'x']) == '1'
assert glblcfg.get(['platforms', 'bar', 'meta', 'x']) == '3'
assert glblcfg.get(['platforms', 'baz', 'meta', 'x']) == '3'
assert glblcfg.get(['platforms', 'pub', 'meta', 'x']) == '4'

# ensure install target sections are correctly merged:
assert glblcfg.get(["install", "symlink dirs", "foo", "run"]) == "/x"
assert glblcfg.get(["install", "symlink dirs", "foo", "share"]) == "/y"
assert glblcfg.get(["install", "symlink dirs", "bar", "run"]) == "/x"
assert glblcfg.get(["install", "symlink dirs", "bar", "share"]) == "/z"


@pytest.mark.parametrize(
'src_dir, err_expected',
Expand Down
Loading