Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/8.1.x' into dont_get_platform_…
Browse files Browse the repository at this point in the history
…too_soon

* upstream/8.1.x:
  Fix.platform is regex remote tidy fail (cylc#5445)
  parsec: better error messages for section/setting mixups
  cat-log: change interface for scheduler logs to include the dirname
  cat-log: support other workflow files
  Fix workflow shutdown on no platforms error (cylc#5395)
  actions: add build test
  • Loading branch information
wxtim committed Apr 21, 2023
2 parents f81d085 + 39159b8 commit 1249b4a
Show file tree
Hide file tree
Showing 21 changed files with 747 additions and 204 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build

# build the project whenever the configuration is changed

on:
workflow_dispatch:
pull_request:
paths:
- 'README.md' # check markdown is valid
- 'MANIFEST.in' # check packaging
- 'pyproject.toml' # check build config
- 'setup.cfg' # check deps and project config

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
matrix:
os: ['ubuntu-latest']
python: ['3.7', '3.8', '3.9', '3.10']
include:
- os: 'macos-latest'
python: '3.7'
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

- name: Build
uses: cylc/release-actions/build-python-package@v1

- name: Inspect
run: |
unzip -l dist/*.whl | tee files
grep 'cylc/flow/py.typed' files
grep 'cylc/flow/etc' files
grep 'cylc/flow/etc/cylc-completion.bash' files
14 changes: 14 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@ 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-8.1.3 (<span actions:bind='release-date'>Upcoming</span>)__

### Enhancements

[#5453](https://github.com/cylc/cylc-flow/pull/5453) - `cylc cat-log` can now
list and view workflow log files including install logs and workflow
configuration files.

### Fixes

[5450](https://github.com/cylc/cylc-flow/pull/5450) - Validation provides
better error messages if [sections] and settings are mixed up in a
configuration.

[5445](https://github.com/cylc/cylc-flow/pull/5445) - Fix remote tidy
bug where install target is not explicit in platform definition.

[5398](https://github.com/cylc/cylc-flow/pull/5398) - Fix platform from
group selection order bug.

Expand Down
7 changes: 0 additions & 7 deletions cylc/flow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@ def __init__(
except KeyError:
parameter_templates = {}

# Check that parameter templates are a section
if not hasattr(parameter_templates, 'update'):
raise WorkflowConfigError(
'[task parameters][templates] is a section. Don\'t use it '
'as a parameter.'
)

# parameter values and templates are normally needed together.
self.parameters = (parameter_values, parameter_templates)

Expand Down
25 changes: 21 additions & 4 deletions cylc/flow/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,29 @@ def __str__(self):


class NoPlatformsError(PlatformLookupError):
"""None of the platforms of a given group were reachable."""
def __init__(self, platform_group):
self.platform_group = platform_group
"""None of the platforms of a given set were reachable.
Args:
identity: The name of the platform group or install target
set_type: Whether the set of platforms is a platform group or an
install target
place: Where the attempt to get the platform failed.
"""
def __init__(
self, identity: str, set_type: str = 'group', place: str = ''
):
self.identity = identity
self.type = set_type
if place:
self.place = f' during {place}.'
else:
self.place = '.'

def __str__(self):
return f'Unable to find a platform from group {self.platform_group}.'
return (
f'Unable to find a platform from {self.type} {self.identity}'
f'{self.place}'
)


class CylcVersionError(CylcError):
Expand Down
8 changes: 7 additions & 1 deletion cylc/flow/parsec/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ def obsolete(self, vn, oldkeys, silent=False, is_section=False):
def get_item(self, keys):
item = self.cfg
for key in keys:
item = item[key]
try:
item = item[key]
except TypeError:
raise UpgradeError(
f'{self.show_keys(keys[:-1], True)}'
f' ("{keys[-2]}" should be a [section] not a setting)'
)
return item

def put_item(self, keys, val):
Expand Down
22 changes: 20 additions & 2 deletions cylc/flow/parsec/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,28 @@ def validate(self, cfg_root, spec_root):
else:
speckey = key
specval = spec[speckey]
if isinstance(value, dict) and not specval.is_leaf():

cfg_is_section = isinstance(value, dict)
spec_is_section = not specval.is_leaf()
if cfg_is_section and not spec_is_section:
# config is a [section] but it should be a setting=
raise IllegalItemError(
keys,
key,
msg=f'"{key}" should be a setting not a [section]',
)
if (not cfg_is_section) and spec_is_section:
# config is a setting= but it should be a [section]
raise IllegalItemError(
keys,
key,
msg=f'"{key}" should be a [section] not a setting',
)

if cfg_is_section and spec_is_section:
# Item is dict, push to queue
queue.append([value, specval, keys + [key]])
elif value is not None and specval.is_leaf():
elif value is not None and not spec_is_section:
# Item is value, coerce according to value type
cfg[key] = self.coercers[specval.vdr](value, keys + [key])
if specval.options:
Expand Down
52 changes: 16 additions & 36 deletions cylc/flow/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import re
from copy import deepcopy
from typing import (
TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Set, Union, overload
TYPE_CHECKING, Any, Dict, Iterable,
List, Optional, Set, Union, overload
)

from cylc.flow import LOG
Expand Down Expand Up @@ -128,7 +129,7 @@ def get_platform(
Raises:
NoPlatformsError:
Platform group has no platforms with usable hosts.
This should be caught if this function is used on a raw on config,
This should be caught if this function is used on a raw config,
or in any other context where a platform group might be selected.
PlatformLookupError:
Raised if the name of a platform cannot be selected based on the
Expand Down Expand Up @@ -630,18 +631,29 @@ def get_install_target_from_platform(platform: Dict[str, Any]) -> str:


def get_install_target_to_platforms_map(
platform_names: Iterable[str]
platform_names: Iterable[str],
quiet: bool = False
) -> Dict[str, List[Dict[str, Any]]]:
"""Get a dictionary of unique install targets and the platforms which use
them.
Args:
platform_names: List of platform names to look up in the global config.
quiet: Supress PlatformNotFound Errors
Return {install_target_1: [platform_1_dict, platform_2_dict, ...], ...}
"""
platform_names = set(platform_names)
platforms = [platform_from_name(p_name) for p_name in platform_names]
platforms: List[Dict[str, Any]] = []
for p_name in platform_names:
try:
platform = platform_from_name(p_name)
except PlatformLookupError as exc:
if not quiet:
raise exc
else:
platforms.append(platform)

install_targets = {
get_install_target_from_platform(platform)
for platform in platforms
Expand All @@ -667,38 +679,6 @@ def is_platform_with_target_in_list(
)


def get_all_platforms_for_install_target(
install_target: str
) -> List[Dict[str, Any]]:
"""Return list of platform dictionaries for given install target."""
platforms: List[Dict[str, Any]] = []
all_platforms = glbl_cfg(cached=True).get(['platforms'], sparse=False)
for k, v in all_platforms.iteritems(): # noqa: B301 (iteritems valid here)
if (v.get('install target', k) == install_target):
v_copy = deepcopy(v)
v_copy['name'] = k
platforms.append(v_copy)
return platforms


def get_random_platform_for_install_target(
install_target: str
) -> Dict[str, Any]:
"""Return a randomly selected platform (dict) for given install target.
Raises:
PlatformLookupError: We can't get a platform for this install target.
"""
platforms = get_all_platforms_for_install_target(install_target)
try:
return random.choice(platforms) # nosec (not crypto related)
except IndexError:
# No platforms to choose from
raise PlatformLookupError(
f'Could not select platform for install target: {install_target}'
)


def get_localhost_install_target() -> str:
"""Returns the install target of localhost platform"""
localhost = get_platform()
Expand Down
Loading

0 comments on commit 1249b4a

Please sign in to comment.