Skip to content

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

Closed
@andres-fr

Description

@andres-fr

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:

if name.startswith("cz_")

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions