source: orange/Orange/__init__.py @ 10974:a208761d8586

Revision 10974:a208761d8586, 5.1 KB checked in by Miran Levar <mlevar@…>, 20 months ago (diff)

Removed multitarget imports from init.py

Line 
1from __future__ import absolute_import
2
3# This is overwritten with version from version.py, which is generated by
4# setup.py automatically
5__version__ = "unknown"
6
7ADDONS_ENTRY_POINT = 'orange.addons'
8
9from . import orange
10
11# Definitely ugly, but I see no other workaround.
12# When, e.g. data.io executes "from orange import ExampleTable"
13# orange gets imported again since it is not in sys.modules
14# before this entire file is executed
15import sys
16sys.modules["orange"] = orange
17
18# Little trick so that legacy imports work automatically
19import Orange.orng
20sys.path = Orange.orng.__path__ + sys.path
21
22import warnings
23import pkg_resources
24
25alreadyWarned = False
26disabledMsg = "Some features will be disabled due to failing modules\n"
27def _import(name):
28    global alreadyWarned
29    try:
30        __import__(name, globals(), locals(), [], -1)
31    except ImportError, err:
32        warnings.warn("%sImporting '%s' failed: %s" %
33            (disabledMsg if not alreadyWarned else "", name, err),
34            UserWarning, 2)
35        alreadyWarned = True
36
37def _import_addons():
38    globals_dict = globals()
39    for entry_point in pkg_resources.iter_entry_points(ADDONS_ENTRY_POINT):
40        try:
41            module = entry_point.load()
42            # Dot is not allowed in an entry point name (it should
43            # be a Python identifier, because it is used as a class
44            # name), so we are using __ instead
45            name = entry_point.name.replace('__', '.')
46            if '.' not in name:
47                globals_dict[name] = module
48            else:
49                path, mod = name.rsplit('.', 1)
50                parent_module_name = 'Orange.%s' % (path,)
51                try:
52                    parent_module = sys.modules[parent_module_name]
53                except KeyError:
54                    warnings.warn("Loading add-on '%s' failed because destination namespace point '%s' was not found." % (entry_point.name, parent_module_name), UserWarning, 2)
55                    continue
56                setattr(parent_module, mod, module)
57            sys.modules['Orange.%s' % (name,)] = module
58        except ImportError, err:
59            warnings.warn("Importing add-on '%s' failed: %s" % (entry_point.name, err), UserWarning, 2)
60        except pkg_resources.DistributionNotFound, err:
61            warnings.warn("Loading add-on '%s' failed because of a missing dependency: '%s'" % (entry_point.name, err), UserWarning, 2)
62        except Exception, err:
63            warnings.warn("An exception occurred during the loading of '%s':\n%r" %(entry_point.name, err), UserWarning, 2)
64
65
66_import("utils")
67
68_import("data")
69_import("data.io")
70_import("data.sample")
71_import("data.outliers")
72_import("data.preprocess")
73_import("data.preprocess.scaling")
74_import("data.utils")
75_import("data.discretization")
76_import("data.continuization")
77_import("data.filter")
78_import("data.imputation")
79
80_import("feature")
81_import("feature.construction")
82_import("feature.construction.functionDecomposition")
83_import("feature.construction.univariate")
84_import("feature.discretization")
85_import("feature.imputation")
86_import("feature.scoring")
87_import("feature.selection")
88
89_import("network")
90
91_import("stat")
92
93_import("statistics")
94_import("statistics.estimate")
95_import("statistics.contingency")
96_import("statistics.distribution")
97_import("statistics.basic")
98_import("statistics.evd")
99
100_import("classification")
101_import("classification.tree")
102
103_import("classification.rules")
104
105_import("classification.lookup")
106_import("classification.bayes")
107_import("classification.svm")
108_import("classification.logreg")
109_import("classification.knn")
110_import("classification.majority")
111
112_import("tuning")
113
114_import("projection")
115_import("projection.linear")
116_import("projection.mds")
117_import("projection.som")
118
119_import("ensemble")
120_import("ensemble.bagging")
121_import("ensemble.boosting")
122_import("ensemble.forest")
123_import("ensemble.stacking")
124
125_import("regression")
126_import("regression.base")
127_import("regression.earth")
128_import("regression.lasso")
129_import("regression.linear")
130_import("regression.mean")
131_import("regression.pls")
132_import("regression.tree")
133
134_import("multilabel")
135_import("multilabel.multibase")
136_import("multilabel.br")
137_import("multilabel.lp")
138_import("multilabel.mlknn")
139_import("multilabel.brknn")
140_import("multilabel.mulan")
141
142_import("associate")
143
144_import("distance")
145
146_import("wrappers")
147
148_import("featureConstruction")
149_import("featureConstruction.univariate")
150_import("featureConstruction.functionDecomposition")
151
152_import("evaluation")
153_import("evaluation.scoring")
154_import("evaluation.testing")
155
156_import("clustering")
157_import("clustering.kmeans")
158_import("clustering.hierarchical")
159_import("clustering.consensus")
160
161_import("misc")
162
163_import("utils") #TODO hide utils from the user
164_import("utils.environ")
165_import("utils.counters")
166_import("utils.addons")
167_import("utils.render")
168_import("utils.serverfiles")
169
170_import_addons()
171
172try:
173    from . import version
174    # Always use short_version here (see PEP 386)
175    __version__ = version.short_version
176    __hg_revision__ = version.hg_revision
177except ImportError:
178    # Leave the default version defined at the top.
179    pass
180
181del _import
182del _import_addons
183del alreadyWarned
184del disabledMsg
Note: See TracBrowser for help on using the repository browser.