Skip to content

Commit

Permalink
Trac #27472: py3: import error
Browse files Browse the repository at this point in the history
This is bug report on python3-build sage.

When attaching a file which loads a pyx file, the reloading fails.

Steps to reproduce:

create a file "test.py" with
{{{
from sage.misc.persist import load
load("anyfile.pyx")

def cool(n):
    return -n
}}}
and a pyx file with the chosen name.

Then attach the test.py file. This should compile the pyx file.

Then modify a function in the test.py file and save it.

Then one gets an error:
{{{
### reloading attached file test.py modified at 16:49:10 ###
  File "<string>", line 1
    from _home_chapoton_anyfile_pyx_0.cpython-36m-x86_64-linux-gnu
import *
            ^
SyntaxError: invalid syntax
}}}

I suspect that maybe the issue is the presence of `-` in the name of the
created python module.

URL: https://trac.sagemath.org/27472
Reported by: chapoton
Ticket author(s): Erik Bray, Frédéric Chapoton
Reviewer(s): François Bissey
  • Loading branch information
Release Manager authored and vbraun committed Apr 7, 2019
2 parents 409939a + d29aa5c commit 347b51a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
23 changes: 18 additions & 5 deletions src/sage/misc/sageinspect.py
Expand Up @@ -122,14 +122,22 @@ def foo(unsigned int x=1, a=')"', b={not (2+1==3):'bar'}, *args, **kwds): return
import inspect
import functools
import os
import sys
import tokenize
import re
EMBEDDED_MODE = False
from sage.env import SAGE_LIB

try:
import importlib.machinery as import_machinery
except ImportError:
pass


def loadable_module_extension():
r"""
Return the filename extension of loadable modules, including the dot.
It is '.dll' on cygwin, '.so' otherwise.
EXAMPLES::
Expand All @@ -138,11 +146,15 @@ def loadable_module_extension():
sage: sage.structure.sage_object.__file__.endswith(loadable_module_extension())
True
"""
import sys
if sys.platform == 'cygwin':
return os.path.extsep+'dll'
if six.PY2:
if sys.platform == 'cygwin':
return os.path.extsep + 'dll'
else:
return os.path.extsep + 'so'
else:
return os.path.extsep+'so'
# Return the full platform-specific extension module suffix
return import_machinery.EXTENSION_SUFFIXES[0]


def isclassinstance(obj):
r"""
Expand Down Expand Up @@ -2093,7 +2105,8 @@ class ParentMethods:
# the length of lines, which causes an error. Safeguard against that.
lnum = min(obj.co_firstlineno,len(lines))-1
while lnum > 0:
if pmatch(lines[lnum]): break
if pmatch(lines[lnum]):
break
lnum -= 1

return inspect.getblock(lines[lnum:]), lnum+base_lineno
Expand Down
12 changes: 6 additions & 6 deletions src/sage/repl/attach.py
Expand Up @@ -58,15 +58,15 @@
sage: detach(src)
"""

#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2013 Volker Braun <vbraun.name@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
# https://www.gnu.org/licenses/
# ****************************************************************************
from __future__ import print_function

import os
Expand Down Expand Up @@ -532,8 +532,8 @@ def modified_file_iterator():
[('/.../tmp_....py', time.struct_time(...))]
"""
global attached
modified = dict()
for filename in attached.keys():
modified = {}
for filename in list(attached):
old_tm = attached[filename]
if not os.path.exists(filename):
print('### detaching file {0} because it does not exist (deleted?) ###'.format(filename))
Expand All @@ -547,7 +547,7 @@ def modified_file_iterator():
return
time.sleep(0.1) # sleep 100ms to give the editor time to finish saving

for filename in modified.keys():
for filename in list(modified):
old_tm = modified[filename]
new_tm = os.path.getmtime(filename)
if new_tm == old_tm:
Expand Down

0 comments on commit 347b51a

Please sign in to comment.