[GRASS-SVN] r67626 - grass/branches/releasebranch_7_0/lib/python/pygrass

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 22 11:42:04 PST 2016


Author: martinl
Date: 2016-01-22 11:42:04 -0800 (Fri, 22 Jan 2016)
New Revision: 67626

Modified:
   grass/branches/releasebranch_7_0/lib/python/pygrass/utils.py
Log:
pygrass: sync get_path_lib() and set_path() with trunk (fixes compiling of some addons)
         (merge r66411, r67535, r67537, r67544, r67570 from trunk)



Modified: grass/branches/releasebranch_7_0/lib/python/pygrass/utils.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/pygrass/utils.py	2016-01-22 13:32:13 UTC (rev 67625)
+++ grass/branches/releasebranch_7_0/lib/python/pygrass/utils.py	2016-01-22 19:42:04 UTC (rev 67626)
@@ -263,7 +263,7 @@
         raise ValueError('Raster map does not exist.')
 
 
-def get_lib_path(modname, libname):
+def get_lib_path(modname, libname=None):
     """Return the path of the libname contained in the module.
 
     >>> get_lib_path(modname='r.modis', libname='libmodis')
@@ -273,24 +273,40 @@
 
     if isdir(join(getenv('GISBASE'), 'etc', modname)):
         path = join(os.getenv('GISBASE'), 'etc', modname)
+    elif getenv('GRASS_ADDON_BASE') and libname and \
+            isdir(join(getenv('GRASS_ADDON_BASE'), 'etc', modname, libname)):
+        path = join(getenv('GRASS_ADDON_BASE'), 'etc', modname, libname)
     elif getenv('GRASS_ADDON_BASE') and \
             isdir(join(getenv('GRASS_ADDON_BASE'), 'etc', modname)):
         path = join(getenv('GRASS_ADDON_BASE'), 'etc', modname)
     elif getenv('GRASS_ADDON_BASE') and \
             isdir(join(getenv('GRASS_ADDON_BASE'), modname, modname)):
         path = join(os.getenv('GRASS_ADDON_BASE'), modname, modname)
-    elif isdir(join('..', libname)):
+    elif libname and isdir(join('..', libname)): # used by g.extension compilation process
         path = join('..', libname)
+    elif isdir(join('..', 'etc', modname)):      # used by g.extension compilation process
+        path = join('..', 'etc', modname)
+    elif isdir(join('etc', modname)):            # used by g.extension compilation process
+        path = join('etc', modname)
     else:
         path = None
+    
     return path
 
 
-def set_path(modulename, dirname, path='.'):
+def set_path(modulename, dirname=None, path='.'):
+    """Set sys.path looking in the the local directory GRASS directories.
+
+    @param modulename
+    @param dirname
+    @param path used to run the code locally without compilation
+    """
     import sys
-    """Set sys.path looking in the the local directory GRASS directories."""
-    pathlib = os.path.join(path, dirname)
-    if os.path.exists(pathlib):
+    # TODO: why dirname is checked first - the logic should be revised
+    pathlib = None
+    if dirname:
+        pathlib = os.path.join(path, dirname)
+    if pathlib and os.path.exists(pathlib):
         # we are running the script from the script directory
         sys.path.append(os.path.abspath(pathlib))
     else:
@@ -298,7 +314,9 @@
         from grass.pygrass.utils import get_lib_path
         path = get_lib_path(modulename, dirname)
         if path is None:
-            raise ImportError("Not able to find the path %s directory." % path)
+            pathname = os.path.join(modulename, dirname) if dirname else modulename
+            raise ImportError("Not able to find the path '%s' directory "
+                              "(current dir '%s')." % (pathname, os.getcwd()))
         sys.path.append(path)
 
 



More information about the grass-commit mailing list