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

py3: failing doctest in graph_database.py with interactive_query #27435

Closed
dcoudert opened this issue Mar 7, 2019 · 24 comments
Closed

py3: failing doctest in graph_database.py with interactive_query #27435

dcoudert opened this issue Mar 7, 2019 · 24 comments

Comments

@dcoudert
Copy link
Contributor

dcoudert commented Mar 7, 2019

sage -t --long src/sage/graphs/graph_database.py
**********************************************************************
File "src/sage/graphs/graph_database.py", line 1081, in sage.graphs.graph_database.GraphDatabase.interactive_query
Failed example:
    D.interactive_query(display_cols=['graph6', 'num_vertices', 'degree_sequence'], num_edges=5, max_degree=3)
Exception raised:
    Traceback (most recent call last):
      File "/Users/dcoudert/sage3/sage/local/lib/python3.6/inspect.py", line 1119, in getfullargspec
        sigcls=Signature)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.6/inspect.py", line 2186, in _signature_from_callable
        raise TypeError('{!r} is not a callable object'.format(obj))
    TypeError: 0 is not a callable object

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):
      File "/Users/dcoudert/sage3/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 671, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.6/site-packages/sage/doctest/forker.py", line 1095, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.graphs.graph_database.GraphDatabase.interactive_query[1]>", line 1, in <module>
        D.interactive_query(display_cols=['graph6', 'num_vertices', 'degree_sequence'], num_edges=Integer(5), max_degree=Integer(3))
      File "/Users/dcoudert/sage3/sage/local/lib/python3.6/site-packages/sage/graphs/graph_database.py", line 1087, in interactive_query
        interact(f)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.6/site-packages/sage/misc/decorators.py", line 343, in my_wrap
        return func(*args)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.6/site-packages/sagenb/notebook/interact.py", line 2636, in interact
        (args, varargs, varkw, defaults) = inspect.getargspec(f)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.6/inspect.py", line 1073, in getargspec
        getfullargspec(func)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.6/inspect.py", line 1125, in getfullargspec
        raise TypeError('unsupported callable') from ex
    TypeError: unsupported callable

CC: @dimpase @jdemeyer

Component: graph theory

Author: Ewan Davies, David Coudert

Branch/Commit: 10fd0e8

Reviewer: Frédéric Chapoton, John Palmieri

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

@dcoudert dcoudert added this to the sage-8.7 milestone Mar 7, 2019
@dcoudert
Copy link
Contributor Author

dcoudert commented Mar 7, 2019

comment:1

I don't know how to fix it.

@sheldoncooper07
Copy link
Mannequin

sheldoncooper07 mannequin commented Mar 8, 2019

comment:2

Hi, I am Piyush, I am new to sage, I was wondering if I could be of some help here.

I am not able to replicate this test. Is there something that I am missing? I am using Ubuntu 16.04

$ ./sage -t --long src/sage/graphs/graph_database.py
Running doctests with ID 2019-03-08-11-03-04-40b4d48a.
Git branch: develop
Using --optional=dochtml,memlimit,mpir,python2,sage
Doctesting 1 file.
sage -t --long src/sage/graphs/graph_database.py
    [50 tests, 0.49 s]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 0.6 seconds
    cpu time: 0.5 seconds
    cumulative wall time: 0.5 seconds

@dcoudert
Copy link
Contributor Author

dcoudert commented Mar 8, 2019

comment:3

The problem is with Python 3. We are working hard on the transition from Python 2 to Python 3.

@embray
Copy link
Contributor

embray commented Mar 25, 2019

comment:4

