Changeset 7470:63e219ed12ee in orange


Ignore:
Timestamp:
02/04/11 16:46:02 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
37334cfcf80e0fb77cd480e84f9f4c8cc24c5d15
Message:
  • added comments to fixers
Location:
orange/fixes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orange/fixes/fix_changed_names.py

    r7355 r7470  
     1""" This fixer changes all occurrences of the form 'module.member' from the 
     2global dictionary MAPPING's keys and replaces them with the corresponding 
     3value. It adds the proper imports to make it available in the script 
     4 
     5For example this code:: 
     6    import orange 
     7    import orngSVM 
     8    data = orange.ExampleTable("iris") 
     9    learner = orngSVM.SVMLearner(name='svm') 
     10     
     11will be replaced with:: 
     12    import Orange.data 
     13    import Orange.classification.svm 
     14    data =Orange.data.Table('iris') 
     15    learner =Orange.classification.svm.SVMLearner(name='svm') 
     16     
     17Try to add as much name mappings as possible (This fixer is prefered  
     18(and will run before) the fix_orange_imports   
     19     
     20""" 
    121from lib2to3 import fixer_base 
    222from lib2to3 import fixer_util 
  • orange/fixes/fix_changed_names_aggressive.py

    r7341 r7470  
    3030         
    3131        fixer_base.BaseFix.compile_pattern(self) 
    32          
    33 #    def package_tree(self, package): 
    34 #        """ Return pytree tree for asscesing the package 
    35 #         
    36 #        Example: 
    37 #            >>> package_tree("Orange.feature.scoring") 
    38 #            [Name('Orange'), trailer('.' 'feature'), trailer('.', 'scoring')] 
    39 #        """ 
    40 #        path = package.split('.') 
    41 #        nodes = [] 
    42 #        nodes.append(Name(path[0])) 
    43 #        for name in path[1:]: 
    44 #            new = pytree.Node(self.syms.trailer, [Dot(), Name(name)]) 
    45 #            nodes.append(new) 
    46 #        return nodes 
    47          
    48          
     32                 
    4933    def transform(self, node, results): 
    5034        local = results.get("local") 
  • orange/fixes/fix_orange_imports.py

    r7328 r7470  
     1""" This fixer changes old orange imports (imports of orange, orngSVM, 
     2orngClustering ...) to the corresponding package in the new hierarchy.  
     3It will also fix all occurrences of the module names in the script. 
    14 
     5For example it will replace this code:: 
     6    import orange 
     7    learner = orange.SVMLearner(name='svm') 
     8 
     9with: 
     10    import Orange.core 
     11    learner = Orange.core.SVMLearner(name='svm') 
     12     
     13.. note:: That this is possible only if the new package is a full 
     14    replacement for the old module (i.e. it exposes the same interface). 
     15    If this is not the case use the fix_changed_names fixer and list all 
     16    package content renames. 
     17     
     18.. note:: This fixer runs last and should be used as a last resort. Use 
     19    fix_changed_names fixer for fain grain control of name mappings. (for 
     20    instance we might want to replace the orange.SVMLearner from the core 
     21    to the one in Orange.classification.svm). 
     22   
     23""" 
    224from lib2to3 import fixer_base 
    325from lib2to3 import fixer_util 
     
    527 
    628from lib2to3.fixes import fix_imports 
     29     
    730 
    8 #Why does this not work?? but the copy paste of FixImports class does 
    9  
    10 #class FixOrangeImports(fix_imports.FixImports): 
    11 #    mapping = {"orange": "Orange.core"} 
    12 #     
    13 #    def transfrom(self, node, results): 
    14 #        if "use" in results: 
    15 #            nodes = [fixer_util.Node("core"), 
    16 #                     fixer_util.Dot() 
    17 #                     ] 
    18 #        return fixer_util.FromImport("Orange", "core") 
    19 #     
    20  
    21 """Fix incompatible imports and module references.""" 
    22 # Authors: Collin Winter, Nick Edds 
     31"""Fix incompatible imports and module references. Modified from the 
     32fix_imports fixer in lib2to3 by Collin Winter, Nick Edds. """ 
    2333 
    2434# Local imports 
Note: See TracChangeset for help on using the changeset viewer.