[GRASS-SVN] r67535 - grass/trunk/lib/python/pygrass
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jan 10 03:11:03 PST 2016
Author: martinl
Date: 2016-01-10 03:11:03 -0800 (Sun, 10 Jan 2016)
New Revision: 67535
Modified:
grass/trunk/lib/python/pygrass/utils.py
Log:
pygrass: change dirname in set_path() to optional - this functions needs major revision
Modified: grass/trunk/lib/python/pygrass/utils.py
===================================================================
--- grass/trunk/lib/python/pygrass/utils.py 2016-01-10 10:30:46 UTC (rev 67534)
+++ grass/trunk/lib/python/pygrass/utils.py 2016-01-10 11:11:03 UTC (rev 67535)
@@ -283,7 +283,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.
"""
from os.path import isdir, join
@@ -291,7 +291,7 @@
if isdir(join(getenv('GISBASE'), 'etc', modname)):
path = join(os.getenv('GISBASE'), 'etc', modname)
- elif getenv('GRASS_ADDON_BASE') and \
+ 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 \
@@ -300,18 +300,23 @@
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)):
path = join('..', libname)
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."""
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
+ # TODO probably also 'path' should be also removed - it's used only by
+ # compilation process for addons (see r.green for details)
+ 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:
More information about the grass-commit
mailing list