source: orange/Orange/__init__.py @ 10892:0baeb90e4e08

Revision 10892:0baeb90e4e08, 4.8 KB checked in by mitar, 2 years ago (diff)

Enable loading add-ons deeper into the Orange namespace.

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 = sys.modules['Orange.%s' % (path,)]
51                setattr(parent_module, mod, module)
52            sys.modules['Orange.%s' % (name,)] = module
53        except ImportError, err:
54            warnings.warn("Importing add-on '%s' failed: %s" % (entry_point.name, err), UserWarning, 2)
55        except pkg_resources.DistributionNotFound, err:
56            warnings.warn("Loading add-on '%s' failed because of a missing dependency: '%s'" % (entry_point.name, err), UserWarning, 2)
57        except Exception, err:
58            warnings.warn("An exception occurred during the loading of '%s':\n%r" %(entry_point.name, err), UserWarning, 2)
59
60
61_import("utils")
62
63_import("data")
64_import("data.io")
65_import("data.sample")
66_import("data.outliers")
67_import("data.preprocess")
68_import("data.preprocess.scaling")
69_import("data.utils")
70_import("data.discretization")
71_import("data.continuization")
72_import("data.filter")
73_import("data.imputation")
74
75_import("feature")
76_import("feature.construction")
77_import("feature.construction.functionDecomposition")
78_import("feature.construction.univariate")
79_import("feature.discretization")
80_import("feature.imputation")
81_import("feature.scoring")
82_import("feature.selection")
83
84_import("network")
85
86_import("stat")
87
88_import("statistics")
89_import("statistics.estimate")
90_import("statistics.contingency")
91_import("statistics.distribution")
92_import("statistics.basic")
93_import("statistics.evd")
94
95_import("classification")
96_import("classification.tree")
97
98_import("classification.rules")
99
100_import("classification.lookup")
101_import("classification.bayes")
102_import("classification.svm")
103_import("classification.logreg")
104_import("classification.knn")
105_import("classification.majority")
106
107_import("tuning")
108
109_import("projection")
110_import("projection.linear")
111_import("projection.mds")
112_import("projection.som")
113
114_import("ensemble")
115_import("ensemble.bagging")
116_import("ensemble.boosting")
117_import("ensemble.forest")
118_import("ensemble.stacking")
119
120_import("regression")
121_import("regression.base")
122_import("regression.earth")
123_import("regression.lasso")
124_import("regression.linear")
125_import("regression.mean")
126_import("regression.pls")
127_import("regression.tree")
128
129_import("multitarget")
130_import("multitarget.tree")
131
132_import("multilabel")
133_import("multilabel.multibase")
134_import("multilabel.br")
135_import("multilabel.lp")
136_import("multilabel.mlknn")
137_import("multilabel.brknn")
138_import("multilabel.mulan")
139
140_import("associate")
141
142_import("distance")
143
144_import("wrappers")
145
146_import("featureConstruction")
147_import("featureConstruction.univariate")
148_import("featureConstruction.functionDecomposition")
149
150_import("evaluation")
151_import("evaluation.scoring")
152_import("evaluation.testing")
153
154_import("clustering")
155_import("clustering.kmeans")
156_import("clustering.hierarchical")
157_import("clustering.consensus")
158
159_import("misc")
160
161_import("utils") #TODO hide utils from the user
162_import("utils.environ")
163_import("utils.counters")
164_import("utils.addons")
165_import("utils.render")
166_import("utils.serverfiles")
167
168_import_addons()
169
170try:
171    from . import version
172    # Always use short_version here (see PEP 386)
173    __version__ = version.short_version
174    __hg_revision__ = version.hg_revision
175except ImportError:
176    # Leave the default version defined at the top.
177    pass
178
179del _import
180del _import_addons
181del alreadyWarned
182del disabledMsg
Note: See TracBrowser for help on using the repository browser.