Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old "edit" and "search" commands. #4291

Merged
merged 4 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <command> --help`.
Expand Down
2 changes: 1 addition & 1 deletion cylc/flow/etc/cylc-bash-completion
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cylc/flow/parsec/fileparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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__

Expand Down
141 changes: 10 additions & 131 deletions cylc/flow/parsec/include.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,20 @@
# 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 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
Expand All @@ -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)
Expand All @@ -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)
3 changes: 1 addition & 2 deletions cylc/flow/scheduler_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 0 additions & 1 deletion cylc/flow/scripts/cylc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading