Skip to content

Commit

Permalink
added Cylc lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Jun 24, 2022
1 parent 4a1ed03 commit f171c72
Show file tree
Hide file tree
Showing 12 changed files with 826 additions and 123 deletions.
6 changes: 3 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ default job runner directives for platforms.
[#4887](https://github.com/cylc/cylc-flow/pull/4887) - Disallow relative paths
in `global.cylc[install]source dirs`.

### Fixes
[#4900](https://github.com/cylc/cylc-flow/pull/4900) - Added a command to assist
with upgrading Cylc 7 workflows to Cylc 8: Try `cylc 728 <workflow-dir>`.

[#4926](https://github.com/cylc/cylc-flow/pull/4926) - Fix a docstring
formatting problem presenting in the UI mutation flow argument info.
### Fixes

[#4891](https://github.com/cylc/cylc-flow/pull/4891) - Fix bug that could cause
past jobs to be omitted in the UI.
Expand Down
33 changes: 6 additions & 27 deletions cylc/flow/id.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from enum import Enum
import re
from typing import (
Iterable,
List,
Optional,
Tuple,
Expand Down Expand Up @@ -782,19 +781,13 @@ def detokenise(
return '/'.join(identifier)


def upgrade_legacy_ids(*ids: str, relative=False) -> List[str]:
def upgrade_legacy_ids(*ids: str) -> List[str]:
"""Reformat IDs from legacy to contemporary format:
If no upgrading is required it returns the identifiers unchanged.
Args:
*ids:
Identifier list.
relative:
If `False` then `ids` must describe absolute ID(s) e.g:
workflow task1.cycle1 task2.cycle2
If `True` then `ids` should be relative e.g:
task1.cycle1 task2.cycle2
*ids (tuple): Identifier list.
Returns:
tuple/list - Identifier list.
Expand Down Expand Up @@ -822,27 +815,13 @@ def upgrade_legacy_ids(*ids: str, relative=False) -> List[str]:
>>> upgrade_legacy_ids('workflow', 'task.123:abc', '234/task:def')
['workflow', '//123/task:abc', '//234/task:def']
# upgrade relative IDs:
>>> upgrade_legacy_ids('x.1', relative=True)
['1/x']
>>> upgrade_legacy_ids('x.1', 'x.2', 'x.3:s', relative=True)
['1/x', '2/x', '3/x:s']
"""
if not relative and len(ids) < 2:
if len(ids) < 2:
# only legacy relative references require upgrade => abort
return list(ids)

legacy_ids: List[str]
_ids: Iterable[str]
if relative:
legacy_ids = []
_ids = ids
else:
legacy_ids = [ids[0]]
_ids = ids[1:]

for id_ in _ids:
legacy_ids = [ids[0]]
for id_ in ids[1:]:
try:
tokens = legacy_tokenise(id_)
except ValueError:
Expand All @@ -851,7 +830,7 @@ def upgrade_legacy_ids(*ids: str, relative=False) -> List[str]:
else:
# upgrade this token
legacy_ids.append(
detokenise(tokens, selectors=True, relative=relative)
detokenise(tokens, selectors=True)
)

LOG.warning(
Expand Down
12 changes: 1 addition & 11 deletions cylc/flow/id_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


import asyncio
import fnmatch
from pathlib import Path
import re
from typing import Optional, Dict, List, Tuple, Any

from cylc.flow import LOG
from cylc.flow.exceptions import (
InputError,
WorkflowFilesError,
Expand Down Expand Up @@ -397,16 +397,6 @@ def _validate_workflow_ids(*tokens_list, src_path):
raise InputError(
f'Workflow ID cannot be a file: {tokens["workflow"]}'
)
if tokens['cycle'] and tokens['cycle'].startswith('run'):
# issue a warning if the run number is provided after the //
# separator e.g. workflow//run1 rather than workflow/run1//
suggested = Tokens(
user=tokens['user'],
workflow=f'{tokens["workflow"]}/{tokens["cycle"]}',
cycle=tokens['task'],
task=tokens['job'],
)
LOG.warning(f'Did you mean: {suggested.id}')
detect_both_flow_and_suite(src_path)


Expand Down
12 changes: 9 additions & 3 deletions cylc/flow/network/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,9 +1391,15 @@ def description(self):


class Flow(String):
__doc__ = (
f"""An integer or one of {FLOW_ALL}, {FLOW_NEW} or {FLOW_NONE}."""
)
"""An integer or one of {FLOW_ALL}, {FLOW_NEW} or {FLOW_NONE}."""


# NOTE: docstrings can't be f-strings so we must manually format it.
Flow.__doc__ = Flow.__doc__.format( # type: ignore[union-attr]
FLOW_ALL=FLOW_ALL,
FLOW_NEW=FLOW_NEW,
FLOW_NONE=FLOW_NONE,
)


# Mutations:
Expand Down
22 changes: 8 additions & 14 deletions cylc/flow/option_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,6 @@ def format_shell_examples(string):
)


def verbosity_to_log_level(verb: int) -> int:
"""Convert Cylc verbosity to log severity level."""
if verb < 0:
return logging.WARNING
if verb > 0:
return logging.DEBUG
return logging.INFO


def verbosity_to_opts(verb: int) -> List[str]:
"""Convert Cylc verbosity to the CLI opts required to replicate it.
Expand Down Expand Up @@ -476,7 +467,12 @@ def parse_args(self, api_args, remove_opts=None):
# better choice for the logging stream. This allows us to use STDOUT
# for verbosity agnostic outputs.
# 2. Scheduler will remove this handler when it becomes a daemon.
LOG.setLevel(verbosity_to_log_level(options.verbosity))
if options.verbosity < 0:
LOG.setLevel(logging.WARNING)
elif options.verbosity > 0:
LOG.setLevel(logging.DEBUG)
else:
LOG.setLevel(logging.INFO)
RSYNC_LOG.setLevel(logging.INFO)
# Remove NullHandler before add the StreamHandler
for log in (LOG, RSYNC_LOG):
Expand Down Expand Up @@ -534,9 +530,9 @@ class Options:
But you can't create new options at initiation, this gives us basic
input validation:
>>> PythonOptions(e=6)
>>> opts(e=6)
Traceback (most recent call last):
ValueError: e
TypeError: 'Values' object is not callable
You can reuse the object multiple times
>>> opts2 = PythonOptions(a=2)
Expand All @@ -550,8 +546,6 @@ def __init__(
) -> None:
if overrides is None:
overrides = {}
if isinstance(parser, CylcOptionParser) and parser.auto_add:
parser.add_std_options()
self.defaults = {**parser.defaults, **overrides}

def __call__(self, **kwargs) -> Values:
Expand Down
6 changes: 0 additions & 6 deletions cylc/flow/scheduler_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from cylc.flow import LOG, RSYNC_LOG
from cylc.flow.exceptions import ServiceFileError
import cylc.flow.flags
from cylc.flow.id import upgrade_legacy_ids
from cylc.flow.host_select import select_workflow_host
from cylc.flow.hostuserutil import is_remote_host
from cylc.flow.id_cli import parse_ids
Expand Down Expand Up @@ -412,9 +411,4 @@ async def _run(scheduler: Scheduler) -> int:
@cli_function(get_option_parser)
def play(parser: COP, options: 'Values', id_: str):
"""Implement cylc play."""
if options.starttask:
options.starttask = upgrade_legacy_ids(
*options.starttask,
relative=True,
)
return scheduler_cli(options, id_)
Loading

0 comments on commit f171c72

Please sign in to comment.