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

cli: list installed plugins and entry points #4155

Merged
merged 1 commit into from
Mar 31, 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
49 changes: 47 additions & 2 deletions cylc/flow/scripts/cylc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
4 changes: 2 additions & 2 deletions tests/functional/cli/01-help.t
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Member Author

@oliver-sanders oliver-sanders Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't blame shellcheck for the Bash unsafe-by-defaut variable templating model!

# echo "$(cylc version) ($(dirname $(dirname $(which cylc))))" > long2
cmp_ok long1 long2

Expand Down