Skip to content

Commit

Permalink
Merge pull request #353 from wxtim/remove.empy
Browse files Browse the repository at this point in the history
Remove Empy Support
  • Loading branch information
wxtim authored Nov 28, 2024
2 parents 1b7e97d + af2001e commit 1100801
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 316 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: cylc/release-actions/install-cylc-components@v1
with:
cylc_flow: true
cylc_flow_opts: 'empy'
cylc_flow_opts: ''
metomi_rose: true
metomi_rose_opts: ''

Expand Down
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ 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.5.0 (<span actions:bind='release-date'>Upcoming</span>)__

[#353](https://github.com/cylc/cylc-rose/pull/353) - Remove Empy support.
Cylc has dropped empy support at Cylc 8.4.0.

## __cylc-rose-1.4.2 (<span actions:bind='release-date'>Released 2024-11-07</span>)__

[#345](https://github.com/cylc/cylc-rose/pull/345) - Fix an issue
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ environment for Rose integration.

This plugin provides support for the `rose-suite.conf` file, namely:

* Jinja2/EmPy template variables.
* Jinja2 template variables.
* Scheduler environment variables.
* File installation.
* Optional configurations.
Expand Down
8 changes: 4 additions & 4 deletions cylc/rose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@
``opts=A B C``, A space limited list of optional configs.
``[env]``, "Variables which the cylc-rose plugin will export to the
environment."
``[template variables]``, "Variables which can be used by Jinja2 or Empy
``[template variables]``, "Variables which can be used by Jinja2
in the workflow definition."
``[file:destination]``, A file from one or more sources to be installed.
.. note::
For compatibility with Cylc 7, sections ``[suite.rc:empy]`` and
``[suite.rc:jinja2]`` will be processed, but are deprecated and provided
for ease of porting Cylc 7 workflows.
For compatibility with Cylc 7, section ``[suite.rc:jinja2]`` will be
processed, but is deprecated and provided for ease of porting Cylc 7
workflows.
The ``global.cylc`` file
Expand Down
9 changes: 3 additions & 6 deletions cylc/rose/entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ def pre_configure(srcdir: Path, opts: 'Values') -> dict:

# If we are validating against source, load saved CLI options
# from previous install, as saved in the rose-suite-cylc-install.conf
if (
getattr(opts, 'against_source', False)
and isinstance(opts.against_source, Path)
if getattr(opts, 'against_source', False) and isinstance(
opts.against_source, Path
):
opts = retrieve_installed_cli_opts(srcdir, opts)

Expand Down Expand Up @@ -102,6 +101,4 @@ def rose_stem():
from cylc.rose.stem import get_rose_stem_opts, rose_stem

parser, opts = get_rose_stem_opts()
asyncio.run(
rose_stem(parser, opts)
)
asyncio.run(rose_stem(parser, opts))
111 changes: 46 additions & 65 deletions cylc/rose/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@


ROSE_SUITE_OPT_CONF_KEYS = 'ROSE_SUITE_OPT_CONF_KEYS'
SECTIONS = {'jinja2:suite.rc', 'empy:suite.rc', 'template variables'}
SECTIONS = {'jinja2:suite.rc', 'template variables'}
SET_BY_CYLC = 'set by Cylc'
ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING = (
' ROSE_ORIG_HOST set by cylc install.'
Expand All @@ -59,7 +59,7 @@
STANDARD_VARS = [
('ROSE_ORIG_HOST', get_host()),
('ROSE_VERSION', ROSE_VERSION),
('CYLC_VERSION', SET_BY_CYLC)
('CYLC_VERSION', SET_BY_CYLC),
]


Expand Down Expand Up @@ -104,7 +104,7 @@ def process_config(
# default return value
'env': {},
'template_variables': {},
'templating_detected': None
'templating_detected': None,
}
config_node = config_tree.node

Expand All @@ -127,7 +127,6 @@ def process_config(

# For each section process variables and add standard variables.
for section in ['env', templating]:

# This loop handles standard variables.
# CYLC_VERSION - If it's in the config, remove it.
# ROSE_VERSION - If it's in the config, replace it.
Expand All @@ -154,11 +153,8 @@ def process_config(
# Use env_var_process to process variables which may need expanding.
for key, node in config_node.value[section].value.items():
try:
config_node.value[
section
].value[key].value = env_var_process(
node.value,
environ=environ
config_node.value[section].value[key].value = env_var_process(
node.value, environ=environ
)
if section == 'env':
environ[key] = node.value
Expand All @@ -168,13 +164,13 @@ def process_config(
# For each of the template language sections extract items to a simple
# dict to be returned.
plugin_result['env'] = {
item[0][1]: item[1].value for item in
config_node.value['env'].walk()
item[0][1]: item[1].value
for item in config_node.value['env'].walk()
if item[1].state == ConfigNode.STATE_NORMAL
}
plugin_result['template_variables'] = {
item[0][1]: item[1].value for item in
config_node.value[templating].walk()
item[0][1]: item[1].value
for item in config_node.value[templating].walk()
if item[1].state == ConfigNode.STATE_NORMAL
}

Expand All @@ -198,12 +194,13 @@ def process_config(
value,
f'Invalid template variable: {value}'
'\nMust be a valid Python or Jinja2 literal'
' (note strings "must be quoted").'
' (note strings "must be quoted").',
) from None

# Add ROSE_SUITE_VARIABLES to plugin_result of templating engines in use.
plugin_result['template_variables'][
'ROSE_SUITE_VARIABLES'] = plugin_result['template_variables']
plugin_result['template_variables']['ROSE_SUITE_VARIABLES'] = (
plugin_result['template_variables']
)

return plugin_result

Expand All @@ -227,15 +224,12 @@ def identify_templating_section(config_node):


def id_templating_section(
section: Optional[str] = None,
with_brackets: bool = False
section: Optional[str] = None, with_brackets: bool = False
) -> str:
"""Return a full template section string."""
templating = None
if section and 'jinja2' in section:
templating = 'jinja2:suite.rc'
elif section and 'empy' in section:
templating = 'empy:suite.rc'

if not templating:
templating = 'template variables'
Expand Down Expand Up @@ -293,6 +287,7 @@ def rose_config_tree_loader(

# Load the config tree
from metomi.rose.config_tree import ConfigTreeLoader

config_tree = ConfigTreeLoader().load(
str(srcdir),
'rose-suite.conf',
Expand Down Expand Up @@ -340,7 +335,7 @@ def merge_rose_cylc_suite_install_conf(old, new):
>>> merge_rose_cylc_suite_install_conf(old, new)['opts']
{'value': 'a b c d e', 'state': '', 'comments': []}
"""
# remove jinja2/empy:suite.rc from old if template variables in new
# remove jinja2:suite.rc from old if template variables in new
for before, after in itertools.permutations(SECTIONS, 2):
if new.value.get(after, '') and old.value.get(before, ''):
# Choosing not to warn if user downgrades here because
Expand Down Expand Up @@ -395,12 +390,16 @@ def invalid_defines_check(defines: List) -> None:
raise InvalidDefineError(msg)


def parse_cli_defines(define: str) -> Union[
bool, str, Tuple[
def parse_cli_defines(
define: str,
) -> Union[
bool,
str,
Tuple[
List[Union[str, Any]],
Union[str, Any],
Union[str, Any],
]
],
]:
"""Parse a define string.
Expand Down Expand Up @@ -435,15 +434,16 @@ def parse_cli_defines(define: str) -> Union[
r'^\[(?P<section>.*)\](?P<state>!{0,2})'
r'(?P<key>.*)\s*=\s*(?P<value>.*)'
),
define
define,
)
if match:
groupdict = match.groupdict()
keys = [groupdict['section'].strip(), groupdict['key'].strip()]
else:
# Doesn't have a section:
match = re.match(
r'^(?P<state>!{0,2})(?P<key>.*)\s*=\s*(?P<value>.*)', define)
r'^(?P<state>!{0,2})(?P<key>.*)\s*=\s*(?P<value>.*)', define
)
if match and not match['state']:
groupdict = match.groupdict()
keys = [groupdict['key'].strip()]
Expand Down Expand Up @@ -527,7 +527,7 @@ def get_cli_opts_node(srcdir: Path, opts: 'Values'):
newconfig.set(
keys=[templating, _match_groups['key']],
value=_match_groups['value'],
state=_match_groups['state']
state=_match_groups['state'],
)

# Specialised treatement of optional configs.
Expand Down Expand Up @@ -718,12 +718,9 @@ def override_this_variable(node, section, variable):
"""
if variable not in node[section]:
return False
elif (
variable != 'ROSE_ORIG_HOST'
or (
ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING not in
node[section][variable].comments
)
elif variable != 'ROSE_ORIG_HOST' or (
ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING
not in node[section][variable].comments
):
return True
return False
Expand Down Expand Up @@ -754,8 +751,8 @@ def rose_orig_host_set_by_cylc_install(node, section, var):
"""
if (
var in node[section]
and ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING in
node[section][var].comments
and ROSE_ORIG_HOST_INSTALLED_OVERRIDE_STRING
in node[section][var].comments
):
return True
return False
Expand All @@ -766,53 +763,42 @@ def deprecation_warnings(config_tree):
Logs a warning for deprecated items:
- "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': {
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."),
" 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."),
" 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.'),
'instead.'
),
ALL_MODES: True,
},
}
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()
):
info[ALL_MODES] or not cylc7_back_compat
) and name in string.lower():
LOG.warning(info[MESSAGE])


Expand Down Expand Up @@ -843,13 +829,10 @@ def load_rose_config(
"""
# Return a blank config dict if srcdir does not exist
if not rose_config_exists(srcdir):
if (
opts
and (
getattr(opts, "opt_conf_keys", None)
or getattr(opts, "defines", None)
or getattr(opts, "rose_template_vars", None)
)
if opts and (
getattr(opts, "opt_conf_keys", None)
or getattr(opts, "defines", None)
or getattr(opts, "rose_template_vars", None)
):
raise NotARoseSuiteException()
return ConfigTree()
Expand Down Expand Up @@ -951,9 +934,7 @@ def record_cylc_install_options(

# Get Values for standard ROSE variable ROSE_ORIG_HOST.
rose_orig_host = get_host()
for section in [
'env', 'jinja2:suite.rc', 'empy:suite.rc', 'template variables'
]:
for section in list(SECTIONS) + ['env']:
if section in cli_config:
cli_config[section].set(['ROSE_ORIG_HOST'], rose_orig_host)
cli_config[section]['ROSE_ORIG_HOST'].comments = [
Expand Down Expand Up @@ -1045,7 +1026,7 @@ def retrieve_installed_cli_opts(srcdir, opts):

# Get --suite-defines/-S
# Work out whether user has used "template variables", "jinja2:suite.rc"
# or "empy:suite.rc" (There is an assumption that they aren't mixing
# (There is an assumption that they aren't mixing
# them that is not guarded against):
for section in SECTIONS:
if cli_config.value.get(section, False):
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ async def _inner(wid, args):
# Handle scripts taking a parser or just the output of the parser:
for script_name, n_args in {
'config': 3,
'list': 3,
'list': 2,
'graph': 3,
'view': 2,
'validate': 3,
Expand Down
Loading

0 comments on commit 1100801

Please sign in to comment.