You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ImportError: cannot import name 'BaseCommitizen' and others in files starting with cz_ #287
As it can be seen in the following line, all files present in the Python environment whose filename begins with cz_ will be discovered and iteratively loaded by commitizen. Unfortunately this also includes files that aren't in the scope of commitizen but happen to be in PYTHONPATH:
The reaction is very cryptic and can lead to long and frustrating debugging sessions. Fortunately it is known that the "cannot import" message is linked to circular dependencies, e.g. see https://stackoverflow.com/a/746655
Just importing commitizen doesn't break, but further recursive imports down the package trigger the issue.
Steps to reproduce
Create a file starting with cz_... and call e.g. from commitizen.commands.bump import Bump
Run that file with the python interpreter, making sure that the file's directory is in sys.path
The import will trigger an ImportError that is internal to commitizen like the one in the title.
Current behavior
Code that runs from interactive CLI doesn't run from script
I guess the main idea here is that a library shouldn't discover and load files from the python path by regex. That can be very tricky to find and could be even more problematic at other levels e.g. security. At the moment I'm kind of saturated and don't have any meaningful quickfix, apart from the obvious Don't ever name any Python file starting by cz_
Thanks for your answer, I would have to analyze more the plugin system to propose something more specific.
What do you think about this plugin architecture?
I browse through the article you shared but not yet try it, but it looks like a good approach to me. Also, I just found how poetry can support similiar functionality. https://python-poetry.org/docs/pyproject/#plugins
Interesting, I like it, seems quite intuitive. We'd have to update the template as well. Keep in mind, this would introduce a breaking change, but it's fine by me.
If you guys are comfortable with that I could give a hand in the next few weeks (we could do a hackathon or something) and try to refactor the CLI/plugin section. Only changes that you approve of course. I'd love to play around with poetry, seems neat
Activity
andres-fr commentedon Oct 27, 2020
I guess the main idea here is that a library shouldn't discover and load files from the python path by regex. That can be very tricky to find and could be even more problematic at other levels e.g. security. At the moment I'm kind of saturated and don't have any meaningful quickfix, apart from the obvious Don't ever name any Python file starting by
cz_woile commentedon Oct 27, 2020
Sorry if it's a big frustrating 😞 , the plugin system can be improved, but it's based on a simple version of flask extension system.
There should be a way to avoid this kind of errors, I'm open to enhancements
andres-fr commentedon Oct 27, 2020
Thanks for your answer, I would have to analyze more the plugin system to propose something more specific.
What do you think about this plugin architecture?
https://amir.rachum.com/blog/2017/07/28/python-entry-points/
Lee-W commentedon Oct 28, 2020
I browse through the article you shared but not yet try it, but it looks like a good approach to me. Also, I just found how poetry can support similiar functionality. https://python-poetry.org/docs/pyproject/#plugins
woile commentedon Oct 28, 2020
Interesting, I like it, seems quite intuitive. We'd have to update the template as well. Keep in mind, this would introduce a breaking change, but it's fine by me.
andres-fr commentedon Oct 29, 2020
If you guys are comfortable with that I could give a hand in the next few weeks (we could do a hackathon or something) and try to refactor the CLI/plugin section. Only changes that you approve of course. I'd love to play around with poetry, seems neat
Lee-W commentedon Oct 30, 2020
It sounds good to me. I just add a
3.0.0tag to this issue.woile commentedon Oct 30, 2020
I'm in, great idea! Let's coordinate a date
woile commentedon Nov 11, 2020
21 November 2020 I'll be joining to pycon argentina with a sprint for commitizen, hope you can join!
andres-fr commentedon Nov 11, 2020
Sounds good, I can't promise it but will mark the date 📝. In any case this sounds amazing for the project! Looking forward to what comes out of it
Lee-W commentedon Mar 13, 2022
Hi @andres-fr , https://github.com/commitizen-tools/commitizen/pull/480/files seems to solve this issue. Could you please check again? As this issue also proposed something worth enhancing, @woile do you think we should keep this one open or create a new one for tracking that stuff?
woile commentedon Mar 13, 2022
I think we should create a new ticket, I still want to refactor the plugin system
andres-fr commentedon Mar 13, 2022
Hey, sorry for dropping the ball here. I'm happy to close this one if you think that is appropriate!
Lee-W commentedon Mar 29, 2022
Hi all, I've created a new issue for tracking this #495. Let's close this one