Changeset 10471:51b3ee98ec02 in orange for Orange/__init__.py


Ignore:
Timestamp:
03/08/12 15:19:10 (2 years ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Removed the use of ugly builtin.ORANGESETUP. Instead use imp module to load Orange.version directly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/__init__.py

    r10470 r10471  
    33__version__ = "2.5a4" 
    44 
     5from . import orange 
     6 
     7# Definitely ugly, but I see no other workaround. 
     8# When, e.g. data.io executes "from orange import ExampleTable" 
     9# orange gets imported again since it is not in sys.modules 
     10# before this entire file is executed 
     11import sys 
     12sys.modules["orange"] = orange 
     13 
     14import warnings 
     15 
     16alreadyWarned = False 
     17disabledMsg = "Some features will be disabled due to failing modules\n" 
     18def _import(name): 
     19    global alreadyWarned 
     20    try: 
     21        __import__(name, globals(), locals(), [], -1) 
     22    except ImportError, err: 
     23        warnings.warn("%sImporting '%s' failed: %s" % 
     24            (disabledMsg if not alreadyWarned else "", name, err), 
     25            UserWarning, 2) 
     26        alreadyWarned = True 
     27 
     28_import("misc") 
     29_import("data") 
     30_import("data.io") 
     31_import("data.sample") 
     32_import("data.outliers") 
     33_import("data.utils") 
     34_import("data.discretization") 
     35_import("data.continuization") 
     36_import("data.filter") 
     37_import("data.imputation") 
     38 
     39_import("feature") 
     40_import("feature.construction") 
     41_import("feature.construction.functionDecomposition") 
     42_import("feature.construction.univariate") 
     43_import("feature.discretization") 
     44_import("feature.imputation") 
     45_import("feature.scoring") 
     46_import("feature.selection") 
     47 
     48_import("network") 
     49 
     50_import("stat") 
     51 
     52_import("statistics") 
     53_import("statistics.estimate") 
     54_import("statistics.contingency") 
     55_import("statistics.distribution") 
     56_import("statistics.basic") 
     57_import("statistics.evd") 
     58 
     59_import("classification") 
     60_import("classification.tree") 
     61 
     62_import("classification.rules") 
     63 
     64_import("classification.lookup") 
     65_import("classification.bayes") 
     66_import("classification.svm") 
     67_import("classification.logreg") 
     68_import("classification.knn") 
     69_import("classification.majority") 
     70 
     71_import("optimization") 
     72 
     73_import("projection") 
     74_import("projection.linear") 
     75_import("projection.mds") 
     76_import("projection.som") 
     77_import("projection.pca") 
     78 
     79_import("ensemble") 
     80_import("ensemble.bagging") 
     81_import("ensemble.boosting") 
     82_import("ensemble.forest") 
     83 
     84_import("regression") 
     85_import("regression.base") 
     86_import("regression.earth") 
     87_import("regression.lasso") 
     88_import("regression.linear") 
     89_import("regression.mean") 
     90_import("regression.pls") 
     91_import("regression.tree") 
     92 
     93_import("multitarget") 
     94_import("multitarget.tree") 
     95 
     96_import("multilabel") 
     97_import("multilabel.multibase") 
     98_import("multilabel.br") 
     99_import("multilabel.lp") 
     100_import("multilabel.mlknn") 
     101_import("multilabel.brknn") 
     102_import("multilabel.mulan") 
     103 
     104_import("associate") 
     105 
     106_import("preprocess") 
     107_import("preprocess.scaling") 
     108 
     109_import("distance") 
     110 
     111_import("wrappers") 
     112 
     113_import("featureConstruction") 
     114_import("featureConstruction.univariate") 
     115_import("featureConstruction.functionDecomposition") 
     116 
     117_import("evaluation") 
     118_import("evaluation.scoring") 
     119_import("evaluation.testing") 
     120_import("evaluation.reliability") 
     121 
     122_import("clustering") 
     123_import("clustering.kmeans") 
     124_import("clustering.hierarchical") 
     125_import("clustering.consensus") 
     126 
     127_import("misc") 
     128_import("misc.environ") 
     129_import("misc.counters") 
     130_import("misc.addons") 
     131_import("misc.render") 
     132_import("misc.selection") 
     133_import("misc.serverfiles") 
     134#_import("misc.r") 
     135 
    5136try: 
    6     __ORANGE_SETUP__ 
    7 except NameError: 
    8     __ORANGE_SETUP__ = False 
     137    from . import version 
     138    # Always use short_version here (see PEP 386) 
     139    __version__ = version.short_version 
     140    __hg_revision__ = version.hg_revision 
     141except ImportError: 
     142    # Leave the default version defined at the top. 
     143    pass 
    9144 
    10  
    11 if __ORANGE_SETUP__: 
    12     import sys as _sys 
    13     _sys.stderr.write('Running from orange source directory.\n') 
    14     del _sys 
    15 else: 
    16     from . import orange 
    17  
    18     # Definitely ugly, but I see no other workaround. 
    19     # When, e.g. data.io executes "from orange import ExampleTable" 
    20     # orange gets imported again since it is not in sys.modules 
    21     # before this entire file is executed 
    22     import sys 
    23     sys.modules["orange"] = orange 
    24  
    25     import warnings 
    26  
    27     alreadyWarned = False 
    28     disabledMsg = "Some features will be disabled due to failing modules\n" 
    29     def _import(name): 
    30         global alreadyWarned 
    31         try: 
    32             __import__(name, globals(), locals(), [], -1) 
    33         except ImportError, err: 
    34             warnings.warn("%sImporting '%s' failed: %s" % 
    35                 (disabledMsg if not alreadyWarned else "", name, err), 
    36                 UserWarning, 2) 
    37             alreadyWarned = True 
    38  
    39     _import("misc") 
    40     _import("data") 
    41     _import("data.io") 
    42     _import("data.sample") 
    43     _import("data.outliers") 
    44     _import("data.utils") 
    45     _import("data.discretization") 
    46     _import("data.continuization") 
    47     _import("data.filter") 
    48     _import("data.imputation") 
    49  
    50     _import("feature") 
    51     _import("feature.construction") 
    52     _import("feature.construction.functionDecomposition") 
    53     _import("feature.construction.univariate") 
    54     _import("feature.discretization") 
    55     _import("feature.imputation") 
    56     _import("feature.scoring") 
    57     _import("feature.selection") 
    58  
    59     _import("network") 
    60  
    61     _import("stat") 
    62  
    63     _import("statistics") 
    64     _import("statistics.estimate") 
    65     _import("statistics.contingency") 
    66     _import("statistics.distribution") 
    67     _import("statistics.basic") 
    68     _import("statistics.evd") 
    69  
    70     _import("classification") 
    71     _import("classification.tree") 
    72  
    73     _import("classification.rules") 
    74  
    75     _import("classification.lookup") 
    76     _import("classification.bayes") 
    77     _import("classification.svm") 
    78     _import("classification.logreg") 
    79     _import("classification.knn") 
    80     _import("classification.majority") 
    81  
    82     _import("optimization") 
    83  
    84     _import("projection") 
    85     _import("projection.linear") 
    86     _import("projection.mds") 
    87     _import("projection.som") 
    88     _import("projection.pca") 
    89  
    90     _import("ensemble") 
    91     _import("ensemble.bagging") 
    92     _import("ensemble.boosting") 
    93     _import("ensemble.forest") 
    94  
    95     _import("regression") 
    96     _import("regression.base") 
    97     _import("regression.earth") 
    98     _import("regression.lasso") 
    99     _import("regression.linear") 
    100     _import("regression.mean") 
    101     _import("regression.pls") 
    102     _import("regression.tree") 
    103  
    104     _import("multitarget") 
    105     _import("multitarget.tree") 
    106  
    107     _import("multilabel") 
    108     _import("multilabel.multibase") 
    109     _import("multilabel.br") 
    110     _import("multilabel.lp") 
    111     _import("multilabel.mlknn") 
    112     _import("multilabel.brknn") 
    113     _import("multilabel.mulan") 
    114  
    115     _import("associate") 
    116  
    117     _import("preprocess") 
    118     _import("preprocess.scaling") 
    119  
    120     _import("distance") 
    121  
    122     _import("wrappers") 
    123  
    124     _import("featureConstruction") 
    125     _import("featureConstruction.univariate") 
    126     _import("featureConstruction.functionDecomposition") 
    127  
    128     _import("evaluation") 
    129     _import("evaluation.scoring") 
    130     _import("evaluation.testing") 
    131     _import("evaluation.reliability") 
    132  
    133     _import("clustering") 
    134     _import("clustering.kmeans") 
    135     _import("clustering.hierarchical") 
    136     _import("clustering.consensus") 
    137  
    138     _import("misc") 
    139     _import("misc.environ") 
    140     _import("misc.counters") 
    141     _import("misc.addons") 
    142     _import("misc.render") 
    143     _import("misc.selection") 
    144     _import("misc.serverfiles") 
    145     #_import("misc.r") 
    146  
Note: See TracChangeset for help on using the changeset viewer.