-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
Use custom build_ext to compile Cython code #21600
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Branch: u/jdemeyer/ticket/21600 |
Commit: |
Branch pushed to git repo; I updated commit sha1. This was a forced push. Last 10 new commits:
|
comment:8
If I'm to understand correctly, this is mostly just taking the existing Cython build code and moving into the build_ext command, right? Or was anything substantive changed in the build code too (beyond what was already from #21604)? |
comment:9
Replying to @embray:
Exactly. But it interacts in non-trivial ways with other parts of |
comment:10
Could you be more specific? I can probably help. |
comment:11
Well, I haven't figured out precisely what to do with this part from from sage_setup.find import find_python_sources, find_extra_files
python_packages, python_modules = find_python_sources(
SAGE_SRC, ['sage', 'sage_setup'])
python_data_files = find_extra_files(python_packages,
".", SAGE_CYTHONIZED, SAGE_LIB, ["ntlwrap.cpp"]) This code determines some inputs to the On the other hand, the last line assumes that Cython has run because it looks for files in |
comment:12
One secret about distutils, which is both a bug and a feature--and the fact that it's often exploited is why it's so hard to change anything about distutils--is that in many cases it doesn't really matter what you pass to So for example, the Where this requires care is it's sometimes important to make sure you're using those attributes in ways that are compatible with how other commands use them, for which the best documentation is the source code (another misfeature).
|
comment:13
Thanks a lot! I think I have enough information now to work on this. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:15
I'm not quite sure why you're not not using I'm not sure why the |
comment:16
Replying to @embray:
I could have done that, but the usage of
That doesn't work either:
No, we can always change
These |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:19
Replying to @jdemeyer:
Since the purpose of But for coherency I would rather use the existing option that is specifically for this purpose, and use our command subclasses to enhance its functionality to work for our purposes, rather than make up something entirely new. |
This comment has been minimized.
This comment has been minimized.
comment:21
Replying to @embray:
There is another issue:
You mean: going back to use |
comment:22
I see, that's a bit annoying. I'm surprised I haven't run into that before. If I have I don't know what solution I used--maybe just manually copying the generated Cython files to the appropriate build path. It would still not be a bad idea to add relevant entries to Looking at the source again, I think the simplest thing to do would be after Cythonization to copy the appropriate generated files to the appropriate build/ directory (basically emulating what
The former is the same as if those files were included in An alternative I kind of like, but that's more complicated, is to make cythonize and entirely separate command ( My only real problem at this point is with the new attribute you're tacking on. It seems easily avoidable. |
comment:27
Hmmm...I think I can appreciate what the I don't think that should just happen when you "install" though, but really prior to any build. |
comment:29
I've tested it (on top of 7.4.beta6), and it seems to work for me. |
Reviewer: Matthias Koeppe |
comment:30
Replying to @embray:
Adding attributes to a class is a completely normal thing when subclassing. In this case, I could make a trivial subclass
and define that So, I still don't get why it's perfectly fine to have |
comment:31
Please--you don't have to explain to me how Python works. The point I'm trying to make is that the way you're doing this is antithetical to the common programming patterns used specifically in the context of writing distutils commands. I'm still not convinced that you need this extra attribute at all. But for now I'd be satisfied if it were implemented as I described above. If that's not clear I'll just do it. |
comment:32
Replying to @embray:
Of course I don't need to explain Python. I wanted to explain the philosophy behind what I was doing.
And I'm still not convinced that what I'm doing is somehow wrong.
I'll try it. |
comment:33
BTW I should add--if what I suggested is not clear that's of course my fault for explaining poorly. My point is that it's not good practice in general to use classes as dumping grounds for arbitrary attributes. Python allows it, sure, but it's almost always confusing and error-prone. For example it's possible to run the "install" command without running "build_py" first, in which case you'll get an attribute error. There are myriad little corner cases like that in distutils. I think instead of "sage_extra_files" it might be fine to call this "cythonized_files" or something like that, and have it be an attribute of the custom "build_ext". That way it's clearer exactly what this is about (and that the only reason it needs to exist at all is due to how we're putting the cythonized files in a separate, parallel directory structure). |
Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:
|
comment:35
Needs review. |
comment:36
This looks along the right lines. It occurs to me there's something kind of problematic here, which is that it runs
|
comment:37
Something like class sage_build_ext(build_ext):
def finalize_options(self):
...
self.cythonized_files = None
def run(self):
self.run_cython()
# The following two lines, or the equivalent thereof, could be called
# directly from run_cython() too
self.find_cythonized_files()
self.copy_cythonized_files()
build_ext.run(self)
def find_cythonized_files(self):
if self.cythonized_files is None:
...
self.cythonized_files = ...
class sage_install(install):
def clean_stale_files(self):
...
cmd_build_ext = self.get_finalized_command('build_ext')
cmd.find_cythonized_files()
# Do stuff with cmd.find_cythonized_files() And the rest pretty much exactly as you have it. Would that work? It's not pretty but with distutils you have to write code like you're writing for Python 2.1 or something :) |
comment:38
Replying to @embray:
That's exactly what upstream Cython 0.25 does (which was the inspiration for this ticket), so I'm not inclined to change this. |
comment:39
Erik, on this ticket (and elsewhere) you have mentioned various subtle issues of |
comment:40
Then I'll have to bother upstream Cython about this. There may be a reason they're doing it that way, but it doesn't make a lot of sense on its face. The point of |
comment:41
If I had to guess, the reason they're doing it that way is because of how the "sdist" command uses the "build_ext" command to get a list of source files to include in the sdist. I think the right way to do that is not really to run |
comment:42
Replying to @embray:
Please do that. |
comment:43
Replying to @jdemeyer:
I will try to work with them more closely on that. In the interest of harmony and in making progress, if this is working for you as is, then I give it a positive review. I'll open a separate ticket with my ideas for how to build on this to make it a bit cleaner, but I don't think it's bad as is as long as it works. I just know we can do better. |
Changed reviewer from Matthias Koeppe to Matthias Koeppe, Erik Bray |
comment:44
I'll let the other reviewer (Matthias Koeppe) decide on giving positive review. |
comment:45
See #21682 |
comment:46
Tested on top of 7.4.rc0. |
Changed branch from u/jdemeyer/ticket/21600 to |
In
src/setup.py
, we should not runcythonize()
manually. It would be better to use a custombuild_ext
command for that.This is inspired by the
build_ext
from Cython 0.25: https://github.com/cython/cython/blob/master/Cython/Distutils/build_ext.pyUnfortunately, we cannot really use that since it doesn't allow to pass options to
cythonize()
.Due to a Cython bug, this warning gets displayed even though the
cache
option is valid:UserWarning: got unknown compilation option, please remove: cache
.Depends on #21604
CC: @mkoeppe @embray
Component: build
Author: Jeroen Demeyer
Branch/Commit:
dfcd817
Reviewer: Matthias Koeppe, Erik Bray
Issue created by migration from https://trac.sagemath.org/ticket/21600
The text was updated successfully, but these errors were encountered: