Skip to content

Commit

Permalink
Ensure that the cached globalconfig object
Browse files Browse the repository at this point in the history
is reloaded after the export of `CYLC_SYMLINKS` variable.
This means that using the `CYLC_SYMLINKS` variable allows
users to specify installation symlink locations in the
`rose-suite.conf`.
  • Loading branch information
wxtim committed Dec 4, 2023
1 parent 4862c06 commit 4a34384
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ creating a new release entry be sure to copy & paste the span tag with the
updated. Only the first match gets replaced, so it's fine to leave the old
ones in. -->


## __cylc-rose-1.4.0 (<span actions:bind='release-date'>Upcoming</span>)__

### Features

[#269](://github.com/cylc/cylc-rose/pull/269) - Reload the Cylc Global
config after exporting CYLC_SYMLINKS variable. This change will allow
users to set symlink directory locations in their `rose-suite.conf`.

## __cylc-rose-1.3.1 (<span actions:bind='release-date'>Released 2023-10-24</span>)__

### Fixes
Expand Down
8 changes: 8 additions & 0 deletions cylc/rose/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from cylc.flow import LOG
from cylc.flow.exceptions import CylcError
from cylc.flow.flags import cylc7_back_compat
from cylc.flow.cfgspec.glbl_cfg import glbl_cfg
from cylc.flow.hostuserutil import get_host
from metomi.isodatetime.datetimeoper import DateTimeOperator
from metomi.rose import __version__ as ROSE_VERSION
Expand Down Expand Up @@ -869,6 +870,13 @@ def export_environment(environment: Dict[str, str]) -> None:
for key, val in environment.items():
os.environ[key] = val

# If CYLC_SYMLINKS has been set we want to force reload
# the global config so that the value of CYLC_SYMLINKS
# can be used by Jinja2 in the global config.
# https://github.com/cylc/cylc-rose/issues/237
if 'CYLC_SYMLINKS' in environment:
glbl_cfg().load()


def record_cylc_install_options(
srcdir: Path,
Expand Down
34 changes: 34 additions & 0 deletions tests/functional/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,37 @@ def test_basic(tmp_path):
assert Path(tmp_path / 'src/rose-suite.conf').read_text() == (
Path(tmp_path / 'dest/rose-suite.conf').read_text()
)


def test_CYLC_SYMLINKS(monkeypatch, tmp_path, cylc_validate_cli):
"""We reload the global config after exporting env variables."""
# Setup global config:
global_conf = """#!jinja2
{% from "cylc.flow" import LOG %}
{% set cylc_symlinks = environ.get('CYLC_SYMLINKS', None) %}
{% do LOG.critical(cylc_symlinks) %}
"""
conf_path = tmp_path / 'conf'
conf_path.mkdir()
monkeypatch.setenv('CYLC_CONF_PATH', conf_path)

# Setup workflow config:
(conf_path / 'global.cylc').write_text(global_conf)
(tmp_path / 'rose-suite.conf').write_text(
'[env]\nCYLC_SYMLINKS="Foo"\n')
(tmp_path / 'flow.cylc').write_text("""
[scheduling]
initial cycle point = now
[[graph]]
R1 = x
[runtime]
[[x]]
""")

# Validate the config:
output = cylc_validate_cli(tmp_path)
assert output.ret == 0

# CYLC_SYMLINKS == None the first time the global.cylc
# is loaded and "Foo" the second time.
assert output.logging == 'None\n"Foo"'

0 comments on commit 4a34384

Please sign in to comment.