Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entry_point with un-satisfied extras_require doesn't throw a DistributionNotFound if you installed your package as a wheel #882

jimporter opened this issue Dec 11, 2016 · 0 comments


Copy link

jimporter commented Dec 11, 2016

This is somewhat-complex, but I think I have a handle on what's going on. I have a project with a that looks like this:

        'msbuild': ['lxml'],

        'bfg9000.backends': [
            'msbuild=bfg9000.backends.msbuild.writer [msbuild]',

The goal of this code is to say "the MSBuild backend requires the lxml package". Later, I do the following:

from pkg_resources import iter_entry_points, DistributionNotFound
# ...
for i in iter_entry_points('bfg9000.backends'):
        backend = i.load()
        backends.append((, backend))
    except DistributionNotFound:

The above should load all the backends whose requirements are met (i.e. don't load the MSBuild backend if you don't have lxml). This works fine when the package was not installed as a Wheel, but if it's a Wheel, setuptools tries to actually import the MSBuild backend and raises an ImportError instead of DistributionNotFound.

It appears to be caused by this code, which from my reading says, "If the extras for this requirement are not satisfied, skip this requirement." However, the requirement in this case is lxml; extra == "msbuild" (in a non-Wheel installation, it's just lxml), so pkg_resources is basically saying, "It's ok if you don't have lxml; just try to load the MSBuild backend." Unfortunately, that's the opposite of what I want, and isn't consistent with the docs:

[An entry_point] can also include a bracketed list of “extras” that are required for the entry point to be used. When the invoking application or framework requests loading of an entry point, any requirements implied by the associated extras will be passed to pkg_resources.require(), so that an appropriate error message can be displayed if the needed package(s) are missing.

I assume "appropriate error message" in the above is supposed to mean a DistributionNotFound exception.

@jaraco jaraco closed this as completed in 8c1f489 Jan 24, 2017
jaraco added a commit that referenced this issue Jan 24, 2017
Fix usage of extras when installing via Wheels; resolves #882
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

1 participant