summaryrefslogtreecommitdiff
path: root/gnuradio-core
diff options
context:
space:
mode:
authorBen Reynwar <ben@reynwar.net>2013-03-07 22:39:16 -0700
committerBen Reynwar <ben@reynwar.net>2013-03-07 22:39:16 -0700
commit45127424b4b7252dfc6d20c91709e1536497f97c (patch)
tree145bdc037a86c5f70c49115f70131e781143633b /gnuradio-core
parent27a222ad8dcd245e7b9b4ff51141bdf3d8675a3c (diff)
gnuradio-core: Enabling uninstalled python imports.
Diffstat (limited to 'gnuradio-core')
-rw-r--r--gnuradio-core/src/python/gnuradio/__init__.py20
-rw-r--r--gnuradio-core/src/python/gnuradio/gr/__init__.py12
2 files changed, 31 insertions, 1 deletions
diff --git a/gnuradio-core/src/python/gnuradio/__init__.py b/gnuradio-core/src/python/gnuradio/__init__.py
index d55dac79d..266113b2b 100644
--- a/gnuradio-core/src/python/gnuradio/__init__.py
+++ b/gnuradio-core/src/python/gnuradio/__init__.py
@@ -10,3 +10,23 @@ GNU Radio is licensed under the GNU General Public License (GPL) version 3. All
# This file makes gnuradio a package
# The docstring will be associated with the top level of the package.
+
+import os
+
+# Check if the gnuradio package is installed or whether we're attempting to import it from
+# the build directory.
+path_ending = os.path.join('gnuradio-core', 'src', 'python', 'gnuradio', '__init__.py')
+path = os.path.abspath(__file__)
+if path.endswith('.pyc'):
+ path = path[:-1]
+
+if path.endswith(path_ending):
+ print("importing from build directory")
+ # We importing it from build directory.
+ build_path = os.path.join(path[:-len(path_ending)])
+
+ # Place these directory on __path__ so that it's contents are part of the gnuradio
+ # package.
+ __path__.append(os.path.join(build_path, 'gr-utils', 'src', 'python'))
+
+print(__path__)
diff --git a/gnuradio-core/src/python/gnuradio/gr/__init__.py b/gnuradio-core/src/python/gnuradio/gr/__init__.py
index c468437db..18f97b157 100644
--- a/gnuradio-core/src/python/gnuradio/gr/__init__.py
+++ b/gnuradio-core/src/python/gnuradio/gr/__init__.py
@@ -28,7 +28,17 @@ Core contents.
# This is the main GNU Radio python module.
# We pull the swig output and the other modules into the gnuradio.gr namespace
-from gnuradio_core import *
+# If gnuradio is installed then the swig output will be in this directory.
+# Otherwise it will reside in ../../../swig.
+
+import os
+
+try:
+ from gnuradio_core import *
+except ImportError:
+ dirname, filename = os.path.split(os.path.abspath(__file__))
+ __path__.append(os.path.join(dirname, "..", "..", "..", "lib", "swig"))
+ from gnuradio_core import *
from exceptions import *
from hier_block2 import *
from top_block import *