You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I install cython, then it works. Thus, the behaviour of setup.py is not the same if cython was installed before or is installed using setup_requires.
Yeah, I've encountered this before, but I don't know that there's an easy solution to it. The extension and the setup_requires both need to be passed to the setup function, so Extension needs to be pulled in beforesetup is executed.
In Rust extensions, I've seen this done, which basically solves the problem.
Another possible option would be to add some mechanism for deferred execution, so the import statements can be nested in commands run only aftersetup_requires has installed the missing modules.
I was under the impression that the one true solution to this is PEP 518, and setup-time requirements will be resolved from pyproject.toml.
Reacted by Louis Abraham, David Ignacio Cortes and Ihor Slabkyy
Nice one for rust. I think that's the best thing to do. A simple wrapper would call this for all the setup_requires. The only problem is that it would also mess with the installed package (the setup_requires are not installed in sites-packages but in a temp folder instead), so I guess doing it like that is explicit and simple enough.
Indeed, the setup_requires options aren't available until after setup is executed, but I thought that the Extensions could be defined in such a way that they weren't evaluated until after setup_requires was evaluated. I went to a lot of work to get this all to work, and I'm pretty sure I tested it when I worked through the issue. Do you have a simple example that doesn't work?
I created this minimal setup script with an empty foo.pyx and it runs with setup.py build without error:
I'm not quite sure how that ever worked without cython already installed on the system. If Cython is special-cased in this way, maybe it's worth making a PR or issue against the documentation. I'm not sure that helps the rust situation I mentioned, but I guess pyproject.toml will solve that eventually.
If we did want to support this use case, we could create a MagicMock-like class that defers imports in the case of missing modules until aftersetup_requires has fired off. Something like:
Edit Thinking about this - this would probably be very complicated to do correctly. Probably better to just have a separate mechanism for firing off setup_requires before setup is called.
Probably better to just have a separate mechanism for firing off setup_requires before setup is called.
Indeed, and PEP518 does just that (via pyproject.toml). It does require pip 10. It obviates setup_requires, but only for environments where pip 10 can be relied upon. I figure about 18 months before it will be generally available. I had hoped the setup_requires functionality would be a useful stopgap, but for cases where it's not viable, I think the only option is to wait for pip 10 to become dominant (and of course validate/test those concepts in the meantime).
I don't think there's anything left that setuptools can do here, so I'm closing the ticket, but I'm not seeking to stifle discussion. If there's something setuptools can or should do here, we can re-open and explore.
Reacted by Louis Abraham, Jamie Kirkpatrick and Thomas Walther
Activity
jaraco commentedon Apr 10, 2018
Sorry to hear that. You should be able to include
setup_requires=['cython'],in yoursetup.pyand it should work. Did you try that?louisabraham commentedon Apr 10, 2018
I did that. "the behaviour of setup.py is not the same if cython was installed before or is installed using setup_requires"
I think the problem is that Extension is evaluated before any
setup_requiresinstallation.pganssle commentedon Apr 10, 2018
Yeah, I've encountered this before, but I don't know that there's an easy solution to it. The extension and the
setup_requiresboth need to be passed to thesetupfunction, soExtensionneeds to be pulled in beforesetupis executed.In Rust extensions, I've seen this done, which basically solves the problem.
Another possible option would be to add some mechanism for deferred execution, so the
importstatements can be nested in commands run only aftersetup_requireshas installed the missing modules.I was under the impression that the one true solution to this is PEP 518, and setup-time requirements will be resolved from
pyproject.toml.louisabraham commentedon Apr 10, 2018
Nice one for rust. I think that's the best thing to do. A simple wrapper would call this for all the
setup_requires. The only problem is that it would also mess with the installed package (thesetup_requiresare not installed insites-packagesbut in a temp folder instead), so I guess doing it like that is explicit and simple enough.jaraco commentedon Apr 10, 2018
Indeed, the setup_requires options aren't available until after setup is executed, but I thought that the Extensions could be defined in such a way that they weren't evaluated until after setup_requires was evaluated. I went to a lot of work to get this all to work, and I'm pretty sure I tested it when I worked through the issue. Do you have a simple example that doesn't work?
I created this minimal setup script with an empty foo.pyx and it runs with
setup.py buildwithout error:Can you share an example of what doesn't work (preferably a minimal example)?
pganssle commentedon Apr 10, 2018
In the past I've had problems with the Cython documentation examples, which use
cythonize, because they tend to usefrom Cython.build import cythonizeThat also includes this example:
I'm not quite sure how that ever worked without
cythonalready installed on the system. If Cython is special-cased in this way, maybe it's worth making a PR or issue against the documentation. I'm not sure that helps the rust situation I mentioned, but I guesspyproject.tomlwill solve that eventually.pganssle commentedon Apr 10, 2018
If we did want to support this use case, we could create a
MagicMock-like class that defers imports in the case of missing modules until aftersetup_requireshas fired off. Something like:Edit Thinking about this - this would probably be very complicated to do correctly. Probably better to just have a separate mechanism for firing off
setup_requiresbeforesetupis called.louisabraham commentedon Apr 11, 2018
@jaraco I can reproduce your behavior, on your example. I originally got the bug from bootphon/ABXpy#11, I will work on a minimal example.
jkp commentedon May 8, 2018
Just to add another voice - this issue is affecting me as well: I'll subscribe and watch for updates.
jaraco commentedon May 9, 2018
Indeed, and PEP518 does just that (via pyproject.toml). It does require pip 10. It obviates setup_requires, but only for environments where pip 10 can be relied upon. I figure about 18 months before it will be generally available. I had hoped the
setup_requiresfunctionality would be a useful stopgap, but for cases where it's not viable, I think the only option is to wait for pip 10 to become dominant (and of course validate/test those concepts in the meantime).I don't think there's anything left that setuptools can do here, so I'm closing the ticket, but I'm not seeking to stifle discussion. If there's something setuptools can or should do here, we can re-open and explore.