Commit 869ac654 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Clean-up module loading

Reduce duplication of code for loading C++ modules.
parent 86436d9d
......@@ -2,6 +2,7 @@
graph_tool_PYTHON = \
__init__.py \
dl_import.py \
core.py \
decorators.py \
io.py \
......
......@@ -16,24 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
# RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and friends to
# work properly across DSO boundaries. See http://gcc.gnu.org/faq.html#dso
# The "except" is because the dl module raises a system error on ia64 and x86_64
# systems because "int" and addresses are different sizes.
try:
from dl import RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL
except ImportError:
RTLD_LAZY = 1
RTLD_NOW = 2
RTLD_GLOBAL = 256
_orig_dlopen_flags = sys.getdlopenflags()
sys.setdlopenflags(RTLD_LAZY|RTLD_GLOBAL)
import libgraph_tool_clustering
sys.setdlopenflags(_orig_dlopen_flags) # reset it to normal case to avoid
# unnecessary symbol collision
from .. dl_import import dl_import
dl_import("import libgraph_tool_clustering")
from .. core import _degree, _prop
from numpy import *
......
......@@ -16,29 +16,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
# RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and friends to
# work properly across DSO boundaries. See http://gcc.gnu.org/faq.html#dso
# The "except" is because the dl module raises a system error on ia64 and x86_64
# systems because "int" and addresses are different sizes.
try:
from dl import RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL
except ImportError:
RTLD_LAZY = 1
RTLD_NOW = 2
RTLD_GLOBAL = 256
_orig_dlopen_flags = sys.getdlopenflags()
sys.setdlopenflags(RTLD_LAZY|RTLD_GLOBAL)
import libgraph_tool_core as libcore
sys.setdlopenflags(_orig_dlopen_flags) # reset it to normal case to avoid
# unnecessary symbol collision
from dl_import import *
dl_import("import libgraph_tool_core as libcore")
__version__ = libcore.mod_info().version
import io # sets up libcore io routines
import os, os.path, re, struct, fcntl, termios, gzip, bz2, string,\
import sys, os, os.path, re, struct, fcntl, termios, gzip, bz2, string,\
textwrap, time, signal, traceback, shutil, time, math, inspect, \
functools, types, weakref
from StringIO import StringIO
......
......@@ -16,24 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
# RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and friends to
# work properly across DSO boundaries. See http://gcc.gnu.org/faq.html#dso
# The "except" is because the dl module raises a system error on ia64 and x86_64
# systems because "int" and addresses are different sizes.
try:
from dl import RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL
except ImportError:
RTLD_LAZY = 1
RTLD_NOW = 2
RTLD_GLOBAL = 256
_orig_dlopen_flags = sys.getdlopenflags()
sys.setdlopenflags(RTLD_LAZY|RTLD_GLOBAL)
import libgraph_tool_correlations
sys.setdlopenflags(_orig_dlopen_flags) # reset it to normal case to avoid
# unnecessary symbol collision
from .. dl_import import dl_import
dl_import("import libgraph_tool_correlations")
from .. core import _degree, _prop
from numpy import *
......
#! /usr/bin/env python
# graph_tool -- a general graph manipulation python module
#
# Copyright (C) 2007 Tiago de Paula Peixoto <tiago@forked.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
try:
from dl import RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL
except ImportError:
RTLD_LAZY = 1
RTLD_NOW = 2
RTLD_GLOBAL = 256
all = ["dl_import"]
def dl_import(import_expr):
"""Import module according to import_expr, but with RTLD_GLOBAL enabled."""
# we need to get the locals and globals of the _calling_ function. Thus, we
# need to go deeper into the call stack
call_frame = sys._getframe(1)
local_dict = call_frame.f_locals
global_dict = call_frame.f_globals
# RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and friends to
# work properly across DSO boundaries. See http://gcc.gnu.org/faq.html#dso
# The "except" is because the dl module raises a system error on ia64 and x86_64
# systems because "int" and addresses are different sizes.
orig_dlopen_flags = sys.getdlopenflags()
sys.setdlopenflags(RTLD_LAZY|RTLD_GLOBAL)
exec import_expr in local_dict, global_dict
sys.setdlopenflags(orig_dlopen_flags) # reset it to normal case to avoid
# unnecessary symbol collision
......@@ -16,32 +16,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
# RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and friends to
# work properly across DSO boundaries. See http://gcc.gnu.org/faq.html#dso
# The "except" is because the dl module raises a system error on ia64 and x86_64
# systems because "int" and addresses are different sizes.
try:
from dl import RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL
except ImportError:
RTLD_LAZY = 1
RTLD_NOW = 2
RTLD_GLOBAL = 256
_orig_dlopen_flags = sys.getdlopenflags()
sys.setdlopenflags(RTLD_LAZY|RTLD_GLOBAL)
import libgraph_tool_generation
sys.setdlopenflags(_orig_dlopen_flags) # reset it to normal case to avoid
# unnecessary symbol collision
from .. dl_import import dl_import
dl_import("import libgraph_tool_generation")
from .. core import Graph
import random
__all__ = ["random_graph"]
def random_graph(N, deg_sampler, deg_corr=None, directed=True,
parallel=False, self_loops=False,
seed=0, verbose=False):
......
......@@ -16,24 +16,9 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
# RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and friends to
# work properly across DSO boundaries. See http://gcc.gnu.org/faq.html#dso
from .. dl_import import dl_import
dl_import("import libgraph_tool_misc")
# The "except" is because the dl module raises a system error on ia64 and x86_64
# systems because "int" and addresses are different sizes.
try:
from dl import RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL
except ImportError:
RTLD_LAZY = 1
RTLD_NOW = 2
RTLD_GLOBAL = 256
_orig_dlopen_flags = sys.getdlopenflags()
sys.setdlopenflags(RTLD_LAZY|RTLD_GLOBAL)
import libgraph_tool_misc
sys.setdlopenflags(_orig_dlopen_flags) # reset it to normal case to avoid
# unnecessary symbol collision
import random, sys
__all__ = ["random_rewire"]
......
......@@ -16,24 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
# RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and friends to
# work properly across DSO boundaries. See http://gcc.gnu.org/faq.html#dso
# The "except" is because the dl module raises a system error on ia64 and x86_64
# systems because "int" and addresses are different sizes.
try:
from dl import RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL
except ImportError:
RTLD_LAZY = 1
RTLD_NOW = 2
RTLD_GLOBAL = 256
_orig_dlopen_flags = sys.getdlopenflags()
sys.setdlopenflags(RTLD_LAZY|RTLD_GLOBAL)
import libgraph_tool_stats
sys.setdlopenflags(_orig_dlopen_flags) # reset it to normal case to avoid
# unnecessary symbol collision
from .. dl_import import dl_import
dl_import("import libgraph_tool_stats")
from .. core import _degree, _prop
from numpy import *
......
......@@ -16,24 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
# RTLD_GLOBAL needs to be set in dlopen() if we want typeinfo and friends to
# work properly across DSO boundaries. See http://gcc.gnu.org/faq.html#dso
# The "except" is because the dl module raises a system error on ia64 and x86_64
# systems because "int" and addresses are different sizes.
try:
from dl import RTLD_LAZY, RTLD_NOW, RTLD_GLOBAL
except ImportError:
RTLD_LAZY = 1
RTLD_NOW = 2
RTLD_GLOBAL = 256
_orig_dlopen_flags = sys.getdlopenflags()
sys.setdlopenflags(RTLD_LAZY|RTLD_GLOBAL)
import libgraph_tool_util
sys.setdlopenflags(_orig_dlopen_flags) # reset it to normal case to avoid
# unnecessary symbol collision
from .. dl_import import dl_import
dl_import("import libgraph_tool_util")
from .. core import _degree, _prop
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment