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

Scan for providers using metadata.entry_points in init #1258

Open
dhmmasson opened this issue Oct 14, 2024 · 0 comments
Open

Scan for providers using metadata.entry_points in init #1258

dhmmasson opened this issue Oct 14, 2024 · 0 comments

Comments

@dhmmasson
Copy link
Contributor

Description

Currently, when running the cz init command, Commitizen scans for plugins using the registry populated by metadata.entry_points(group="commitizen.plugin") in commitizen/cz/__init__.py.

However, for providers, while the cz version command scans and detects third-party providers dynamically, the cz init command relies on a fixed list of providers. This makes it difficult to discover or configure new providers during the initialization process.

To improve usability, cz should implement dynamic discovery of providers during cz init, similar to how third-party plugins are handled, allowing for easier integration of new or custom providers.

I have locally implemented the feature and I'd be willing to provide a PR if possible.

Possible Solution

Create a similar registry for providers and populate it using metadata.entry_points(group="commitizen.provider"). Concatenate the results with the hardcoded one in (commitizen/commands/init.py:227)

commitizen/cz/init.py

def discover_providers() -> dict[str, type[VersionProvider]]:
    """Discover commitizen version providers on the path

        Returns:
        Dict[str, Type[VersionProvider]]: Registry with found version providers
    """

    return {
        ep.name: ep.load() for ep in metadata.entry_points(group="commitizen.provider")
    }

versioner: dict[str, type[BaseCommitizen]] = discover_providers()

commitizen/commands/init.py - line 236

  opts = list(versioner.keys())
    # Merge
  OPTS.update(
      {opt: f"{opt}: Get and set version from {opt}" for opt in opts})

Additional context

No response

Additional context

No response

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

No branches or pull requests

1 participant