Skip to content

Conversation

nathanael-naeri
Copy link
Contributor

ModuleNotFoundError is a subclass of ImportError, new in Python 3.6. It describes a module not being available in the virtual environment (because blocked by vext) better than the more generic ImportError.

This PR changes ImportError into ModuleNotFoundError in function GateKeeperLoader.load_module(). I've let the other ImportErrors in the code as they are, as I'm not sure about them.

Obviously a drawback of using ModuleNotFoundError is that it requires Python 3.6, but then again Python 3.6 was released in 2016, and as of today Python 3.7 is the oldest version still maintained.

I've tested the same way as .travis.yml tests, but with dependencies fixed to what they were at the time of the previous commit, Mar 24, 2021. In a new virtual environment:

$ pip3 install -U setuptools==54.2.0 pip==21.0.1
$ pip3 install ruamel.yaml==0.16.13 ruamel.yaml.clib==0.2.2
$ VEXT_RELOAD_HACK=1 python3 setup.py install

$ pip3 install virtualenv==20.4.3 # because required by test_virtualenv.sh
$ bash scripts/test_virtualenv.sh

Tests pass this way. They don't pass using current pip and setuptools. Too much has changed in these dependencies since last commit. I think python3 setup.py ... is now deprecated in favor of python3 -m build, also virtualenv in favor of python3 -m venv if I understand correctly. Here's what trying to build vext with current dependencies return, in a new virtual environment:

$ pip3 install -U setuptools pip
$ pip3 install -r requirements.txt
$ VEXT_RELOAD_HACK=1 python3 setup.py install
setup.py:45: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  if StrictVersion(r.version) >= StrictVersion(MIN_SETUPTOOLS):
setuptools version: 60.9.3
/home/me/.myvext/lib/python3.8/site-packages/setuptools/dist.py:738: UserWarning: Usage of dash-separated 'description-file' will not be supported in future versions. Please use the underscore name 'description_file' instead
  warnings.warn(
Traceback (most recent call last):
  File "setup.py", line 280, in <module>
    setup(
  File "/home/me/.myvext/lib/python3.8/site-packages/setuptools/__init__.py", line 154, in setup
    _install_setup_requires(attrs)
  File "/home/me/.myvext/lib/python3.8/site-packages/setuptools/__init__.py", line 148, in _install_setup_requires
    dist.fetch_build_eggs(dist.setup_requires)
  File "/home/me/.myvext/lib/python3.8/site-packages/setuptools/dist.py", line 826, in fetch_build_eggs
    resolved_dists = pkg_resources.working_set.resolve(
  File "/home/me/.myvext/lib/python3.8/site-packages/pkg_resources/__init__.py", line 739, in resolve
    requirements = list(requirements)[::-1]
  File "/home/me/.myvext/lib/python3.8/site-packages/pkg_resources/__init__.py", line 3089, in __init__
    super(Requirement, self).__init__(requirement_string)
TypeError: super(type, obj): obj must be an instance or subtype of type

With this modified vext, I confirm that I can build distribution packages for my project at work with python3 -m build without triggering #85, so this PR closes #85.

ModuleNotFoundError is a subclass of ImportError. It describes the
module not being available in the virtual environment (because
blocked by vext) better than the more generic ImportError.
@stuaxo
Copy link
Collaborator

stuaxo commented Mar 10, 2022

This makes sense.. I think, that the other places could well be changed to ModuleNotFoundError as well, but lack of tests makes it a little hard to say.

If you bump python version in setup.py to 3.6 as well then I can merge this.

@nathanael-naeri
Copy link
Contributor Author

Done. There was no minimum Python version specified in setup.py so I just added it.

I'd love to help modernize the packaging scripts so that vext builds with the current setuptools, but sadly that is beyond my skills.

Copy link
Collaborator

@stuaxo stuaxo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks :)

@stuaxo
Copy link
Collaborator

stuaxo commented Mar 11, 2022

Cheers, merged.

@stuaxo stuaxo merged commit 9c0c6e1 into vext-python:master Mar 11, 2022
@nathanael-naeri nathanael-naeri deleted the importerror-to-modulenotfounderror branch March 24, 2022 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants