File: __init__.py

package info (click to toggle)
python-igraph 0.7.1.post6-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,288 kB
  • ctags: 2,287
  • sloc: ansic: 20,069; python: 14,108; sh: 56; makefile: 9
file content (40 lines) | stat: -rw-r--r-- 1,246 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
This package contains third party libraries that igraph depends on and that
are small enough to be distributed with igraph itself.

The primary entry point of this module is ``vendor_import``, a function that
first tries to import a particular library using the standard Python mechanism
and falls back to the version of the library provided within ``igraph.vendor``
if the standard Python import fails.

The libraries contained within igraph are as follows:

	- `texttable`, a library to print ASCII tables, by Gerome Fournier.
	  See <http://foutaise.org/code/>.
"""

__license__ = "GPL"

__all__ = ["vendor_import"]
__docformat__ = "restructuredtext en"

def vendor_import(module_name):
	"""Tries to import a module name ``module_name`` using the standard Python
	`import` statement and return the imported module. If the import fails,
	tries to import a module of the same name from within ``igraph.vendor``
	and return that module instead.
	"""

	parts = module_name.split(".")

	try:
		result = __import__(module_name, level=0)
	except ImportError:
		result = __import__("igraph.vendor.%s" % module_name, level=0)
		parts[0:0] = ["igraph", "vendor"]

	parts.pop(0)
	while parts:
		result = getattr(result, parts.pop(0))

	return result