source: orange/Orange/__init__.py @ 11031:4d70c107a289

Revision 11031:4d70c107a289, 5.2 KB checked in by Miha Stajdohar <miha.stajdohar@…>, 18 months ago (diff)

Workaround for readthedocs.

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