Skip to content

Commit

Permalink
Merge pull request #3952 from hjoliver/cylc-version-long-take-2
Browse files Browse the repository at this point in the history
Cylc version long take 2
  • Loading branch information
hjoliver authored Nov 19, 2020
2 parents 50cc449 + 82273e7 commit a40886d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cylc/flow/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
]

LICENCE = dedent(f"""
The Cylc Suite Engine [{__version__}]
The Cylc Workflow Engine [{__version__}]
Copyright (C) 2008-2020 NIWA
& British Crown (Met Office) & Contributors.
""")
Expand Down
31 changes: 24 additions & 7 deletions cylc/flow/scripts/cylc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import os
import sys
from pathlib import Path

from ansimarkup import parse as cparse
import click
Expand All @@ -33,15 +34,31 @@
)


def get_version(long=False):
"""Return version string, and (if long is True) install location.
The install location returned is the top directory of the virtual
environment, obtained from the Python executable path. (cylc-flow file
locations are buried deep in the library and don't always give the right
result, e.g. if installed with `pip install -e .`).
"""
version = f"{__version__}"
if long:
version += f" ({Path(sys.executable).parent.parent})"
return version


DESC = '''
Cylc ("silk") is a workflow engine for orchestrating complex *suites* of
inter-dependent distributed cycling (repeating) tasks, as well as ordinary
non-cycling workflows.
Cylc ("silk") orchestrates complex cycling (and non-cycling) workflows.
'''

USAGE = f"""{cylc_header()}
{centered(DESC)}
Version:
$ cylc version --long # print cylc-flow version and install path
{get_version(True)}
Usage:
$ cylc help all # list all commands
$ cylc validate FLOW # validate a workflow configuration
Expand Down Expand Up @@ -339,9 +356,9 @@ def cli_help():
sys.exit(0)


def cli_version():
"""Display the Cylc Flow version."""
click.echo(__version__)
def cli_version(long=False):
"""Wrapper for get_version."""
click.echo(get_version(long))
sys.exit(0)


Expand All @@ -360,7 +377,7 @@ def main(cmd_args, version, help_):
command = cmd_args.pop(0)

if command == "version":
cli_version()
cli_version("--long" in cmd_args)

if command == "help":
help_ = True
Expand Down
12 changes: 11 additions & 1 deletion tests/functional/cli/01-help.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

. "$(dirname "$0")/test_header"
# Number of tests depends on the number of 'cylc' commands.
set_test_number $(( 22 + $(find "${CYLC_REPO_DIR}/bin" -name 'cylc-*' | wc -l) ))
set_test_number $(( 23 + $(find "${CYLC_REPO_DIR}/bin" -name 'cylc-*' | wc -l) ))

# Top help
run_ok "${TEST_NAME_BASE}-0" cylc
Expand Down Expand Up @@ -72,6 +72,16 @@ run_ok "${TEST_NAME_BASE}-version.stdout" \
cmp_ok "${TEST_NAME_BASE}-version.stdout" "${TEST_NAME_BASE}---version.stdout"
cmp_ok "${TEST_NAME_BASE}-version.stdout" "${TEST_NAME_BASE}-V.stdout"

# Check "cylc version --long" output is correct.
cylc version --long > long1
WHICH="$(which cylc)"
PARENT1="$(dirname "${WHICH}")"
PARENT2="$(dirname "${PARENT1}")"
echo "$(cylc version) (${PARENT2})" > long2
# the concise version of the above is a shellcheck quoting nightmare:
# echo "$(cylc version) ($(dirname $(dirname $(which cylc))))" > long2
cmp_ok long1 long2

# --help with no DISPLAY
while read -r ITEM; do
run_ok "${TEST_NAME_BASE}-no-display-${ITEM}--help" \
Expand Down

0 comments on commit a40886d

Please sign in to comment.