source: orange/Orange/__init__.py @ 10879:1707c807d6f4

Revision 10879:1707c807d6f4, 4.4 KB checked in by Ales Erjavec <ales.erjavec@…>, 2 years ago (diff)

Handle all exceptions when entry_points loading fails.

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