Ticket retargeted after milestone closed (if you don't believe this ticket is appropriate for the Sage 8.8 release please retarget manually)

@embray embray modified the milestones: sage-8.7, sage-8.8 Mar 25, 2019
@ed359
Copy link
Contributor

ed359 commented May 13, 2019

comment:5

I may have managed to fix this error. I don't know anything about the origins of the code but the error arises in in graph_database._gen_interact_func where it seems a string defining a function called _ is run with exec.

I tried changing the name of the function that gets defined and ran into a different python3-related bug in the sagenb python package (maintained out of the main sage tree): it still uses xrange in sagenb.notebook.interact at line 1185.

I downloaded the source for that package, changed the uses of xrange, and now the doctest passes on my machine, but the bar for passing is simply emitting a string starting and finishing with <html> and </html>.

I'm not sure what to suggest for this ticket, the doctest in question has something to do with the old sage notebook (sagenb). The function interactive_query returns some html that doesn't appear do anything in jupyter, and I can't use the old notebook on python3 (an error related to Twisted). Is the old notebook formally deprecated? See #22431 and in particular the 'side remark' about the graph database explorer.

If my changes to _gen_interact_func and the sagenb package are wanted I can send patches, but as I can't run the notebook myself on python3 I can't even verify that it's a proper fix.

@dcoudert
Copy link
Contributor Author

comment:6

Let's ask the author of #22431 if anything was said about graph_editor and interactive queries in graph_database.

Also I don't know if these tools have users. If not, we may simply deprecate the parts involving sagenb. Otherwise, someone with enough knowledge in notebooks should try to solve the issues.

@dimpase
Copy link
Member

dimpase commented May 13, 2019

comment:7

Replying to @ed359:

I may have managed to fix this error. I don't know anything about the origins of the code but the error arises in in graph_database._gen_interact_func where it seems a string defining a function called _ is run with exec.

I tried changing the name of the function that gets defined and ran into a different python3-related bug in the sagenb python package (maintained out of the main sage tree): it still uses xrange in sagenb.notebook.interact at line 1185.

I downloaded the source for that package, changed the uses of xrange, and now the doctest passes on my machine, but the bar for passing is simply emitting a string starting and finishing with <html> and </html>.

I'm not sure what to suggest for this ticket, the doctest in question has something to do with the old sage notebook (sagenb). The function interactive_query returns some html that doesn't appear do anything in jupyter, and I can't use the old notebook on python3 (an error related to Twisted). Is the old notebook formally deprecated? See #22431 and in particular the 'side remark' about the graph database explorer.

If my changes to _gen_interact_func and the sagenb package are wanted I can send patches, but as I can't run the notebook myself on python3 I can't even verify that it's a proper fix.

As long as these changes don't break sagenb on python2, it is fine.
Please send a PR on https://github.com/sagemath/sagenb
(perhaps they are already fixed in the 4 most recent open PRs there.)

As to functionality to be removed, I don't know.

@ed359
Copy link
Contributor

ed359 commented May 13, 2019

@kcrisman
Copy link
Member

comment:9

Thanks. We may need to think about how to deal with this in the eventual removal of sagenb, as the interact should in principle still be able to work in e.g. Jupyter notebooks, but would have to import from elsewhere. Cc:ing Jeroen as he knows a lot about how that is implemented in Jupyter and where things might need to import from now.


New commits:

2d05ce8graph_database.py: fix doctest on python3

@kcrisman
Copy link
Member

Commit: 2d05ce8

@dcoudert
Copy link
Contributor Author

comment:10

Now the error is in sagenb (tested over 8.8.beta6).

sage -t --long src/sage/graphs/graph_database.py
**********************************************************************
File "src/sage/graphs/graph_database.py", line 1082, in sage.graphs.graph_database.GraphDatabase.interactive_query
Failed example:
    D.interactive_query(display_cols=['graph6', 'num_vertices', 'degree_sequence'], num_edges=5, max_degree=3)
Exception raised:
    Traceback (most recent call last):
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 681, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 1105, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.graphs.graph_database.GraphDatabase.interactive_query[1]>", line 1, in <module>
        D.interactive_query(display_cols=['graph6', 'num_vertices', 'degree_sequence'], num_edges=Integer(5), max_degree=Integer(3))
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/graphs/graph_database.py", line 1088, in interactive_query
        interact(f)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/misc/decorators.py", line 343, in my_wrap
        return func(*args)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sagenb/notebook/interact.py", line 2643, in interact
        for i, arg in enumerate(args)]
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sagenb/notebook/interact.py", line 2643, in <listcomp>
        for i, arg in enumerate(args)]
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sagenb/notebook/interact.py", line 3093, in render
        to_value=self.__to_value, width=self.__width)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sagenb/notebook/interact.py", line 1185, in __init__
        default_value = [[default_value[i * columns + j] for j in xrange(columns)] for i in xrange(rows)]
    NameError: name 'xrange' is not defined
**********************************************************************

@embray
Copy link
Contributor

embray commented Jun 14, 2019

comment:11

As the Sage-8.8 release milestone is pending, we should delete the sage-8.8 milestone for tickets that are not actively being worked on or that still require significant work to move forward. If you feel that this ticket should be included in the next Sage release at the soonest please set its milestone to the next release milestone (sage-8.9).

@embray embray removed this from the sage-8.8 milestone Jun 14, 2019
@dcoudert dcoudert added this to the sage-8.9 milestone Jun 15, 2019
@jhpalmieri
Copy link
Member

comment:13

If the problem is with sagenb, then can we mark the doctest as "# py2", since my understanding is that sagenb is not compatible with Python 3? That is, keep the proposed changes here, but also tag the doctest as py2 only.

@dimpase
Copy link
Member

dimpase commented Jul 10, 2019

comment:14

can't we just skip installing sagenb on Python3?

@jhpalmieri
Copy link
Member

comment:15

I think that sagenb as a whole does not work with Python 3, but parts of it do, and parts are imported into the Sage library in various places. If we don't install it, some things may break. Some of the imports:

src/sage/graphs/graph_editor.py:    import sagenb.notebook.interact
src/sage/interacts/library.py:        import sagenb.notebook.interact
src/sage/interacts/debugger.py:        from sagenb.notebook.interact import slider, input_box, selector

@dcoudert
Copy link
Contributor Author

comment:16

I agree with the proposal of marking this doctest as # py2, but we should also add that there is known issue with py3, no ? This way, we don't await for a decision about sagenb.

@dcoudert
Copy link
Contributor Author

comment:17

I added proposed modification and pushed the code to a new branch in public. Feel free to modify it if needed.


New commits:

d5074f9trac #27435: Merged with 8.9.beta2
10fd0e8trac #27435: mark doctest as py2 only and add warning block

@dcoudert
Copy link
Contributor Author

Author: Ewan Davies, David Coudert

@dcoudert
Copy link
Contributor Author

@dcoudert
Copy link
Contributor Author

Changed commit from 2d05ce8 to 10fd0e8

@jhpalmieri
Copy link
Member

comment:18

This is fine with me. Anyone else have any comments? Objections to setting to positive review?

@fchapoton
Copy link
Contributor

Reviewer: Frédéric Chapoton, John Palmieri

@fchapoton
Copy link
Contributor

comment:19

ok..

@vbraun
Copy link
Member

vbraun commented Jul 20, 2019

Changed branch from public/graphs/27435_doctest_in_graph_database to 10fd0e8

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

8 participants