diff --git a/CHANGES.md b/CHANGES.md index 91cc40a2af9..83c3f90203c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -56,6 +56,8 @@ Third beta release of Cylc 8. ### Enhancements +[#4291](https://github.com/cylc/cylc-flow/pull/4291) + - Remove obsolete `cylc edit` and `cylc search` commands. [#4284](https://github.com/cylc/cylc-flow/pull/4284) - Make `--color=never` work with `cylc --help`. diff --git a/cylc/flow/etc/cylc-bash-completion b/cylc/flow/etc/cylc-bash-completion index 45f4c0a23c6..4623e1e2c90 100644 --- a/cylc/flow/etc/cylc-bash-completion +++ b/cylc/flow/etc/cylc-bash-completion @@ -38,7 +38,7 @@ _cylc() { cur="${COMP_WORDS[COMP_CWORD]}" sec="${COMP_WORDS[1]}" opts="$(cylc scan -t name 2>/dev/null)" - workflow_cmds="broadcast|bcast|cat-log|check-versions|clean|compare|config|diff|dump|edit|ext-trigger|external-trigger|get-workflow-version|get-cylc-version|graph|hold|insert|install|kill|list|log|ls|tui|pause|ping|play|poll|print|reinstall|release|unhold|reload|remove|report-timings|reset|scan|search|grep|set-verbosity|show|set-outputs|stop|shutdown|single|workflow-state|test-battery|trigger|validate|view|warranty" + workflow_cmds="broadcast|bcast|cat-log|check-versions|clean|compare|config|diff|dump|ext-trigger|external-trigger|get-workflow-version|get-cylc-version|graph|hold|insert|install|kill|list|log|ls|tui|pause|ping|play|poll|print|reinstall|release|unhold|reload|remove|report-timings|reset|scan|set-verbosity|show|set-outputs|stop|shutdown|single|workflow-state|test-battery|trigger|validate|view|warranty" if [[ ${COMP_CWORD} -eq 1 ]]; then diff --git a/cylc/flow/parsec/fileparse.py b/cylc/flow/parsec/fileparse.py index 5a4e46feab7..e118ca7a00e 100644 --- a/cylc/flow/parsec/fileparse.py +++ b/cylc/flow/parsec/fileparse.py @@ -278,7 +278,7 @@ def process_plugins(fpath): return extra_vars -def read_and_proc(fpath, template_vars=None, viewcfg=None, asedit=False): +def read_and_proc(fpath, template_vars=None, viewcfg=None): """ Read a cylc parsec config file (at fpath), inline any include files, process with Jinja2, and concatenate continuation lines. @@ -324,7 +324,7 @@ def read_and_proc(fpath, template_vars=None, viewcfg=None, asedit=False): # inline any cylc include-files if do_inline: flines = inline( - flines, fdir, fpath, False, viewcfg=viewcfg, for_edit=asedit) + flines, fdir, fpath, viewcfg=viewcfg) template_vars['CYLC_VERSION'] = __version__ diff --git a/cylc/flow/parsec/include.py b/cylc/flow/parsec/include.py index aaf4ea67fc5..c8d6425509d 100644 --- a/cylc/flow/parsec/include.py +++ b/cylc/flow/parsec/include.py @@ -14,28 +14,20 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import datetime import os import re -import sys -from shutil import copy as shcopy -from textwrap import dedent from cylc.flow.parsec.exceptions import ( FileParseError, IncludeFileNotFoundError) done = [] -modtimes = {} -backups = {} -newfiles = [] flist = [] include_re = re.compile(r'\s*%include\s+([\'"]?)(.*?)([\'"]?)\s*$') -def inline(lines, dir_, filename, for_grep=False, for_edit=False, viewcfg=None, - level=None): +def inline(lines, dir_, filename, for_grep=False, viewcfg=None, level=None): """Recursive inlining of parsec include-files""" global flist @@ -55,36 +47,16 @@ def inline(lines, dir_, filename, for_grep=False, for_edit=False, viewcfg=None, viewcfg = {} global done - global modtimes outf = [] initial_line_index = 0 if level is None: level = '' - if for_edit: - m = re.match('^(#![jJ]inja2)', lines[0]) - if m: - outf.append(m.groups()[0]) - initial_line_index = 1 - outf.append( - """# !WARNING! CYLC EDIT INLINED (DO NOT MODIFY THIS LINE). -# !WARNING! This is an inlined parsec config file; include-files are split -# !WARNING! out again on exiting the edit session. If you are editing -# !WARNING! this file manually then a previous inlined session may have -# !WARNING! crashed; exit now and use 'cylc edit -i' to recover (this -# !WARNING! will split the file up again on exiting).""") + elif mark: + level += '!' - else: - if mark: - level += '!' - elif for_edit: - level += ' > ' - - if for_edit: - msg = ' (DO NOT MODIFY THIS LINE!)' - else: - msg = '' + msg = '' for line in lines[initial_line_index:]: m = include_re.match(line) @@ -98,119 +70,26 @@ def inline(lines, dir_, filename, for_grep=False, for_edit=False, viewcfg=None, ) inc = os.path.join(dir_, match) if inc not in done: - if single or for_edit: + if single: done.append(inc) - if for_edit: - backup(inc) - # store original modtime - modtimes[inc] = os.stat(inc).st_mtime if not os.path.isfile(inc): flist.append(inc) raise IncludeFileNotFoundError(flist) - if for_grep or single or label or for_edit: + if for_grep or single or label: outf.append( '#++++ START INLINED INCLUDE FILE ' + match + msg) with open(inc, 'r') as handle: finc = [line.rstrip('\n') for line in handle] # recursive inclusion outf.extend(inline( - finc, dir_, inc, for_grep, for_edit, viewcfg, level)) - if for_grep or single or label or for_edit: + finc, dir_, inc, for_grep, viewcfg, level)) + if for_grep or single or label: outf.append( '#++++ END INLINED INCLUDE FILE ' + match + msg) else: - if not for_edit: - outf.append(level + line) - else: - outf.append(line) + outf.append(level + line) else: # no match - if not for_edit: - outf.append(level + line) - else: - outf.append(line) + outf.append(level + line) return outf - - -def cleanup(workflowdir): - print('CLEANUP REQUESTED, deleting:') - for root, _, files in os.walk(workflowdir): - for filename in files: - if '.EDIT.' in filename: - print(' + %s' % filename.replace(workflowdir + '/', '')) - os.unlink(os.path.join(root, filename)) - - -def backup(src, tag=''): - if not os.path.exists(src): - raise SystemExit("File not found: " + src) - bkp = src + tag + '.EDIT.' + datetime.datetime.now().isoformat() - global backups - shcopy(src, bkp) - backups[src] = bkp - - -def split_file(dir_, lines, filename, recovery=False, level=None): - global modtimes - global newfiles - - if level is None: - # config file itself - level = '' - else: - level += ' > ' - # check mod time on the target file - if not recovery: - mtime = os.stat(filename).st_mtime - if mtime != modtimes[filename]: - # oops - original file has changed on disk since we started - # editing - filename += '.EDIT.NEW.' + datetime.datetime.now().isoformat() - newfiles.append(filename) - - inclines = [] - with open(filename, 'w') as fnew: - match_on = False - for line in lines: - if re.match('^# !WARNING!', line): - continue - if not match_on: - m = re.match( - r'^#\+\+\+\+ START INLINED INCLUDE FILE ' + - r'([\w/.\-]+) \(DO NOT MODIFY THIS LINE!\)', line) - if m: - match_on = True - inc_filename = m.groups()[0] - inc_file = os.path.join(dir_, m.groups()[0]) - fnew.write('%include ' + inc_filename + '\n') - else: - fnew.write(line) - elif match_on: - # match on, go to end of the 'on' include-file - m = re.match( - r'^#\+\+\+\+ END INLINED INCLUDE FILE ' + - inc_filename + r' \(DO NOT MODIFY THIS LINE!\)', line) - if m: - match_on = False - # now split this lot, in case of nested inclusions - split_file(dir_, inclines, inc_file, recovery, level) - # now empty the inclines list ready for the next inclusion - # in this file - inclines = [] - else: - inclines.append(line) - if match_on: - for line in inclines: - fnew.write(line) - print(file=sys.stderr) - print(( - "ERROR: end-of-file reached while matching include-file", - inc_filename + "."), file=sys.stderr) - print(dedent( - """This probably means you have corrupted the inlined file by - modifying one of the include-file boundary markers. Fix the - backed- up inlined file, copy it to the original filename and - invoke another inlined edit session split the file up again.""" - ), file=sys.stderr) - print(file=sys.stderr) diff --git a/cylc/flow/scheduler_cli.py b/cylc/flow/scheduler_cli.py index 63e68a64410..918a2e09215 100644 --- a/cylc/flow/scheduler_cli.py +++ b/cylc/flow/scheduler_cli.py @@ -45,8 +45,7 @@ PLAY_DOC = r"""cylc play [OPTIONS] ARGS -Start a newly-installed workflow from scratch, restart a stopped workflow, or -resume a paused workflow. +Start a new workflow, restart a stopped workflow, or resume a paused workflow. The scheduler will run as a daemon unless you specify --no-detach. diff --git a/cylc/flow/scripts/cylc.py b/cylc/flow/scripts/cylc.py index b7c8d41c004..8d8b2007e02 100644 --- a/cylc/flow/scripts/cylc.py +++ b/cylc/flow/scripts/cylc.py @@ -105,7 +105,6 @@ def get_version(long=False): 'external-trigger': 'ext-trigger', 'get-contact': 'get-workflow-contact', 'get-cylc-version': 'get-workflow-version', - 'grep': 'search', 'log': 'cat-log', 'ls': 'list', 'shutdown': 'stop', diff --git a/cylc/flow/scripts/edit.py b/cylc/flow/scripts/edit.py deleted file mode 100755 index 02f917668c2..00000000000 --- a/cylc/flow/scripts/edit.py +++ /dev/null @@ -1,213 +0,0 @@ -#!/usr/bin/env python3 - -# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. -# Copyright (C) NIWA & British Crown (Met Office) & Contributors. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -"""cylc edit [OPTIONS] ARGS - -Edit workflow definitions. - -Edit workflow definitions without having to move to their directory -locations, and with optional reversible inlining of include-files. Note -that Jinja2 workflows can only be edited in raw form but the processed -version can be viewed with 'cylc view -p'. - -1/ cylc edit WORKFLOW -Change to the workflow definition directory and edit the flow.cylc file. - -2/ cylc edit -i,--inline WORKFLOW -Edit the workflow with include-files inlined between special markers. The -original flow.cylc file is temporarily replaced so that the inlined -version is "live" during editing (i.e. you can run workflows during -editing and cylc will pick up changes to the workflow definition). The -inlined file is then split into its constituent include-files -again when you exit the editor. Include-files can be nested or -multiply-included; in the latter case only the first inclusion is -inlined (this prevents conflicting changes made to the same file). - -3/ cylc edit --cleanup WORKFLOW -Remove backup files left by previous INLINED edit sessions. - -INLINED EDITING SAFETY: The flow.cylc file and its include-files are -automatically backed up prior to an inlined editing session. If the -editor dies mid-session just invoke 'cylc edit -i' again to recover from -the last saved inlined file. On exiting the editor, if any of the -original include-files are found to have changed due to external -intervention during editing you will be warned and the affected files -will be written to new backups instead of overwriting the originals. -Finally, the inlined flow.cylc file is also backed up on exiting -the editor, to allow recovery in case of accidental corruption of the -include-file boundary markers in the inlined file. - -The edit process is spawned in the foreground as follows: - $ flow.cylc -Where is defined in the cylc site/user config files. - -See also 'cylc view'.""" - -import os -import re -from subprocess import call -from shutil import copy -import sys - -from cylc.flow.exceptions import CylcError, UserInputError - -from cylc.flow.parsec.include import ( - inline, - split_file, - backup, - backups, - newfiles, - cleanup, - modtimes -) -from cylc.flow.cfgspec.glbl_cfg import glbl_cfg -from cylc.flow.option_parsers import CylcOptionParser as COP -from cylc.flow.workflow_files import parse_workflow_arg -from cylc.flow.terminal import cli_function -from cylc.flow.wallclock import get_current_time_string - - -def get_option_parser(): - parser = COP(__doc__, prep=True) - - parser.add_option( - "--inline", "-i", - help="Edit with include-files inlined as described above.", - action="store_true", default=False, dest="inline") - - parser.add_option( - "--cleanup", - help="Remove backup files left by previous inlined edit sessions.", - action="store_true", default=False, dest="cleanup") - - parser.add_option( - "--gui", "-g", help="Force use of the configured GUI editor.", - action="store_true", default=False, dest="geditor") - - return parser - - -@cli_function(get_option_parser) -def main(parser, options, *args): - flow_file = parse_workflow_arg(options, args[0])[1] - - if options.geditor: - editor = glbl_cfg().get(['editors', 'gui']) - else: - editor = glbl_cfg().get(['editors', 'terminal']) - - workflowdir = os.path.dirname(flow_file) - - if options.cleanup: - # remove backup files left by inlined editing sessions - cleanup(workflowdir) - sys.exit(0) - - if not options.inline: - # plain old editing. - # move to workflow def dir - os.chdir(workflowdir) - - # edit the flow.cylc file - if not os.path.isfile(flow_file): - raise UserInputError(f'file not found: {flow_file}') - - # in case editor has options, e.g. 'emacs -nw': - command_list = re.split(' ', editor) - command_list.append(flow_file) - command = ' '.join(command_list) - # THIS BLOCKS UNTIL THE COMMAND COMPLETES - retcode = call(command_list) - if retcode != 0: - # the command returned non-zero exist status - raise CylcError(f'{command} failed: {retcode}') - - # !!!EDITING FINISHED!!! - sys.exit(0) - - # read the flow.cylc file - if os.path.isfile(flow_file): - # back up the original - backup(flow_file) - # record original modtime - modtimes[flow_file] = os.stat(flow_file).st_mtime - # read the file - with open(flow_file, 'r') as handle: - lines0 = handle.readlines() - if lines0[0].startswith('# !WARNING! CYLC EDIT INLINED'): - print('WARNING: RECOVERING A PREVIOUSLY INLINED FILE') - recovery = True - lines = lines0 - else: - recovery = False - lines = inline(lines0, workflowdir, flow_file, for_edit=True) - else: - parser.error(f"File not found: {flow_file}") - - lines = [i.rstrip() for i in lines] - - # overwrite the (now backed up) original with the inlined file: - with open(flow_file, 'wb') as handle: - for line in lines: - handle.write((line + '\n').encode()) - - print('PRE-EDIT BACKUPS:') - for file in backups: - src = re.sub(workflowdir + '/', '', file) - dst = re.sub(workflowdir + '/', '', backups[file]) - print(' + ' + src + ' ---> ' + dst) - - # in case editor has options, e.g. 'emacs -nw': - command_list = re.split(' ', editor) - command_list.append(flow_file) - command = ' '.join(command_list) - # THIS BLOCKS UNTIL THE COMMAND COMPLETES - retcode = call(command_list) - if retcode != 0: - # the command returned non-zero exist status - raise CylcError(f'{command} failed: {retcode}') - print('EDITING DONE') - - # Now back up the inlined file in case of absolute disaster, so as the - # user or his editor corrupting the inlined-include-file marker lines. - inlined_flow_file_backup = ( - workflowdir + '/flow.cylc.INLINED.EDIT.' + - get_current_time_string(override_use_utc=True, use_basic_format=True) - ) - copy(flow_file, inlined_flow_file_backup) - - # read in the edited inlined file - with open(flow_file, 'r') as handle: - lines = handle.readlines() - - # split it back into separate files - split_file(workflowdir, lines, flow_file, recovery) - - print(f' + edited: {flow_file}') - print(f' + backup: {inlined_flow_file_backup}') - print('INCLUDE-FILES WRITTEN:') - for file in newfiles: - f = re.sub(workflowdir + '/', '', file) - if re.search(r'\.EDIT\.NEW\.', f): - print(' + ' + f + ' (!!! WARNING: original changed on disk !!!)') - else: - print(' + ' + f) - # DONE - - -if __name__ == "__main__": - main() diff --git a/cylc/flow/scripts/search.py b/cylc/flow/scripts/search.py deleted file mode 100755 index d22ff5f0521..00000000000 --- a/cylc/flow/scripts/search.py +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/env python3 - -# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. -# Copyright (C) NIWA & British Crown (Met Office) & Contributors. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -"""cylc search [OPTIONS] ARGS - -Search for patterns in workflow configurations. - -Search for pattern matches in workflow definitions and any files in the -workflow bin directory. Matches are reported by line number and workflow -section. An unquoted list of PATTERNs will be converted to an OR'd -pattern. Note that the order of command line arguments conforms to -normal cylc command usage (workflow name first) not that of the grep -command. - -Note that this command performs a text search on the workflow definition, -it does not search the data structure that results from parsing the -workflow definition - so it will not report implicit default settings. - -For case insensitive matching use '(?i)PATTERN'.""" - -from collections import deque -import os -import re -import sys - -from cylc.flow.option_parsers import CylcOptionParser as COP -from cylc.flow.workflow_files import parse_workflow_arg -from cylc.flow.terminal import cli_function -from cylc.flow.parsec.include import inline - - -def section_level(heading): - # e.g. foo => 0 - # [foo] => 1 - # [[foo]] => 2 - m = re.match(r'^(\[+)', heading) - if m: - level = len(m.groups()[0]) - else: - level = 0 - return level - - -def print_heading(heading): - print('>>>' + '->'.join(heading)) - - -def get_option_parser(): - parser = COP( - __doc__, prep=True, - argdoc=[('WORKFLOW', 'Workflow name or path'), - ('PATTERN', 'Python-style regular expression'), - ('[PATTERN2...]', 'Additional search patterns')]) - - parser.add_option( - "-x", help="Do not search in the workflow bin directory", - action="store_false", default=True, dest="search_bin") - - return parser - - -@cli_function(get_option_parser) -def main(parser, options, reg, *patterns): - workflow, flow_file = parse_workflow_arg(options, reg) - - # cylc search WORKFLOW PATTERN - pattern = '|'.join(patterns) - - workflowdir = os.path.dirname(flow_file) - - if os.path.isfile(flow_file): - with open(flow_file, 'r') as handle: - lines = handle.readlines() - lines = inline(lines, workflowdir, flow_file, for_grep=True) - else: - parser.error(f"File not found: {flow_file}") - - sections = deque(['(top)']) - - line_count = 1 - inc_file = None - in_include_file = False - prev_section_key = None - prev_file = None - - for line in lines: - - m = re.match( - r'^#\+\+\+\+ START INLINED INCLUDE FILE ([\w/\.\-]+)', line) - if m: - inc_file = m.groups()[0] - in_include_file = True - inc_line_count = 0 - continue - - if not in_include_file: - line_count += 1 - else: - inc_line_count += 1 - m = re.match( - r'^#\+\+\+\+ END INLINED INCLUDE FILE ' + inc_file, line) - if m: - in_include_file = False - inc_file = None - continue - - m = re.match(r'\s*(\[+\s*.+\s*\]+)', line) - if m: - # new section heading detected - heading = m.groups()[0] - level = section_level(heading) - # unwind to the current section level - while len(sections) > level - 1: - sections.pop() - sections.append(heading) - continue - - if re.search(pattern, line): - # Found a pattern match. - - # Print the file name - if in_include_file: - curr_file = os.path.join(workflowdir, inc_file) - line_no = inc_line_count - else: - curr_file = flow_file - line_no = line_count - - if curr_file != prev_file: - prev_file = curr_file - print("\nFILE:", curr_file) - - # Print the nested section headings - section_key = '->'.join(sections) - if section_key != prev_section_key: - prev_section_key = section_key - print(' SECTION:', section_key) - - # Print the pattern match, with line number - print(' (' + str(line_no) + '):', line.rstrip('\n')) - - if not options.search_bin: - sys.exit(0) - - # search files in workflow bin directory - bin_ = os.path.join(workflowdir, 'bin') - if not os.path.isdir(bin_): - print("\nWorkflow " + workflow + " has no bin directory", - file=sys.stderr) - sys.exit(0) - - for name in os.listdir(bin_): - if name.startswith('.'): - # skip hidden dot-files - # (e.g. vim editor temporary files) - continue - new_file = True - try: - with open(os.path.join(bin_, name), 'r') as handle: - contents = handle.readlines() - except IOError as exc: - # e.g. there's a sub-directory under bin; ignore it. - print('Unable to open file ' + os.path.join(bin_, name), - file=sys.stderr) - print(exc, file=sys.stderr) - continue - - for count, line in enumerate(contents): - line = line.rstrip('\n') - if re.search(pattern, line): - if new_file: - print('\nFILE:', os.path.join(bin_, name)) - new_file = False - print(' (' + str(count) + '): ' + line) - - -if __name__ == '__main__': - main() diff --git a/cylc/flow/scripts/view.py b/cylc/flow/scripts/view.py index ff9ff62ccec..8819521e006 100755 --- a/cylc/flow/scripts/view.py +++ b/cylc/flow/scripts/view.py @@ -30,8 +30,7 @@ The edit process is spawned in the foreground as follows: $ flow.cylc Where can be set in cylc global config. - -See also 'cylc edit'.""" +""" import sys @@ -106,12 +105,6 @@ def get_option_parser(): "--stdout", help="Print the workflow definition to stdout.", action="store_true", default=False, dest="stdout") - parser.add_option( - "--mark-for-edit", - help="(With '-i') View file inclusion markers as " - "for 'cylc edit --inline'.", - action="store_true", default=False, dest="asedit") - return parser @@ -137,7 +130,7 @@ def main(parser, options, reg): lines = read_and_proc( flow_file, load_template_vars(options.templatevars, options.templatevars_file), - viewcfg=viewcfg, asedit=options.asedit) + viewcfg=viewcfg) if options.stdout: for line in lines: @@ -175,13 +168,11 @@ def main(parser, options, reg): modtime2 = os.stat(viewfile.name).st_mtime if modtime2 > modtime1: - print() - print('WARNING: YOU HAVE EDITED A TEMPORARY READ-ONLY WORKFLOW COPY:', - file=sys.stderr) - print(viewfile.name, file=sys.stderr) - print('In future use \'cylc edit\' to edit a workflow.', - file=sys.stderr) - print() + print( + "\nWARNING: YOU HAVE EDITED A TEMPORARY READ-ONLY COPY " + f"OF THE WORKFLOW:\n {viewfile.name}\n", + file=sys.stderr + ) # DONE viewfile.close() diff --git a/setup.cfg b/setup.cfg index 1a4d5d8805d..6b6a28fcfcb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -76,7 +76,6 @@ cylc.command = cycle-point = cylc.flow.scripts.cycle_point:main diff = cylc.flow.scripts.diff:main dump = cylc.flow.scripts.dump:main - edit = cylc.flow.scripts.edit:main ext-trigger = cylc.flow.scripts.ext_trigger:main extract-resources = cylc.flow.scripts.extract_resources:main function-run = cylc.flow.scripts.function_run:main @@ -104,7 +103,6 @@ cylc.command = remove = cylc.flow.scripts.remove:main report-timings = cylc.flow.scripts.report_timings:main scan = cylc.flow.scripts.scan:cli - search = cylc.flow.scripts.search:main set-verbosity = cylc.flow.scripts.set_verbosity:main show = cylc.flow.scripts.show:main set-outputs = cylc.flow.scripts.set_outputs:main diff --git a/tests/functional/cylc-edit/00-basic.t b/tests/functional/cylc-edit/00-basic.t deleted file mode 100644 index ad5de567f51..00000000000 --- a/tests/functional/cylc-edit/00-basic.t +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash -# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. -# Copyright (C) NIWA & British Crown (Met Office) & Contributors. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- -# Test "cylc edit" basic usage. -. "$(dirname "$0")/test_header" -#------------------------------------------------------------------------------- -set_test_number 3 -install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}" -#------------------------------------------------------------------------------- -TEST_NAME="${TEST_NAME_BASE}-validate-before" -run_fail "${TEST_NAME}" cylc validate "${WORKFLOW_NAME}" - -TEST_NAME="${TEST_NAME_BASE}" -create_test_global_config '' ' -[editors] - terminal = my-edit' -PATH=$PWD/bin:$PATH run_ok "${TEST_NAME}" cylc edit -i "${WORKFLOW_NAME}" - -TEST_NAME="${TEST_NAME_BASE}-validate-after" -run_ok "${TEST_NAME}" cylc validate "${WORKFLOW_NAME}" -#------------------------------------------------------------------------------- -purge -exit diff --git a/tests/functional/cylc-edit/00-basic/bin/my-edit b/tests/functional/cylc-edit/00-basic/bin/my-edit deleted file mode 100755 index 6fdaaff2466..00000000000 --- a/tests/functional/cylc-edit/00-basic/bin/my-edit +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -sed -i 's/retry delays = 0.1/retry delays = PT6S/' "$@" diff --git a/tests/functional/cylc-edit/00-basic/flow.cylc b/tests/functional/cylc-edit/00-basic/flow.cylc deleted file mode 100644 index 7baa29d0355..00000000000 --- a/tests/functional/cylc-edit/00-basic/flow.cylc +++ /dev/null @@ -1,8 +0,0 @@ -#!jinja2 -[meta] - title=foo - description=A test flow.cylc with includes -[scheduler] -UTC mode=True # Ignore DST -%include include/flow-scheduling.cylc -%include include/flow-runtime.cylc diff --git a/tests/functional/cylc-edit/00-basic/include/flow-runtime.cylc b/tests/functional/cylc-edit/00-basic/include/flow-runtime.cylc deleted file mode 100644 index 4088ffa54f4..00000000000 --- a/tests/functional/cylc-edit/00-basic/include/flow-runtime.cylc +++ /dev/null @@ -1,5 +0,0 @@ -[runtime] - [[foo, bar]] - script=true - [[[job]]] - execution retry delays = 0.1 diff --git a/tests/functional/cylc-edit/00-basic/include/flow-scheduling.cylc b/tests/functional/cylc-edit/00-basic/include/flow-scheduling.cylc deleted file mode 100644 index 17c2e21539e..00000000000 --- a/tests/functional/cylc-edit/00-basic/include/flow-scheduling.cylc +++ /dev/null @@ -1,5 +0,0 @@ -[scheduling] -initial cycle point=20130101 -final cycle point=20130110 -[[graph]] -P1D="""foo[-P2D]=>foo=>bar""" diff --git a/tests/functional/cylc-edit/test_header b/tests/functional/cylc-edit/test_header deleted file mode 120000 index 90bd5a36f92..00000000000 --- a/tests/functional/cylc-edit/test_header +++ /dev/null @@ -1 +0,0 @@ -../lib/bash/test_header \ No newline at end of file diff --git a/tests/functional/cylc-search/00-basic.t b/tests/functional/cylc-search/00-basic.t deleted file mode 100644 index b2f785e79f2..00000000000 --- a/tests/functional/cylc-search/00-basic.t +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. -# Copyright (C) NIWA & British Crown (Met Office) & Contributors. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -#------------------------------------------------------------------------------- -# Test "cylc search" basic usage. -. "$(dirname "$0")/test_header" -#------------------------------------------------------------------------------- -set_test_number 2 -install_workflow "${TEST_NAME_BASE}" "${TEST_NAME_BASE}" -#------------------------------------------------------------------------------- -TEST_NAME="${TEST_NAME_BASE}" -cd "${WORKFLOW_RUN_DIR}" || exit 1 -run_ok "${TEST_NAME}" cylc search "${WORKFLOW_NAME}" 'initial cycle point' -cmp_ok "${TEST_NAME}.stdout" <<__OUT__ - -FILE: ${PWD}/include/flow-scheduling.cylc - SECTION: [scheduling] - (2): initial cycle point=20130101 -__OUT__ -#------------------------------------------------------------------------------- -purge -exit diff --git a/tests/functional/cylc-search/00-basic/bin/my-command b/tests/functional/cylc-search/00-basic/bin/my-command deleted file mode 100755 index 2a41d5d499e..00000000000 --- a/tests/functional/cylc-search/00-basic/bin/my-command +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/usr/bin/env bash -exit diff --git a/tests/functional/cylc-search/00-basic/flow.cylc b/tests/functional/cylc-search/00-basic/flow.cylc deleted file mode 100644 index 7baa29d0355..00000000000 --- a/tests/functional/cylc-search/00-basic/flow.cylc +++ /dev/null @@ -1,8 +0,0 @@ -#!jinja2 -[meta] - title=foo - description=A test flow.cylc with includes -[scheduler] -UTC mode=True # Ignore DST -%include include/flow-scheduling.cylc -%include include/flow-runtime.cylc diff --git a/tests/functional/cylc-search/00-basic/include/flow-runtime.cylc b/tests/functional/cylc-search/00-basic/include/flow-runtime.cylc deleted file mode 100644 index 4485b2df60e..00000000000 --- a/tests/functional/cylc-search/00-basic/include/flow-runtime.cylc +++ /dev/null @@ -1,3 +0,0 @@ -[runtime] -[[foo, bar]] -script=true diff --git a/tests/functional/cylc-search/00-basic/include/flow-scheduling.cylc b/tests/functional/cylc-search/00-basic/include/flow-scheduling.cylc deleted file mode 100644 index 17c2e21539e..00000000000 --- a/tests/functional/cylc-search/00-basic/include/flow-scheduling.cylc +++ /dev/null @@ -1,5 +0,0 @@ -[scheduling] -initial cycle point=20130101 -final cycle point=20130110 -[[graph]] -P1D="""foo[-P2D]=>foo=>bar""" diff --git a/tests/functional/cylc-search/test_header b/tests/functional/cylc-search/test_header deleted file mode 120000 index 90bd5a36f92..00000000000 --- a/tests/functional/cylc-search/test_header +++ /dev/null @@ -1 +0,0 @@ -../lib/bash/test_header \ No newline at end of file diff --git a/tests/functional/include-files/00-basic.t b/tests/functional/include-files/00-basic.t index 6d8d89ea1ba..cd7ca5daf25 100644 --- a/tests/functional/include-files/00-basic.t +++ b/tests/functional/include-files/00-basic.t @@ -25,9 +25,10 @@ install_workflow "${TEST_NAME_BASE}" workflow TEST_NAME="${TEST_NAME_BASE}-validate" # test raw workflow validates run_ok "${TEST_NAME}.1" cylc val "${WORKFLOW_NAME}" + # test workflow validates as inlined during editing -cylc view --inline --mark-for-edit --stdout "${WORKFLOW_NAME}" > inlined-for-edit.cylc -run_ok "${TEST_NAME}.2" cylc val inlined-for-edit.cylc +cylc view --inline --stdout "${WORKFLOW_NAME}" > inlined.cylc +run_ok "${TEST_NAME}.2" cylc val inlined.cylc #------------------------------------------------------------------------------- # compare inlined workflow def with reference copy TEST_NAME=${TEST_NAME_BASE}-compare diff --git a/tests/unit/parsec/test_empysupport.py b/tests/unit/parsec/test_empysupport.py index d16931d8ac4..4b518507d09 100644 --- a/tests/unit/parsec/test_empysupport.py +++ b/tests/unit/parsec/test_empysupport.py @@ -71,18 +71,17 @@ def test_empysupport_empyprocess(self): 'empy': True, 'jinja2': False, 'contin': False, 'inline': False } - asedit = None tf.write("#!empy\na=@name\n".encode()) tf.flush() r = read_and_proc(fpath=fpath, template_vars=template_vars, - viewcfg=viewcfg, asedit=asedit) + viewcfg=viewcfg) self.assertEqual(['a=Cylc'], r) del template_vars['name'] with self.assertRaises(EmPyError): read_and_proc(fpath=fpath, template_vars=template_vars, - viewcfg=viewcfg, asedit=asedit) + viewcfg=viewcfg) sys.stdout.getvalue = lambda: '' sys.stdout.getvalue = lambda: '' diff --git a/tests/unit/parsec/test_fileparse.py b/tests/unit/parsec/test_fileparse.py index 08a0279b03f..1c8d8c09410 100644 --- a/tests/unit/parsec/test_fileparse.py +++ b/tests/unit/parsec/test_fileparse.py @@ -272,11 +272,10 @@ def test_read_and_proc_no_template_engine(): 'empy': False, 'jinja2': False, 'contin': False, 'inline': False } - asedit = None tf.write("a=b\n".encode()) tf.flush() r = read_and_proc(fpath=fpath, template_vars=template_vars, - viewcfg=viewcfg, asedit=asedit) + viewcfg=viewcfg) assert r == ['a=b'] # last \\ is ignored, becoming just '' @@ -288,7 +287,7 @@ def test_read_and_proc_no_template_engine(): 'contin': True, 'inline': False } r = read_and_proc(fpath=fpath, template_vars=template_vars, - viewcfg=viewcfg, asedit=asedit) + viewcfg=viewcfg) assert r == ['a=b', 'c=d', ''] @@ -301,7 +300,6 @@ def test_inline(): 'contin': False, 'inline': True, 'mark': None, 'single': None, 'label': None } - asedit = None with tempfile.NamedTemporaryFile() as include_file: include_file.write("c=d".encode()) include_file.flush() @@ -309,7 +307,7 @@ def test_inline(): .format(include_file.name)).encode()) tf.flush() r = read_and_proc(fpath=fpath, template_vars=template_vars, - viewcfg=viewcfg, asedit=asedit) + viewcfg=viewcfg) assert r == ['a=b', 'c=d'] @@ -322,12 +320,11 @@ def test_inline_error(): 'contin': False, 'inline': True, 'mark': None, 'single': None, 'label': None } - asedit = None tf.write("a=b\n%include \"404.txt\"".encode()) tf.flush() with pytest.raises(IncludeFileNotFoundError) as cm: read_and_proc(fpath=fpath, template_vars=template_vars, - viewcfg=viewcfg, asedit=asedit) + viewcfg=viewcfg) assert "404.txt" in str(cm.value) @@ -341,11 +338,10 @@ def test_read_and_proc_jinja2(): 'empy': False, 'jinja2': True, 'contin': False, 'inline': False } - asedit = None tf.write("#!jinja2\na={{ name }}\n".encode()) tf.flush() r = read_and_proc(fpath=fpath, template_vars=template_vars, - viewcfg=viewcfg, asedit=asedit) + viewcfg=viewcfg) assert r == ['a=Cylc'] @@ -359,12 +355,11 @@ def test_read_and_proc_jinja2_error(): 'empy': False, 'jinja2': True, 'contin': False, 'inline': False } - asedit = None tf.write("#!jinja2\na={{ name \n".encode()) tf.flush() with pytest.raises(Jinja2Error) as cm: read_and_proc(fpath=fpath, template_vars=template_vars, - viewcfg=viewcfg, asedit=asedit) + viewcfg=viewcfg) assert ( "unexpected end of template, expected " "'end of print statement'." @@ -381,12 +376,11 @@ def test_read_and_proc_jinja2_error_missing_shebang(): 'empy': False, 'jinja2': True, 'contin': False, 'inline': False } - asedit = None # first line is missing shebang! tf.write("a={{ name }}\n".encode()) tf.flush() r = read_and_proc(fpath=fpath, template_vars=template_vars, - viewcfg=viewcfg, asedit=asedit) + viewcfg=viewcfg) assert r == ['a={{ name }}'] diff --git a/tests/unit/parsec/test_include.py b/tests/unit/parsec/test_include.py index e818cdbbc38..2298495bd46 100644 --- a/tests/unit/parsec/test_include.py +++ b/tests/unit/parsec/test_include.py @@ -19,11 +19,12 @@ tests. So this suite of unit tests should not cover all the module features. """ +import os import tempfile import unittest from cylc.flow.parsec.exceptions import ParsecError -from cylc.flow.parsec.include import * +from cylc.flow.parsec.include import inline, IncludeFileNotFoundError class TestInclude(unittest.TestCase): @@ -35,22 +36,6 @@ def test_include_file_not_found_error(self): error = IncludeFileNotFoundError(file_list) self.assertTrue(" via " in str(error)) - def test_inline_error_empty_lines_1(self): - """The inline function throws an error when you have the following - combination: - - - lines is an empty list - - for_edit is True - - level is None - """ - with self.assertRaises(IndexError): - inline( - lines=[], - dir_=None, - filename=None, - for_edit=True, - level=None) - def test_inline_error_mismatched_quotes(self): """The inline function throws an error when you have the %include statement with a value without the correct balance @@ -61,7 +46,6 @@ def test_inline_error_mismatched_quotes(self): lines=["%include 'abc.txt"], dir_=None, filename=None, - for_edit=True, level=None) def test_inline(self):