From 5a644d466a7f346ad799f59619017c821decb2cd Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Tue, 30 Mar 2021 17:27:05 +0100 Subject: [PATCH] cli: list installed plugins and entry points --- cylc/flow/scripts/cylc.py | 49 ++++++++++++++++++++++++++++++++-- setup.cfg | 4 +++ tests/functional/cli/01-help.t | 4 +-- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/cylc/flow/scripts/cylc.py b/cylc/flow/scripts/cylc.py index 4a9bdf24090..1730f418a9d 100644 --- a/cylc/flow/scripts/cylc.py +++ b/cylc/flow/scripts/cylc.py @@ -334,12 +334,57 @@ def cli_help(): sys.exit(0) -def cli_version(long=False): +def cli_version(long_fmt=False): """Wrapper for get_version.""" - click.echo(get_version(long)) + click.echo(get_version(long_fmt)) + if long_fmt: + list_plugins() sys.exit(0) +def list_plugins(): + entry_point_names = [ + entry_point_name + for entry_point_name + in pkg_resources.get_entry_map('cylc-flow').keys() + if entry_point_name.startswith('cylc.') + ] + + entry_point_groups = { + entry_point_name: [ + entry_point + for entry_point + in pkg_resources.iter_entry_points(entry_point_name) + if not entry_point.module_name.startswith('cylc.flow') + ] + for entry_point_name in entry_point_names + } + + dists = { + entry_point.dist + for entry_points in entry_point_groups.values() + for entry_point in entry_points + } + + if dists: + print('\nPlugins:') + maxlen1 = max(len(dist.project_name) for dist in dists) + 2 + maxlen2 = max(len(dist.version) for dist in dists) + 2 + for dist in dists: + print( + f' {dist.project_name.ljust(maxlen1)}' + f' {dist.version.ljust(maxlen2)}' + f' {dist.module_path}' + ) + + print('\nEntry Points:') + for entry_point_name, entry_points in entry_point_groups.items(): + if entry_points: + print(f' {entry_point_name}:') + for entry_point in entry_points: + print(f' {entry_point}') + + @contextmanager def pycoverage(cmd_args): """Capture code coverage if configured to do so. diff --git a/setup.cfg b/setup.cfg index 1723efa2d60..5edf5854577 100644 --- a/setup.cfg +++ b/setup.cfg @@ -123,3 +123,7 @@ cylc.main_loop = log_main_loop = cylc.flow.main_loop.log_main_loop log_memory = cylc.flow.main_loop.log_memory prune_flow_labels = cylc.flow.main_loop.prune_flow_labels +# NOTE: all entry points should be listed here even if Cylc Flow does not +# provide any implementations to make entry point scraping easier +cylc.pre_configure = +cylc.post_install = diff --git a/tests/functional/cli/01-help.t b/tests/functional/cli/01-help.t index b49965e7d60..21f54fffbcd 100755 --- a/tests/functional/cli/01-help.t +++ b/tests/functional/cli/01-help.t @@ -70,12 +70,12 @@ 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 +cylc version --long | head -n 1 > long1 WHICH="$(command -v cylc)" PARENT1="$(dirname "${WHICH}")" PARENT2="$(dirname "${PARENT1}")" echo "$(cylc version) (${PARENT2})" > long2 -# the concise version of the above is a shellcheck quoting nightmare: +# the concise version of the above is a bash quoting nightmare: # echo "$(cylc version) ($(dirname $(dirname $(which cylc))))" > long2 cmp_ok long1 long2