Skip to content

Conversation

Crivella
Copy link
Contributor

@Crivella Crivella commented Jul 17, 2025

Enabling

Using pip and optional python dependencies:

pip install easybuild-framework[eb2]

How it works

  • Extract all the parameters from EasyBuildOptions and use them to generate a CLI with click
  • Uses click + rich_click to have a fancier looking CLI
  • click is only used for the nicer help and auto completion, but the parameters are still passed as is to the normal parser

Autocomplete

From click docs add the following to the .bashrc or venv activation script.

eval "$(_EB2_COMPLETE=bash_source eb2)"

Alternatively see aiida-core EC to activate it as a module

Advantages

  • Nicer looking
  • Automatic integration and autocomplete with bash zsh fish shells

TODO

  • Implement/convert more types for better autocompletion

Maybe

  • Add autocomplete for path options (do not think there is a way that they are flagged as such in EB right now)
  • Better integrate logging with rich
  • Rewrite the CLI logic to use click natively and divide the commands in subgroups to have an easier to read help

How would this look like

eb2 --help image
Error image
Normal build run image

@boegel boegel added this to the 5.x milestone Jul 30, 2025
@boegel
Copy link
Member

boegel commented Jul 30, 2025

This looks kind of nice, but I'm not a big fan of introducing a required 3rd party dependency.

Is there any way we can support this opt-in, for example by defining an environment variable like $EB_CLICK_CLI?

@Crivella
Copy link
Contributor Author

We could make use of
https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#optional-dependencies

probably not only for this but also for all the optional dependencies we specify in
https://docs.easybuild.io/installation/#optional_python_packages

Then we add a check on top of eb2 to try and import the required packages and print an error if they are not there suggesting to install the optional dependencies (if we keep eb2 and eb separate, otherwise we could just fallback to the normal eb behavior if they are not there and potentially also allow to disable the behavior with the env variable)

@Crivella Crivella changed the title WIP click CLI wrapper around normal CLI New experimental eb2 CLI using click Jul 31, 2025
@Crivella Crivella marked this pull request as ready for review July 31, 2025 13:05
@Crivella
Copy link
Contributor Author

@boegel

So for now the eb2 CLI is separate from the existing eb one.
I've added an optional set of install dependencies so that if one does pip install easybuild-framework[eb2] it also install the stuff required (and optional) for the new CLI.
The CLI will still be present if the dependencies are not there but will print an informative message instead of actually running

try:
    import click as original_click
except ImportError:
    def eb():
        """Placeholder function to inform the user that `click` is required."""
        print('Using `eb2` requires `click` to be installed.')
        print('Either use `eb` or install `click` with `pip install click`.')
        print('`eb2` also uses `rich` and `rich_click` as optional dependencies for enhanced CLI experience.')
        print('Exiting...')
        sys.exit(0)

The approach of using an ENV variable i think make sense if we decide to merge eb with eb2 to only have one CLI with both behaviors, but it might be difficult to reconcile the autocomplete as they come from the environment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants