[GRASS-SVN] r65345 - grass/trunk/lib/python/script
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun May 31 19:19:04 PDT 2015
Author: wenzeslaus
Date: 2015-05-31 19:19:04 -0700 (Sun, 31 May 2015)
New Revision: 65345
Added:
grass/trunk/lib/python/script/setup.py
Removed:
grass/trunk/lib/python/script/setup.py.sed
Modified:
grass/trunk/lib/python/script/Makefile
Log:
pythonlib: use .py extension for python files
The tmp file is now directly in the source directory and deleted with make clean.
This should enable autogenerating documentation from setup.py even when GRASS was not compiled. It also contributes to better editing.
Modified: grass/trunk/lib/python/script/Makefile
===================================================================
--- grass/trunk/lib/python/script/Makefile 2015-05-31 18:36:44 UTC (rev 65344)
+++ grass/trunk/lib/python/script/Makefile 2015-06-01 02:19:04 UTC (rev 65345)
@@ -18,10 +18,12 @@
$(DSTDIR)/%: % | $(DSTDIR)
$(INSTALL_DATA) $< $@
-$(DSTDIR)/setup.py: $(OBJDIR)/setup.py | $(DSTDIR)
+EXTRA_CLEAN_FILES = setup.tmp.py
+
+$(DSTDIR)/setup.py: setup.tmp.py | $(DSTDIR)
$(INSTALL_DATA) $< $@
-$(OBJDIR)/setup.py: setup.py.sed | $(OBJDIR)
+setup.tmp.py: setup.py
sed \
-e 's#@LD_LIBRARY_PATH_VAR@#$(LD_LIBRARY_PATH_VAR)#' \
$< > $@
Copied: grass/trunk/lib/python/script/setup.py (from rev 65235, grass/trunk/lib/python/script/setup.py.sed)
===================================================================
--- grass/trunk/lib/python/script/setup.py (rev 0)
+++ grass/trunk/lib/python/script/setup.py 2015-06-01 02:19:04 UTC (rev 65345)
@@ -0,0 +1,77 @@
+"""!@package grass.script.setup
+
+ at brief GRASS Python scripting module (setup)
+
+Setup functions to be used in Python scripts.
+
+Usage:
+
+ at code
+from grass.script import setup as grass
+
+grass.init()
+...
+ at endcode
+
+(C) 2010-2012 by the GRASS Development Team
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+ at author Martin Landa <landa.martin gmail.com>
+"""
+
+import os
+import sys
+import tempfile as tmpfile
+
+
+def write_gisrc(dbase, location, mapset):
+ """Write the gisrc file and return the gisrc path."""
+ fd, gisrc = tmpfile.mkstemp()
+ os.write(fd, "GISDBASE: %s\n" % dbase)
+ os.write(fd, "LOCATION_NAME: %s\n" % location)
+ os.write(fd, "MAPSET: %s\n" % mapset)
+ os.close(fd)
+ return gisrc
+
+
+def init(gisbase, dbase='', location='demolocation', mapset='PERMANENT'):
+ """!Initialize system variables to run scripts without starting
+ GRASS explicitly.
+
+ User is resposible to delete gisrc file.
+
+ @param gisbase path to GRASS installation
+ @param dbase path to GRASS database (default: '')
+ @param location location name (default: 'demolocation')
+ @param mapset mapset within given location (default: 'PERMANENT')
+ @return path to gisrc file
+ """
+ # define PATH
+ os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'bin')
+ os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'scripts')
+ if sys.platform.startswith('win'): # added for winGRASS
+ os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'extrabin')
+
+ # define LD_LIBRARY_PATH
+ if '@LD_LIBRARY_PATH_VAR@' not in os.environ:
+ os.environ['@LD_LIBRARY_PATH_VAR@'] = ''
+ os.environ['@LD_LIBRARY_PATH_VAR@'] += os.pathsep + os.path.join(gisbase, 'lib')
+
+ os.environ['GIS_LOCK'] = str(os.getpid())
+
+ # Set PYTHONPATH to find GRASS Python modules
+ path = os.getenv('PYTHONPATH')
+ etcpy = os.path.join(gisbase, 'etc', 'python')
+ if path:
+ path = etcpy + os.pathsep + path
+ else:
+ path = etcpy
+ os.environ['PYTHONPATH'] = path
+
+ if not dbase:
+ dbase = gisbase
+
+ os.environ['GISRC'] = write_gisrc(dbase, location, mapset)
+ return os.environ['GISRC']
Deleted: grass/trunk/lib/python/script/setup.py.sed
===================================================================
--- grass/trunk/lib/python/script/setup.py.sed 2015-05-31 18:36:44 UTC (rev 65344)
+++ grass/trunk/lib/python/script/setup.py.sed 2015-06-01 02:19:04 UTC (rev 65345)
@@ -1,77 +0,0 @@
-"""!@package grass.script.setup
-
- at brief GRASS Python scripting module (setup)
-
-Setup functions to be used in Python scripts.
-
-Usage:
-
- at code
-from grass.script import setup as grass
-
-grass.init()
-...
- at endcode
-
-(C) 2010-2012 by the GRASS Development Team
-This program is free software under the GNU General Public
-License (>=v2). Read the file COPYING that comes with GRASS
-for details.
-
- at author Martin Landa <landa.martin gmail.com>
-"""
-
-import os
-import sys
-import tempfile as tmpfile
-
-
-def write_gisrc(dbase, location, mapset):
- """Write the gisrc file and return the gisrc path."""
- fd, gisrc = tmpfile.mkstemp()
- os.write(fd, "GISDBASE: %s\n" % dbase)
- os.write(fd, "LOCATION_NAME: %s\n" % location)
- os.write(fd, "MAPSET: %s\n" % mapset)
- os.close(fd)
- return gisrc
-
-
-def init(gisbase, dbase='', location='demolocation', mapset='PERMANENT'):
- """!Initialize system variables to run scripts without starting
- GRASS explicitly.
-
- User is resposible to delete gisrc file.
-
- @param gisbase path to GRASS installation
- @param dbase path to GRASS database (default: '')
- @param location location name (default: 'demolocation')
- @param mapset mapset within given location (default: 'PERMANENT')
- @return path to gisrc file
- """
- # define PATH
- os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'bin')
- os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'scripts')
- if sys.platform.startswith('win'): # added for winGRASS
- os.environ['PATH'] += os.pathsep + os.path.join(gisbase, 'extrabin')
-
- # define LD_LIBRARY_PATH
- if '@LD_LIBRARY_PATH_VAR@' not in os.environ:
- os.environ['@LD_LIBRARY_PATH_VAR@'] = ''
- os.environ['@LD_LIBRARY_PATH_VAR@'] += os.pathsep + os.path.join(gisbase, 'lib')
-
- os.environ['GIS_LOCK'] = str(os.getpid())
-
- # Set PYTHONPATH to find GRASS Python modules
- path = os.getenv('PYTHONPATH')
- etcpy = os.path.join(gisbase, 'etc', 'python')
- if path:
- path = etcpy + os.pathsep + path
- else:
- path = etcpy
- os.environ['PYTHONPATH'] = path
-
- if not dbase:
- dbase = gisbase
-
- os.environ['GISRC'] = write_gisrc(dbase, location, mapset)
- return os.environ['GISRC']
More information about the grass-commit
mailing list