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 points require setuptools at runtime #1872

Closed
encukou opened this issue Oct 11, 2019 · 7 comments
Closed

Entry points require setuptools at runtime #1872

encukou opened this issue Oct 11, 2019 · 7 comments

Comments

@encukou
Copy link
Contributor

encukou commented Oct 11, 2019

Consider the following setup.py (silly minimal reproducer):

import setuptools

setuptools.setup(
    name = 'print-nl',
    version = '1.0',
    entry_points = {
        'console_scripts': ['print-nl=builtins:print'],
    }
)

This generates a command that requires setuptools, yet doesn't declare the dependency:

$ print-nl
Traceback (most recent call last):
  File ".../bin/print-nl", line 6, in <module>
    from pkg_resources import load_entry_point
ModuleNotFoundError: No module named 'pkg_resources'

It isn't clear at all that a fix/workaround for the error about missing pkg_resources is to add setuptools to install_requires. The entry script is, IMO, an implementation detail the user shouldn't care about.

@pfmoore
Copy link
Member

pfmoore commented Oct 11, 2019

I'm not entirely clear what is being flagged here, but note that if the project is installed from a wheel using pip, the resulting entry point script does not depend on pkg_resources, and in that case a runtime dependency on pkg_resources would be wrong.

@FRidh
Copy link

FRidh commented Oct 11, 2019

Using pip wheel to build the wheel (ensure you have setuptools) and pip install to install the wheel (no need for setuptools here) results in a functioning entry point.

If instead using wheel unpack I do not get any entry point, but that is expected. How did you obtain this entry point?

@pfmoore
Copy link
Member

pfmoore commented Oct 11, 2019

I'm assuming either setup.py install or pip install from source, which uses a non-PEP 517 build and so runs setup.py install behind the scenes.

The point (as best I can understand it) of this ticket is that it's difficult to know what to do to handle an installer that adds a runtime dependency to a project (that the project can't know about).

Of course, if you do setup.py install then you by definition have setuptools already present on the target system. But I think that the RPM build process does something like install to a temporary location, then copy the installed files into the RPM for later deployment on a different environment. That's a special case that may need to be handled by the RPM build process (as "copy an installation somewhere else" isn't a typical use case).

@FRidh
Copy link

FRidh commented Oct 11, 2019

Indeed, this uses setup.py install or pip install which then adds a runtime dependency on pkg_resources in case an entry point is used.

In this case I think setuptools should not be added to install_requires because the import pkg_resources is generated and is indeed an implementation detail of the build system.

@FRidh
Copy link

FRidh commented Oct 11, 2019

Relevant discussion that led to this ticket https://discuss.python.org/t/build-system-and-undeclared-dependency-on-it-during-runtime

@jayvdb
Copy link
Contributor

jayvdb commented Oct 16, 2019

Avoiding the dependency is best for setup.py install due to the very bad performance of pkg_resources which does not scale -- its performance gets worse as the size of site-packages increases. A hack (https://pypi.org/project/fastentrypoints/) to avoid it was noted at #510

@encukou
Copy link
Contributor Author

encukou commented Oct 18, 2019

I see. It looks like we are indeed using an unsupported combination tools (which we'll try to improve by moving to pip directly), and the bug isn't in setuptools.

Thanks for your patience here, and sorry for the noise!

@encukou encukou closed this as completed Oct 18, 2019
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

No branches or pull requests

4 participants