@@ -190,8 +190,8 @@ The basic steps are:
190190
1911911. Inheriting from `BaseCommitizen`
1921922. Give a name to your rules.
193- 3. Expose the class at the end of your file assigning it to `discover_this`
194- 4. Create a python package starting with `cz_` using `setup.py`, `poetry`, etc
193+ 3. Create a python package using `setup.py`, `poetry`, etc
194+ 4. Expose the class as a `commitizen.plugin` entrypoint
195195
196196Check an [example](convcomms) on how to configure `BaseCommitizen`.
197197
@@ -205,7 +205,7 @@ See [commitizen_cz_template](https://github.com/commitizen-tools/commitizen_cz_t
205205
206206# ## Custom commit rules
207207
208- Create a file starting with `cz_` , for example `cz_jira.py`. This prefix is used to detect the plug-in. Same method [flask uses]
208+ Create a Python module , for example `cz_jira.py`.
209209
210210Inherit from `BaseCommitizen`, and you must define `questions` and `message`. The others are optional.
211211
@@ -257,8 +257,6 @@ class JiraCz(BaseCommitizen):
257257 " " "
258258 return 'We use this because is useful'
259259
260-
261- discover_this = JiraCz # used by the plug-in system
262260```
263261
264262The next file required is `setup.py` modified from flask version.
@@ -272,7 +270,12 @@ setup(
272270 py_modules=['cz_jira'],
273271 license='MIT',
274272 long_description='this is a long description',
275- install_requires=['commitizen']
273+ install_requires=['commitizen'],
274+ entry_points = {
275+ 'commitizen.plugin': [
276+ 'cz_jira = cz_jira:JiraCz'
277+ ]
278+ }
276279)
277280```
278281
@@ -287,8 +290,6 @@ doing `pip install .`
287290
288291If you feel like it should be part of this repo, create a PR.
289292
290- [flask uses]: http://flask.pocoo.org/docs/0.12/extensiondev/
291-
292293### Custom bump rules
293294
294295You need to define 2 parameters inside your custom `BaseCommitizen`.
@@ -381,3 +382,56 @@ from commitizen.cz.exception import CzException
381382class NoSubjectProvidedException (CzException ):
382383 ...
383384```
385+
386+ ### Migrating from legacy plugin format
387+
388+ Commitizen migrated to a new plugin format relying on ` importlib.metadata.EntryPoint ` .
389+ Migration should be straight-forward for legacy plugins:
390+
391+ - Remove the ` discover_this ` line from you plugin module
392+ - Expose the plugin class under as a ` commitizen.plugin ` entrypoint.
393+
394+ The name of the plugin is now determined by the name of the entrypoint.
395+
396+ #### Example
397+
398+ If you were having a ` CzPlugin ` class in a ` cz_plugin.py ` module like this:
399+
400+ ``` python
401+ from commitizen.cz.base import BaseCommitizen
402+
403+ class PluginCz (BaseCommitizen ):
404+ ...
405+
406+ discover_this = PluginCz
407+ ```
408+
409+ Then remove the ` discover_this ` line:
410+
411+ ``` python
412+ from commitizen.cz.base import BaseCommitizen
413+
414+ class PluginCz (BaseCommitizen ):
415+ ...
416+ ```
417+
418+ and expose the class as entrypoint in you setuptools:
419+
420+ ``` python
421+ from setuptools import setup
422+
423+ setup(
424+ name = ' MyPlugin' ,
425+ version = ' 0.1.0' ,
426+ py_modules = [' cz_plugin' ],
427+ ...
428+ entry_points = {
429+ ' commitizen.plugin' : [
430+ ' plugin = cz_plugin:PluginCz'
431+ ]
432+ }
433+ ...
434+ )
435+ ```
436+
437+ Then your plugin will be available under the name ` plugin ` .
0 commit comments