#11762: More import cleanup
---------------------------+------------------------------------------------
   Reporter:  robertwb     |          Owner:  jason       
       Type:  enhancement  |         Status:  needs_review
   Priority:  major        |      Milestone:  sage-4.7.2  
  Component:  misc         |       Keywords:              
Work_issues:               |       Upstream:  N/A         
   Reviewer:               |         Author:              
     Merged:               |   Dependencies:              
---------------------------+------------------------------------------------
Changes (by robertwb):

  * status:  new => needs_review


Comment:

 Generated with

 {{{
 #!python
 import re
 import ast
 ignore = re.compile('(file.*no.*empty)|(no.*empty.*file)')

 def add_import_all(source, pkg):
     if 'import all' in source:
         return source
     lines = []
     for line in source.strip().split('\n'):
         if line and line[0] == '#':
             if line.strip('#').strip() in ('', pkg) or
 ignore.search(line[1:]):
                 continue
         lines.append(line)
     if lines:
         lines.append('')
     lines.append('import all')
     lines.append('')
     return '\n'.join(lines).lstrip()

 def import_all(sage_root):
     for root, dirs, files in os.walk('%s/devel/sage/sage/' % sage_root):
         if '__init__.py' in files and 'all.py' in files:
             file = os.path.join(root, '__init__.py')
             source = open(file).read()
             try:
                 new_source = add_import_all(source,
 os.path.basename(root))
                 if new_source != source:
                     ast.parse(new_source)
                     print file
                     open(file, 'w').write(new_source)
                     r = os.system("%s/sage -b > /dev/null 2> /dev/null" %
 sage_root)
                     if r == 0:
                         r = os.system("%s/sage -python -c 'import
 sage.all'" % sage_root)
                     if r != 0:
                         print "Failed!"
                         open(file, 'w').write(source)
                     else:
                         print "Good!"
             except Exception, exn:
                 print file, exn
 }}}

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11762#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to