Skip to content

Proposal(CLI): after_instantiate_classes hook #20400

@AlessandroW

Description

@AlessandroW

Description & Motivation

Adds a after_instantiate_classes hook to the Lightning CLI, called after self.instantiate_classes() during the initalization of LightningCLI.

Pitch

While having the Lightning CLI is great, it is not perfect for each use case out-of-the-box. Hence, you included hooks like before_instantiate_classes and describe in the docs how to extend the CLI. Problem is, you cannot extend this feature without hacks or substantial copy-pasta.

I think, to further improve the CLI, without adding any complexity, it makes sense to add a after_instantiate_classes hook, too.

Alternatives

  1. Hacks
  • Extend the Lightning CLI and run the after_instantiate_classes function before the self._run_subcommand function.
  • Problems: it's not intuitive that the function is called there, won't be called if self.subcommand is None
  1. Copy-Pasta
  • Extend the Lightning CLI and replace the original __init__ with the proposed one.
  • Problems: could break with any update, lots of code duplication

Additional context

No response

cc @Borda @tchaton @justusschock @awaelchli @mauvilsa

Metadata

Metadata

Assignees

No one assigned

    Labels

    designIncludes a design discussionfeatureIs an improvement or enhancementlightningclipl.cli.LightningCLI

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions