@@ -190,8 +190,8 @@ The basic steps are:
190
190
191
191
1. Inheriting from `BaseCommitizen`
192
192
2. 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
195
195
196
196
Check an [example](convcomms) on how to configure `BaseCommitizen`.
197
197
@@ -205,7 +205,7 @@ See [commitizen_cz_template](https://github.com/commitizen-tools/commitizen_cz_t
205
205
206
206
# ## Custom commit rules
207
207
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`.
209
209
210
210
Inherit from `BaseCommitizen`, and you must define `questions` and `message`. The others are optional.
211
211
@@ -257,8 +257,6 @@ class JiraCz(BaseCommitizen):
257
257
" " "
258
258
return 'We use this because is useful'
259
259
260
-
261
- discover_this = JiraCz # used by the plug-in system
262
260
```
263
261
264
262
The next file required is `setup.py` modified from flask version.
@@ -272,7 +270,12 @@ setup(
272
270
py_modules=['cz_jira'],
273
271
license='MIT',
274
272
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
+ }
276
279
)
277
280
```
278
281
@@ -287,8 +290,6 @@ doing `pip install .`
287
290
288
291
If you feel like it should be part of this repo, create a PR.
289
292
290
- [flask uses]: http://flask.pocoo.org/docs/0.12/extensiondev/
291
-
292
293
### Custom bump rules
293
294
294
295
You need to define 2 parameters inside your custom `BaseCommitizen`.
@@ -381,3 +382,56 @@ from commitizen.cz.exception import CzException
381
382
class NoSubjectProvidedException (CzException ):
382
383
...
383
384
```
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