Skip to content

vext makes builds with "python3 -m build" fail in environments without module "colorama" #85

@nathanael-naeri

Description

@nathanael-naeri

Hi, I'm building distribution packages for a project at work with the PEP 517 compliant builder build, using the command line python3 -m build. PEP 517 builders are now recommended over using setuptools as in the past (python3 setup.py sdist|bdist_wheel), if I understand correctly.

In a virtual environment with vext, the build fails with the error ImportError: No module named colorama and the following traceback:

(.dev) $ python3 -m build
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/me/.dev/lib/python3.8/site-packages/build/__main__.py", line 390, in <module>
    main(sys.argv[1:], 'python -m build')
  File "/home/me/.dev/lib/python3.8/site-packages/build/__main__.py", line 337, in main
    _setup_cli()
  File "/home/me/.dev/lib/python3.8/site-packages/build/__main__.py", line 67, in _setup_cli
    import colorama
  File "/home/me/.dev/lib/python3.8/site-packages/vext/gatekeeper/__init__.py", line 204, in load_module
    raise ImportError("No module named %s" % modulename)
ImportError: No module named colorama

This is because build imports colorama, an optional dependency which is not present in the virtual environment, in a try-catch block where the expected exception is of class ModuleNotFoundError, a subclass of ImportError: see import statement here. However, vext raises an ImportError when it does not find the missing module, so this exception is not caught: see here.

I believe ModuleNotFoundError should be raised instead (since Python 3.6).

Alternatively, one could (should?) disable vext with vext --disable before building distribution packages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions