Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/1.3.x' into feature.do_not_all…
Browse files Browse the repository at this point in the history
…ow_--defines_no_equal

* upstream/1.3.x:
  make RoseStemVersionException print the correct missing variable (#252)
  Update tests/unit/test_rose_stem_units.py
  Allow top level  settings in CLI Config (#221)
  Prevent accidental manual setting of project name with -s=
  Fix flake8
  Bump dev version
  Add missing dependency on ansimarkup
  Prepare release 1.3.0
  Bump pypa/gh-action-pypi-publish from 1.8.7 to 1.8.8 (#236)
  Permitted warnings about root-dir for all versions of Cylc. (#231)
  Bump pypa/gh-action-pypi-publish from 1.8.6 to 1.8.7 (#235)
  Bump pypa/gh-action-pypi-publish from 1.8.5 to 1.8.6 (#228)
  1.3.0 (#219)
  • Loading branch information
wxtim committed Oct 9, 2023
2 parents 9f21a2a + 7697d23 commit dee1183
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/2_auto_publish_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: cylc/release-actions/build-python-package@v1

- name: Publish distribution to PyPI
uses: pypa/[email protected].5
uses: pypa/[email protected].8
with:
user: __token__ # uses the API token feature of PyPI - least permissions possible
password: ${{ secrets.PYPI_TOKEN }}
Expand Down
14 changes: 13 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,28 @@ 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.3.0 (<span actions:bind='release-date'>Awaiting Release</span>)__
## __cylc-rose-1.3.1 (<span actions:bind='release-date'>Upcoming</span>)__

### Fixes

[#250](https://github.com/cylc/cylc-rose/pull/250) - Prevent project
name being manually set to an empty string.

## __cylc-rose-1.3.0 (<span actions:bind='release-date'>Released 2023-07-21</span>)__

### Fixes

[#229](https://github.com/cylc/cylc-rose/pull/229) -
Fix bug which stops rose-stem suites using the new `[template variables]` section
in their `rose-suite.conf` files.

<<<<<<< HEAD
[#225](https://github.com/cylc/cylc-rose/pull/225) - Prevent totally invalid
CLI --defines with no = sign.
=======
[#231](https://github.com/cylc/cylc-rose/pull/231) - Show warning about
`root-dir` config setting in compatibility mode.
>>>>>>> upstream/1.3.x
## __cylc-rose-1.2.0 (<span actions:bind='release-date'>Released 2023-01-16</span>)__

Expand Down
2 changes: 1 addition & 1 deletion cylc/rose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,4 @@
"""

__version__ = '1.2.1.dev'
__version__ = '1.3.1.dev'
10 changes: 6 additions & 4 deletions cylc/rose/stem.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,17 @@ def __repr__(self):
__str__ = __repr__


class RoseStemVersionException(Exception):
class RoseStemVersionException(CylcError):

"""Exception class when running the wrong rose-stem version."""

def __init__(self, version):

Exception.__init__(self, version)
if version is None:
self.suite_version = (
"does not have ROSE_VERSION set in the rose-suite.conf"
"does not have ROSE_STEM_VERSION set in the "
"rose-suite.conf"
)
else:
self.suite_version = "at version %s" % (version)
Expand All @@ -165,7 +167,7 @@ def __repr__(self):
__str__ = __repr__


class RoseSuiteConfNotFoundException(Exception):
class RoseSuiteConfNotFoundException(CylcError):

"""Exception class when unable to find rose-suite.conf."""

Expand Down Expand Up @@ -340,7 +342,7 @@ def _ascertain_project(self, item):
if re.search(r'^\.', item):
item = os.path.abspath(os.path.join(os.getcwd(), item))

if project is not None:
if project:
print(f"[WARN] Forcing project for '{item}' to be '{project}'")
return project, item, item, '', ''

Expand Down
70 changes: 46 additions & 24 deletions cylc/rose/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from cylc.flow.hostuserutil import get_host
from cylc.flow import LOG
from cylc.flow.exceptions import CylcError
import cylc.flow.flags as flags
from cylc.flow.flags import cylc7_back_compat
from cylc.rose.jinja2_parser import Parser, patch_jinja2_leading_zeros
from metomi.rose import __version__ as ROSE_VERSION
from metomi.isodatetime.datetimeoper import DateTimeOperator
Expand All @@ -46,6 +46,8 @@
USER_IGNORE = '!'
TRIGGER_IGNORE = '!!'
IGNORES = (USER_IGNORE, TRIGGER_IGNORE)
MESSAGE = 'message'
ALL_MODES = 'all modes'


class MultipleTemplatingEnginesError(CylcError):
Expand Down Expand Up @@ -413,7 +415,7 @@ def parse_cli_define(define: str) -> Union[
# Doesn't have a section:
match = re.match(
r'^(?P<state>!{0,2})(?P<key>.*)\s*=\s*(?P<value>.*)', define)
if match:
if match and not match['state']:
groupdict = match.groupdict()
keys = [groupdict['key'].strip()]
else:
Expand Down Expand Up @@ -744,30 +746,50 @@ def deprecation_warnings(config_tree):
- "root-dir"
- "jinja2:suite.rc"
- "empy:suite.rc"
- root-dir
If ALL_MODES is True this deprecation will ignore whether there is a
flow.cylc or suite.rc in the workflow directory.
"""

deprecations = {
'empy:suite.rc': (
"'rose-suite.conf[empy:suite.rc]' is deprecated."
" Use [template variables] instead."),
'jinja2:suite.rc': (
"'rose-suite.conf[jinja2:suite.rc]' is deprecated."
" Use [template variables] instead."),
'empy:flow.cylc': (
"'rose-suite.conf[empy:flow.cylc]' is not used by Cylc."
" Use [template variables] instead."),
'jinja2:flow.cylc': (
"'rose-suite.conf[jinja2:flow.cylc]' is not used by Cylc."
" Use [template variables] instead."),
'root-dir': (
'You have set "rose-suite.conf[root-dir]", '
'which is not supported at '
'Cylc 8. Use `[install] symlink dirs` in global.cylc '
'instead.')
'empy:suite.rc': {
MESSAGE: (
"'rose-suite.conf[empy:suite.rc]' is deprecated."
" Use [template variables] instead."),
ALL_MODES: False,
},
'jinja2:suite.rc': {
MESSAGE: (
"'rose-suite.conf[jinja2:suite.rc]' is deprecated."
" Use [template variables] instead."),
ALL_MODES: False,
},
'empy:flow.cylc': {
MESSAGE: (
"'rose-suite.conf[empy:flow.cylc]' is not used by Cylc."
" Use [template variables] instead."),
ALL_MODES: False,
},
'jinja2:flow.cylc': {
MESSAGE: (
"'rose-suite.conf[jinja2:flow.cylc]' is not used by Cylc."
" Use [template variables] instead."),
ALL_MODES: False,
},
'root-dir': {
MESSAGE: (
'You have set "rose-suite.conf[root-dir]", '
'which is not supported at '
'Cylc 8. Use `[install] symlink dirs` in global.cylc '
'instead.'),
ALL_MODES: True,
},
}
if not flags.cylc7_back_compat:
for string in list(config_tree.node):
for deprecation in deprecations.keys():
if deprecation in string.lower():
LOG.warning(deprecations[deprecation])
for string in list(config_tree.node):
for name, info in deprecations.items():
if (
(info[ALL_MODES] or not cylc7_back_compat)
and name in string.lower()
):
LOG.warning(info[MESSAGE])
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ packages = find_namespace:
python_requires = >=3.7
include_package_data = True
install_requires =
metomi-rose==2.0.*
cylc-flow==8.1.*
metomi-rose==2.1.*
cylc-flow==8.2.*
metomi-isodatetime
ansimarkup
jinja2

[options.packages.find]
Expand Down
3 changes: 0 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def _cylc_validate_cli(capsys, caplog):
def _inner(srcpath, args=None):
parser = validate_gop()
options = Options(parser, args)()

output = SimpleNamespace()

try:
Expand Down Expand Up @@ -130,7 +129,6 @@ def _inner(srcpath, args=None):
args: Dictionary of arguments.
"""
options = Options(install_gop(), args)()

output = SimpleNamespace()

try:
Expand All @@ -156,7 +154,6 @@ def _inner(workflow_id, opts=None):
args: Dictionary of arguments.
"""
options = Options(reinstall_gop(), opts)()

output = SimpleNamespace()

try:
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_pre_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_warn_if_old_templating_set(
):
"""Test using unsupported root-dir config raises error."""
monkeypatch.setattr(
cylc.rose.utilities.flags, 'cylc7_back_compat', compat_mode
cylc.rose.utilities, 'cylc7_back_compat', compat_mode
)
(tmp_path / 'rose-suite.conf').write_text(f'[{rose_config}]')
get_rose_vars(srcdir=tmp_path)
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from cylc.flow.pathutil import get_workflow_run_dir
from cylc.rose.utilities import (
ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING as ROHIOS)
from cylc.flow.workflow_files import reinstall_workflow
from cylc.flow.install import reinstall_workflow


HOST = get_host()
Expand Down
5 changes: 3 additions & 2 deletions tests/functional/test_rose_stem.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def test_with_config2(self, with_config2, expected):
assert expected in with_config2['jobout_content']


def test_incompatible_versions(setup_stem_repo, monkeymodule):
def test_incompatible_versions(setup_stem_repo, monkeymodule, caplog, capsys):
"""It fails if trying to install an incompatible version.
"""
# Copy suite into working copy.
Expand All @@ -587,7 +587,8 @@ def test_incompatible_versions(setup_stem_repo, monkeymodule):
str(setup_stem_repo['workingcopy']),
"fcm:foo.x_tr@head",
],
'workflow_name': str(setup_stem_repo['suitename'])
'workflow_name': str(setup_stem_repo['suitename']),
'verbosity': 2,
}

monkeymodule.setattr('sys.argv', ['stem'])
Expand Down
43 changes: 43 additions & 0 deletions tests/unit/test_config_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""Tests the plugin with Rose suite configurations via the Python API."""

import pytest
from types import SimpleNamespace

from metomi.isodatetime.datetimeoper import DateTimeOperator
from metomi.rose import __version__ as ROSE_VERSION
Expand All @@ -28,6 +29,7 @@
ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING,
get_rose_vars_from_config_node,
add_cylc_install_to_rose_conf_node_opts,
deprecation_warnings,
dump_rose_log,
identify_templating_section,
MultipleTemplatingEnginesError
Expand Down Expand Up @@ -285,3 +287,44 @@ def test_ROSE_ORIG_HOST_replacement_behaviour(
ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING)
assert not caplog.records
assert node['env']['ROSE_ORIG_HOST'].value == 'IMPLAUSIBLE_HOST_NAME'


@pytest.mark.parametrize(
'compat_mode, must_include, must_exclude',
(
(True, None, 'Use [template variables]'),
(True, 'root-dir', None),
(False, 'Use [template variables]', None),
(False, 'root-dir', None),
)
)
def test_deprecation_warnings(
caplog, monkeypatch, compat_mode, must_include, must_exclude
):
"""Method logs warnings correctly.
Two node items are set:
* ``jinja2:suite.rc`` should not cause a warning in compatibility mode.
* ``root-dir=/somewhere`` should always lead to a warning being logged.
Error messages about
"""
# Create a node to pass to the method
# (It's not a tree test because we can use a simpleNamespace in place of
# a tree object):
node = ConfigNode()
node.set(['jinja2:suite.rc'])
node.set(['root-dir', '~foo'])
tree = SimpleNamespace(node=node)

# Patch compatibility mode flag and run the function under test:
monkeypatch.setattr('cylc.rose.utilities.cylc7_back_compat', compat_mode)
deprecation_warnings(tree)

# Check that warnings have/not been logged:
records = '\n'.join([i.message for i in caplog.records])
if must_include:
assert must_include in records
else:
assert must_exclude not in records
19 changes: 0 additions & 19 deletions tests/unit/test_config_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,25 +467,6 @@ def test_merge_opts(
assert merge_opts(conf, opt_conf_keys) == expected


@pytest.mark.parametrize(
'state',
['!', '!!']
)
def test_cli_defines_ignored_are_ignored(
state, caplog
):
opts = SimpleNamespace(
opt_confs='', defines=[f'[]{state}opts=ignore me'],
rose_template_vars=[]
)

get_cli_opts_node(opts)
assert (
caplog.records[0].message ==
'CLI opts set to ignored or trigger-ignored will be ignored.'
)


@pytest.mark.parametrize(
'opt_confs, defines, rose_template_vars, expect',
[
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_functional_post_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
def assert_rose_conf_full_equal(left, right, no_ignore=True):
for keys_1, node_1 in left.walk(no_ignore=no_ignore):
node_2 = right.get(keys_1, no_ignore=no_ignore)
assert not (
assert not ( # noqa: E721
type(node_1) != type(node_2) or
(
not isinstance(node_1.value, dict) and
Expand Down
Loading

0 comments on commit dee1183

Please sign in to comment.