question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImportError: cannot import name 'BaseCommitizen' and others in files starting with `cz_`

See original GitHub issue

Description

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:

https://github.com/commitizen-tools/commitizen/blob/14b6c382ff96e37ba118ba1b75073b0d2313ee91/commitizen/cz/__init__.py#L18

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

  1. Create a file starting with cz_... and call e.g. from commitizen.commands.bump import Bump
  2. Run that file with the python interpreter, making sure that the file’s directory is in sys.path
  3. 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

Desired behavior

Code that runs on CLI should also run on script.

Environment

python --version Python 3.6.12 :: Anaconda, Inc. python3 -c “import platform; print(platform.system())”

  • commitizen version: 2.4.2
  • python version: 3.6
  • operating system: Ubuntu

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
woilecommented, Mar 13, 2022

I think we should create a new ticket, I still want to refactor the plugin system

2reactions
woilecommented, Oct 30, 2020

I’m in, great idea! Let’s coordinate a date

Read more comments on GitHub >

github_iconTop Results From Across the Web

What can I do about "ImportError: Cannot import name X" or ...
My case is that I encounter this error in jupyter notebook; I write from M import c where M is a python file...
Read more >
cannot import name 'Message' from 'can' in my Ubuntu - Unix ...
I found this solution that worked for me: Try pip3 uninstall python-can but with "sudo" permissions. Raspberry Pi will work this out, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found