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

Closed
jimporter opened this Issue Dec 11, 2016 · 0 comments

Comments

Projects
None yet
1 participant
@jimporter
Contributor

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 setup.py that looks like this:

setup(
    extras_require={
        'msbuild': ['lxml'],
    },

    entry_points={
        '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'):
    try:
        backend = i.load()
        backends.append((i.name, backend))
    except DistributionNotFound:
        pass

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.

jimporter added a commit to jimporter/setuptools that referenced this issue Dec 12, 2016

Fix usage of extras when installing via Wheels; resolves pypa#882
When resolving requirements, we now pass the list of extras we're using along
to Marker.evaluate, since we want to include the extra's requirements in our
list of required packages.

jimporter added a commit to jimporter/setuptools that referenced this issue Dec 12, 2016

Fix usage of extras when installing via Wheels; resolves pypa#882
When resolving requirements, we now pass the list of extras we're using along
to Marker.evaluate, since we want to include the extra's requirements in our
list of required packages.

@jaraco jaraco closed this in 8c1f489 Jan 24, 2017

jaraco added a commit that referenced this issue Jan 24, 2017

Merge pull request #883 from jimporter/extras
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