-
-
Notifications
You must be signed in to change notification settings - Fork 487
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
support extra_compile_args (e.g., C99) when loading/attaching .pyx (cython) files, and when using %cython in the notebook #11680
Comments
comment:1
So what do you propose? Since #clang c99 and some other way to specify "flags" or compile-time options, perhaps also to the linker. AFAIK there's currently not even a way to specify Allowing / using strings that get passed literally to the compiler driver (and perhaps also directly to the linker) is very flexible, but the Cython files may of course get less portable (which is perhaps a minor issue for the Sage library, at least at the moment). What Cython needs, too, is some kind of conditional compilation (à la |
comment:2
leif -- I have no proposal, I just want something, anything, that actually works, so I can get back to work. |
comment:3
Replying to @williamstein:
Do you need or imagine any other "generic" options (other than for compiling as C99 code) which you'd rather like to specify "non-verbatim", i.e., without using a string to be directly passed to e.g. |
comment:4
In addition to #clang C99 I could imagine having #coptions keyword1 keyword2 keyword3 which are then mapped to the appropriate flags and passed to their respective component ( This should be quite flexible, since changes to the flags effectively used (e.g for different compilers or compiler versions) would be limited to I don't know if we'd in addition need something like #cpragma "CFLAGS" "-D_XPG6 --some-very-rare-and-specific-options another_argument"
#cpragma "LDFLAGS" "-L/unusual/location" etc. |
comment:5
Replying to @nexttime:
#cpragma "CFLAGS" "-D_XPG6 --some-very-rare-and-specific-options another_argument"
#cpragma "LDFLAGS" "-L/unusual/location"
We could even extend this to conditionals (e.g. depending on the operating system): #cpragma "CFLAGS" SunOS, HP-UX ? "-D_XPG6" : "" where (Using |
comment:6
Just noticed Will give it a try... Any nice Cython examples to test with? |
test file to demonstrate behaviour |
Author: Martin Albrecht |
comment:7
Attachment: test.spyx.gz Hi, I've addeded cflags which are just passed to extra_compile_args. I only fixed enough things in cython.py such that the attached test.spyx works, e.g. I didn't fix adding |
comment:8
Hmmm, the naming isn't very clear. I'd use some plural form for
(I admit that For compiling C99, I still prefer having P.S.: Now I'm happy I didn't also work on this yesterday... ;-) |
comment:9
|
comment:10
Replying to @williamstein:
Done, I added only one test, though. It seems sufficient. |
comment:11
Replying to @nexttime:
Agreed.
Those weren't added in this ticket.
Yep, the whole cprefix thingy is ambiguous. Perhaps there should be another ticket where the whole system is overhauled?
These weren't added in this ticket.
I have no preference either way. GCC treats it as an option. Hence, I think it's okay to have it as part of
But you could work on a more general ticket tomorrow ;-) |
comment:12
I was refereeing the patch and fixed a doctest failure in it (?). Then I decided I wanted that .pyx file in my original input in a doctest, and setup infrastructure to do that, and did it. So the new patch (which is merged with yours, with both our names) is longer than your original patch. Since I'm happy with yours, if you (=malb) can review this (especially my new code), then it is reviewed. |
comment:13
Patch looks good but I wonder whether we should support replacing |
Attachment: trac_11680.patch.gz |
comment:14
I am happy with this version if you are. |
comment:15
Replying to @malb:
Yep. Positive review :-) Regarding |
Changed keywords from none to sd32 |
comment:18
When #11761 gets approved, we can move using |
comment:19
Shouldn't we make this ticket depend on #11761 then and adapt it accordingly? It doesn't seem to be a good idea to change the syntax that often? |
comment:20
Replying to @malb:
IMHO not until #11761 has positive review. (Otherwise we'd need a negative dependence, invalidating this ticket when #11761 gets merged.) You can open a follow-up ticket based on #11761 though, changing the syntax used here. Or change the syntax used here, and don't make this ticket depend on Cython 0.15... ;-) |
Reviewer: William Stein, Leif Leonhardy |
This comment has been minimized.
This comment has been minimized.
Merged: sage-4.7.2.alpha3 |
comment:23
The patch here seems to be leaving some .c and .html files lying around during doctests. I think we can fix this with this: diff --git a/sage/misc/cython.py b/sage/misc/cython.py
--- a/sage/misc/cython.py
+++ b/sage/misc/cython.py
@@ -17,7 +17,7 @@ AUTHORS:
import os, sys, platform
-from misc import SPYX_TMP, SAGE_ROOT, SAGE_LOCAL
+from misc import SPYX_TMP, SAGE_ROOT, SAGE_LOCAL, SAGE_TMP
from sage.misc.misc import UNAME
def cblas():
@@ -627,6 +627,7 @@ def compile_and_load(code):
file = tmp_filename() + ".pyx"
open(file,'w').write(code)
from sage.server.support import cython_import
+ os.chdir(SAGE_TMP)
return cython_import(file) Is this a good idea? Can anyone confirm that the patch here is responsible for those files? If so, we should open up a follow-up ticket. |
comment:24
Revisiting this, I don't think the They should either be part of the docstring as an -- of course longer -- example, or somewhere in W.r.t. the temporary files: I think it is a more general problem that Cython apparently puts temporary files into the current working directory, just mangling the original path, and, secondly, not deleting them afterwards. I'm pretty sure I've seen similar files sporadically occurring without ever getting deleted in previous releases (i.e., e.g. last year). |
comment:25
P.S.: But John's suggestion is IMHO -- perhaps as a temporary fix only -- ok here (in that it should fix the issue in an easy way), since using Maybe we should also use |
comment:26
Replying to @nexttime:
FWIW, the following fixes the issue for me, without changing the current working directory: diff --git a/sage/misc/cython.py b/sage/misc/cython.py
--- a/sage/misc/cython.py
+++ b/sage/misc/cython.py
@@ -627,7 +627,8 @@
file = tmp_filename() + ".pyx"
open(file,'w').write(code)
from sage.server.support import cython_import
- return cython_import(file)
+ # return cython_import(file, create_local_c_file=False, annotate=False)
+ return cython_import(file, create_local_c_file=False)
TESTS = { The line I've commented out does not work, since However, using just |
comment:27
We definitely want |
comment:28
Replying to @jhpalmieri:
I meant both of course, but disabling the former apparently also disables the latter. |
Right now, the following file
foo.pyx
cannot be just loaded into Sage:The main reason is that there is no way to tell Sage (i.e., the file
cython.py
) that the code needs to have the extra compile flag:Currently
devel/sage/sage/misc/cython.py
supports "clang", "clib", and "cinclude" pragmas. But none of these let us add anextra_compile_arg
or use C99.Apply attachment: trac_11680.patch to the Sage library.
CC: @robertwb
Component: misc
Keywords: sd32
Author: Martin Albrecht
Reviewer: William Stein, Leif Leonhardy
Merged: sage-4.7.2.alpha3
Issue created by migration from https://trac.sagemath.org/ticket/11680
The text was updated successfully, but these errors were encountered: