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

sage's spkg sources should use correct include paths instead of having ../../../../whatever everywhere #12728

Closed
SnarkBoojum mannequin opened this issue Mar 22, 2012 · 66 comments

Comments

@SnarkBoojum
Copy link
Mannequin

SnarkBoojum mannequin commented Mar 22, 2012

Problem

There are many places in sage's spkg sources where inclusions are made with a filename which looks like ../../../../../whatever (no exageration: up to five levels!).

Solution
Those should be removed, and the right path added to the include line.

The first patch was obtained by running the attached script and the second one by hand-editing the remaining occurrences.

Apply

Component: build

Author: Julien Puydt

Reviewer: Volker Braun, Jeroen Demeyer, Julien Puydt

Merged: sage-5.10.beta5

Issue created by migration from https://trac.sagemath.org/ticket/12728

@SnarkBoojum SnarkBoojum mannequin added this to the sage-5.10 milestone Mar 22, 2012
@SnarkBoojum SnarkBoojum mannequin added c: build labels Mar 22, 2012
@SnarkBoojum SnarkBoojum mannequin self-assigned this Mar 22, 2012
@SnarkBoojum SnarkBoojum mannequin added the s: needs review label Mar 24, 2012
@jdemeyer
Copy link
Contributor

jdemeyer commented Apr 2, 2012

comment:2

I don't like attachment: compile_with_no_up_in_includes.patch. I would prefer the patch to add only SAGE_ROOT/devel/sage and not all those other directories.

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented Apr 2, 2012

comment:3

There are two problems with "../../../../.." :

  1. it doesn't give any serious information, so why is it here?
  2. the code is supposed to provide features ; it shouldn't worry about building.

It's better to have the build system provide ten "-I" flags than having a thousand places in the code where those ten paths are engraved, for maintainability reasons.

@jdemeyer
Copy link
Contributor

comment:4

Please fill in your real name as Author.

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented Aug 6, 2012

Author: Julien Puydt

@kiwifb
Copy link
Member

kiwifb commented Aug 8, 2012

comment:6

Some dedication here. The second patch at least will need rebasing against at least 5.2. I am not sure you should add all these paths to CYTHON_INCLUDE_DIRS. Is there a reason why they are not in their own variable. Do you need all these and not just SAGE_ROOT + '/devel/sage/sage/'?

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented Aug 8, 2012

comment:7

Yes, it's now old and deprecated. And yes, I think it was needed to add all those paths.

I plan to rework on the matter differently -- the question is when. The plan would be to have some script with a list of the included headers with their full paths and their wanted path, which would normalize the paths in includes. That might still require changing CYTHON_INCLUDE_DIRS, but hopefully adding less paths.

@simon-king-jena
Copy link
Member

comment:9

On Sage-devel, you reported that by changing the include paths the answers to some doctest in sage.misc.sageinspect changed. I'll see where that comes from, but I guess sageinspect needs a fix concerning temporary Cython code anyway.

@simon-king-jena
Copy link
Member

comment:10

See #13916.

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented Jan 6, 2013

comment:11

That shell script has a bug where everything before stdsage.pxi might get eaten -- that is the reason why there's a failing doctest. Not ready for review yet :-P

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented Jan 6, 2013

Attachment: updirectories-sed.sh.gz

Shell script which patches 99,99% of the issues

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented Jan 7, 2013

comment:12

Ok, the new version of the updirectories-sed shell script passes all doctests: it needs review. It won't fix 100% of the problem, but the rest can be patched by hand, at it concerns only a handful of cases.

@SnarkBoojum SnarkBoojum mannequin added s: needs review and removed s: needs work labels Jan 7, 2013
@jdemeyer
Copy link
Contributor

comment:13

Please make it clear what should be applied.

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented Jan 13, 2013

comment:14

The updirectories-sed.sh shell script needs to be reviewed:

  1. read ;
  2. run (from the right directory) ;
  3. compile ;
  4. make ptestlong ;
  5. report success (very likely) or failure (very unlikely).

@kiwifb
Copy link
Member

kiwifb commented Jan 13, 2013

comment:15

I think that's not how we want to proceed hence, Jeroen's question. Having the script is nice for testing but once you have run it you should generate a patch with mercurial and post it here for inclusion.
The script is nice for stuff that will be included in the future... there is a ticket somewhere where someone is making a similar mess - I didn't have the heart to shoot him early.

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented Jan 13, 2013

comment:16

I'll generate an mercurial patch if that is what you want. It will be thousands of lines long, but if you prefer to review that... every taste is in nature.

@kiwifb
Copy link
Member

kiwifb commented Jan 13, 2013

comment:17

Size of the patch is just a technical problem. It just makes it harder to find a problem if there is any but no more so than with just applying your script.

@jdemeyer
Copy link
Contributor

comment:18

Replying to @SnarkBoojum:

I'll generate an mercurial patch if that is what you want.

No, that's not needed. But you should really explain in the ticket description which patches should be applied/which scripts should be run. From the previous ticket description, it was a absolutely totally utterly completely not clear that the script should be run instead of applying any patches.

@jdemeyer

This comment has been minimized.

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented Jan 13, 2013

comment:19

I don't like editing the ticket description because that breaks the flow of comments. And notice that running the shell script fixes a huge percentage of the updirectory includes, but doesn't fix them all : I'll still need to hand-edit the remaining ones afterwards.

@jdemeyer
Copy link
Contributor

comment:20

Replying to @SnarkBoojum:

I don't like editing the ticket description because that breaks the flow of comments.

So you expect the release manager to read all the comments in every ticket just to know which patches should be applied? That's not going to happen.

And even from reading the comments, it's not that clear that the shell script replaces the usual patch.

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented May 23, 2013

comment:40

Your error message doesn't look at all like it's related to my changes (no error looking like "File not found"), but I'll investigate...

@vbraun
Copy link
Member

vbraun commented May 23, 2013

comment:41

This is what broke:

sage: sage.misc.sageinspect.sage_getargspec(sage.sets.disjoint_set.OP_represent)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-b9940f7f2356> in <module>()
----> 1 sage_getargspec(sage.sets.disjoint_set.OP_represent)

NameError: name 'sage_getargspec' is not defined
sage: sage.misc.sageinspect.sage_getargspec(sage.sets.disjoint_set.OP_represent)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-ee04891bf854> in <module>()
----> 1 sage.misc.sageinspect.sage_getargspec(sage.sets.disjoint_set.OP_represent)

/home/vbraun/opt/sage-5.10.beta3/local/lib/python2.7/site-packages/sage/misc/sageinspect.pyc in sage_getargspec(obj)
   1332         except TypeError: # arg is not a code object
   1333         # The above "hopefully" was wishful thinking:
-> 1334             return inspect.ArgSpec(*_sage_getargspec_cython(sage_getsource(obj)))
   1335             #return _sage_getargspec_from_ast(sage_getsource(obj))
   1336     try:

/home/vbraun/opt/sage-5.10.beta3/local/lib/python2.7/site-packages/sage/misc/sageinspect.pyc in _sage_getargspec_cython(source)
    984 
    985     """
--> 986     defpos = source.find('def ')
    987     assert defpos > -1, "The given source does not contain 'def'"
    988     s = source[defpos:].strip()

AttributeError: 'NoneType' object has no attribute 'find'

used to be

sage: sage.misc.sageinspect.sage_getargspec(sage.sets.disjoint_set.OP_represent)
ArgSpec(args=['n', 'merges', 'perm'], varargs=None, keywords=None, defaults=None)

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented May 23, 2013

comment:42

@vbraun: thanks ; it still doesn't look like a missing file, but at least it's a place I can start digging.

My plan was the following :

  1. freshly unpack a sage-5.10.beta4 tarball ;
  2. make build
  3. apply the patches
  4. ./sage -ba-force
  5. make doc-html

now step 5 is to start from this sage.misc.sageinspect.sage_getargspec(sage.sets.disjoint_set.OP_represent).

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented May 23, 2013

comment:43

Ok, I determined that sage.misc.sageinspect.sage_getargspec(sage.sets.disjoint_set.OP_represent) gets interpreted in sageinspect.py like this:

  1. is it an abstract method, line 1284? No.
  2. is it callable, line 1287? Yes.
  3. try to read the argspec, line 1290 - AttributeError line 1291, pass (line 1292)!
  4. is it a function, line 1293? No.
  5. is it a method, line 1295? No.
  6. is it a class instance, line 1297? No.
  7. is it a class, line 1311? No.
  8. does it have some attributes, line 1314? No.
  9. fallback to the 'else' of line 1318!
  10. let's call sage_getsource, line 1320, and get None.
  11. line 1321-1324: since we got None, we set func_obj=obj.
  12. try something line 1328 and fail with AttributeError
  13. catch this exception and try something else line 1331 and fail with TypeError
  14. catch this exception line 1332
  15. let's do (no try this time): "return inspect.ArgSpec(*_sage_getargspec_cython(sage_getsource(obj)))", because obviously, the fact that a few lines above sage_getsource got us None already won't be a problem! BOOM!

I interpret those findings as meaning that something with my patches has made sage_getsource(obj) return None, and this then uncovered a nice bug in sageinspect. Does this sound sensible? Should I then file a bug against sageinspect.py? [Of course, I'll now investigate why None gets returned]

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented May 23, 2013

comment:44

Oh, I forgot to make explicit the remark that sage_getsource returning None could be related to a "File not found" problem -- so now it makes sense that the problem can be related to my patches. Something which wasn't that clear. So now I'm looking for a problem, and I believe in it :-P

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented May 23, 2013

comment:45

I now determined how sage_getsource(sage.sets.disjoint_set.OP_represent) gets interpreted in sageinspect.py:

  1. try to use the _sage_src_ method and raise an AttributeError, line 1552 (gets pass-ed)
  2. try to use sage_getsourcelines, line 1556 and get None
  3. after a test of the previous value, return None, line 1558

The problems turns into: why does sage_getsourcelines(sage.sets.disjoint_set.OP_represent) return None? Let's follow the trail again:

  1. try to use the _sage_src_lines_ method and raise an AttributeError line 1783 (gets pass-ed)
  2. is it a class instance, line 1791? No.
  3. get a nice-looking doctring line 1802, except that the filename reads 'res_pyx.pxi'
  4. try to use _extract_embedded_position on it... get to line 200... where the filename gets obtained by os.path.join(SAGE_SRC, res.group('FILENAME'))
  5. from there, the rest is history: we have a wrong filename in a wrong path, so it's no surprise things get messy.

So now I see two problems there: first, the only file with a name looking like this is sage/groups/perm_gps/partn_ref/data_structures_pyx.pxi, and second, the way the full path is obtained from the filename looks too naive.

How can I debug the first problem?

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented May 23, 2013

comment:46

"sage.sets.disjoint_set.OP_represent" is defined in sage/groups/perm_gps/partn_ref/data_structures_pyx.pxi, and indeed at line 125 as I see in the docstring.
The line number is correct ; only the filename looks like it has been eaten.

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented May 23, 2013

comment:47

On the non-patched sage-5.10.beta5 the filename is "sage/sets/../groups/perm_gps/partn_ref/data_structures_pyx.pxi".

@vbraun
Copy link
Member

vbraun commented May 23, 2013

comment:48

The filename is already wrong in the Cythonized disjoint_set.c:

static char __pyx_doc_4sage_4sets_12disjoint_set_OP_represent[] = "File: pyx.pxi (starting at line 125)\n\n    Demonstration and testing.\n    \n    TESTS::\n\n        [...]        Done.\n\n    ";

So there is nothing in this ticket that is responsible for it.

@vbraun
Copy link
Member

vbraun commented May 23, 2013

comment:49

The bug is in Cython Nodes.relative_position, which assumes that you can make the path relative by stripping off len(os.path.abspath(os.getcwd())) characters. Thats of course totally wrong when the file was discovered through a search path.

@vbraun
Copy link
Member

vbraun commented May 23, 2013

comment:50

See #14634 for the Cython bug

@jdemeyer
Copy link
Contributor

Dependencies: #14634

@jdemeyer jdemeyer removed this from the sage-5.10 milestone May 23, 2013
@vbraun
Copy link
Member

vbraun commented May 23, 2013

Initial patch

@vbraun
Copy link
Member

vbraun commented May 23, 2013

comment:52

Attachment: trac_12728_docbuild_workaround.patch.gz

I suggest we just revert the two includes that trigger the Cython bug.

@vbraun

This comment has been minimized.

@vbraun
Copy link
Member

vbraun commented May 23, 2013

Changed dependencies from #14634 to none

@vbraun vbraun added this to the sage-5.10 milestone May 23, 2013
@vbraun vbraun removed the pending label May 23, 2013
@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented May 23, 2013

comment:53

I'm happy with your solution. I rebuilt sagelib adding your patch to my two patches, then built the doc from there : perfect. Positive review!

@SnarkBoojum
Copy link
Mannequin Author

SnarkBoojum mannequin commented May 23, 2013

Changed reviewer from Volker Braun, Jeroen Demeyer to Volker Braun, Jeroen Demeyer, Julien Puydt

@jdemeyer
Copy link
Contributor

Merged: sage-5.10.beta5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants