[GRASS-SVN] r62535 - in grass/trunk: gui/wxpython/docs/wxgui_sphinx lib/python/docs lib/python/exceptions lib/python/script scripts/g.extension scripts/r.grow

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 1 21:42:47 PDT 2014


Author: wenzeslaus
Date: 2014-11-01 21:42:47 -0700 (Sat, 01 Nov 2014)
New Revision: 62535

Modified:
   grass/trunk/gui/wxpython/docs/wxgui_sphinx/Makefile
   grass/trunk/lib/python/docs/Makefile
   grass/trunk/lib/python/exceptions/__init__.py
   grass/trunk/lib/python/script/core.py
   grass/trunk/scripts/g.extension/g.extension.py
   grass/trunk/scripts/r.grow/r.grow.py
Log:
sphinx: do not build API documentation for standalone program internals (removes messages from documentation build and empty sections from HTML)

Modified: grass/trunk/gui/wxpython/docs/wxgui_sphinx/Makefile
===================================================================
--- grass/trunk/gui/wxpython/docs/wxgui_sphinx/Makefile	2014-11-02 00:09:27 UTC (rev 62534)
+++ grass/trunk/gui/wxpython/docs/wxgui_sphinx/Makefile	2014-11-02 04:42:47 UTC (rev 62535)
@@ -79,8 +79,8 @@
 wxguiapidoc:
 	@echo $(SPHINXAPIDOC)
 	@echo $(SPHINXBUILD)
-	$(call run_grass,$(SPHINXAPIDOC) -T -f -o src/ ../../)
-	
+	$(call run_grass,$(SPHINXAPIDOC) -T -f -o src/ ../../ ../../*/g.gui.*.py)
+
 wxguihtml:
 	$(call run_grass,$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR_HTML))
 	@echo

Modified: grass/trunk/lib/python/docs/Makefile
===================================================================
--- grass/trunk/lib/python/docs/Makefile	2014-11-02 00:09:27 UTC (rev 62534)
+++ grass/trunk/lib/python/docs/Makefile	2014-11-02 04:42:47 UTC (rev 62535)
@@ -61,7 +61,7 @@
 	@echo "SPHINXBUILD: Using <$(SPHINXBUILD)>"
 	$(call run_grass,$(SPHINXAPIDOC) -T -f -o src/ ../imaging/)
 	$(call run_grass,$(SPHINXAPIDOC) -T -f -o src/ ../exceptions/)
-	$(call run_grass,$(SPHINXAPIDOC) -T -f -o src/ ../gunittest/)
+	$(call run_grass,$(SPHINXAPIDOC) -T -f -o src/ ../gunittest/ ../gunittest/multireport.py ../gunittest/multirunner.py ../gunittest/main.py)
 	$(call run_grass,$(SPHINXAPIDOC) -T -f -o src/ ../pydispatch/)
 	$(call run_grass,$(SPHINXAPIDOC) -T -f -o src/ ../pygrass/)
 	$(call run_grass,$(SPHINXAPIDOC) -T -f -o src/ ../script/)

Modified: grass/trunk/lib/python/exceptions/__init__.py
===================================================================
--- grass/trunk/lib/python/exceptions/__init__.py	2014-11-02 00:09:27 UTC (rev 62534)
+++ grass/trunk/lib/python/exceptions/__init__.py	2014-11-02 04:42:47 UTC (rev 62535)
@@ -53,6 +53,7 @@
 
 
 # TODO: we inherit from subprocess to be aligned with check_call but it is needed?
+# perhaps it would be better to inherit from Exception or from ScriptError
 class CalledModuleError(subprocess.CalledProcessError):
     """Raised when a called module ends with error (non-zero return code)
 
@@ -62,6 +63,7 @@
     :param error: errors provided by the module (stderr)
     """
     def __init__(self, module, code, returncode, errors=None):
+        # CalledProcessError has undocumented constructor
         super(CalledModuleError, self).__init__(returncode, module)
         msg = _("Module run %s %s ended with error") % (module, code)
         msg += _("\nProcess ended with non-zero return code %s") % returncode

Modified: grass/trunk/lib/python/script/core.py
===================================================================
--- grass/trunk/lib/python/script/core.py	2014-11-02 00:09:27 UTC (rev 62534)
+++ grass/trunk/lib/python/script/core.py	2014-11-02 04:42:47 UTC (rev 62535)
@@ -29,7 +29,7 @@
 import types as python_types
 
 from utils import KeyValue, parse_key_val, basename, encode
-from grass.exceptions import ScriptError
+from grass.exceptions import ScriptError, CalledModuleError
 
 # i18N
 import gettext
@@ -344,7 +344,7 @@
 
 def run_command(*args, **kwargs):
     """Passes all arguments to start_command(), then waits for the process to
-    complete, returning its exit code. Similar to subprocess.call(), but
+    complete, returning its exit code. Similar to subprocess.check_call(), but
     with the make_command() interface.
 
     :param list args: list of unnamed arguments (see start_command() for details)
@@ -353,7 +353,15 @@
     :return: exit code (0 for success)
     """
     ps = start_command(*args, **kwargs)
-    return ps.wait()
+    returncode = ps.wait()
+    if returncode:
+        # TODO: construction of the whole command is far from perfect
+        args = make_command(*args, **kwargs)
+        raise CalledModuleError(module=None, code=' '.join(args),
+                                returncode=returncode)
+    else:
+        # the else is just for compatibility, remove before 7.1
+        return 0
 
 
 def pipe_command(*args, **kwargs):
@@ -402,8 +410,15 @@
 
     :return: stdout
     """
-    ps = pipe_command(*args, **kwargs)
-    return ps.communicate()[0]
+    process = pipe_command(*args, **kwargs)
+    stdout, unused = process.communicate()
+    returncode = process.poll()
+    if returncode:
+        # TODO: construction of the whole command is far from perfect
+        args = make_command(*args, **kwargs)
+        raise CalledModuleError(module=None, code=' '.join(args),
+                                returncode=returncode)
+    return stdout
 
 
 def parse_command(*args, **kwargs):
@@ -458,10 +473,17 @@
     :return: return code
     """
     stdin = kwargs['stdin']
-    p = feed_command(*args, **kwargs)
-    p.stdin.write(stdin)
-    p.stdin.close()
-    return p.wait()
+    process = feed_command(*args, **kwargs)
+    process.communicate(stdin)
+    returncode = process.poll()
+    if returncode:
+        # TODO: construction of the whole command is far from perfect
+        args = make_command(*args, **kwargs)
+        raise CalledModuleError(module=None, code=' '.join(args),
+                                returncode=returncode)
+    else:
+        # the else is just for compatibility, remove before 7.1
+        return 0
 
 
 def exec_command(prog, flags="", overwrite=False, quiet=False, verbose=False,
@@ -1044,9 +1066,13 @@
     if element == 'raster' or element == 'rast':
         verbose(_('Element type should be "cell" and not "%s"') % element)
         element = 'cell'
-    s = read_command("g.findfile", flags='n', element=element, file=name,
-                     mapset=mapset)
-    return parse_key_val(s)
+    # g.findfile returns non-zero when file was not found
+    # se we ignore return code and just focus on stdout
+    process = start_command('g.findfile', flags='n',
+                            element=element, file=name, mapset=mapset,
+                            stdout=PIPE)
+    stdout = process.communicate()[0]
+    return parse_key_val(stdout)
 
 # interface to g.list
 

Modified: grass/trunk/scripts/g.extension/g.extension.py
===================================================================
--- grass/trunk/scripts/g.extension/g.extension.py	2014-11-02 00:09:27 UTC (rev 62534)
+++ grass/trunk/scripts/g.extension/g.extension.py	2014-11-02 04:42:47 UTC (rev 62535)
@@ -47,8 +47,16 @@
 #% key_desc: url
 #% description: SVN Addons repository URL
 #% answer: http://svn.osgeo.org/grass/grass-addons/grass7
+#% required: no
 #%end
 #%option
+#% key: srcdir
+#% type: string
+#% key_desc: directory
+#% description: Directory with source code
+#% required: no
+#%end
+#%option
 #% key: prefix
 #% type: string
 #% key_desc: path
@@ -724,11 +732,14 @@
     return 0
 
 # install extension on other plaforms
-def install_extension_other(name):
+def install_extension_other(name, src_dir=None):
     gisbase = os.getenv('GISBASE')
     classchar = name.split('.', 1)[0]
     moduleclass = expand_module_class_name(classchar)
-    url = options['svnurl'] + '/' + moduleclass + '/' + name
+    if not src_dir:
+        url = options['svnurl'] + '/' + moduleclass + '/' + name
+    else:
+        url = None
     
     grass.message(_("Fetching <%s> from GRASS-Addons SVN repository (be patient)...") % name)
 
@@ -738,9 +749,13 @@
     else:
         outdev = sys.stdout
 
-    if grass.call(['svn', 'checkout',
-                   url], stdout = outdev) != 0:
-        grass.fatal(_("GRASS Addons <%s> not found") % name)
+    if url:
+        grass.message(_("Fetching <%s> from GRASS-Addons SVN (be patient)...") % name)
+        if grass.call(['svn', 'checkout',
+                       url], stdout = outdev) != 0:
+            grass.fatal(_("GRASS Addons <%s> not found") % name)
+    else:
+        grass.message(_("Instaling <%s> from directory <%s>...") % (name, src_dir))
 
     dirs = { 'bin'     : os.path.join(TMPDIR, name, 'bin'),
              'docs'    : os.path.join(TMPDIR, name, 'docs'),
@@ -780,7 +795,10 @@
         sys.stderr.write(' '.join(installCmd) + '\n')
         return 0
 
-    os.chdir(os.path.join(TMPDIR, name))
+    if url:
+        os.chdir(os.path.join(TMPDIR, name))
+    else:
+        os.chdir(src_dir)
 
     grass.message(_("Compiling..."))
     if 0 != grass.call(makeCmd,
@@ -1026,6 +1044,17 @@
             options['prefix'] = os.path.join(os.environ['HOME'], '.grass%s' % version[0], 'addons')
         else:
             options['prefix'] = os.environ['GRASS_ADDON_BASE']
+
+    src_dir = options['srcdir']
+    if src_dir:
+        if sys.platform != "win32":
+            install_extension_other(options['extension'], src_dir)
+            return 0
+        else:
+            grass.fatal(_("Cannot compile and install from source code on"
+                          " MS Windows (TODO: this is not true for Python"
+                          " except for the fact that make is not available)."))
+
     if 'svn.osgeo.org/grass/grass-addons/grass7' in options['svnurl']:
         # use pregenerated modules XML file
         xmlurl = "http://grass.osgeo.org/addons/grass%s" % version[0]

Modified: grass/trunk/scripts/r.grow/r.grow.py
===================================================================
--- grass/trunk/scripts/r.grow/r.grow.py	2014-11-02 00:09:27 UTC (rev 62534)
+++ grass/trunk/scripts/r.grow/r.grow.py	2014-11-02 04:42:47 UTC (rev 62535)
@@ -102,7 +102,10 @@
 
     if metric == 'euclidean':
         metric = 'squared'
-        radius = radius * radius
+        if radius > 0:
+            radius = radius * radius
+        else:
+            radius = - (radius * radius)
 
     #check if input file exists
     if not grass.find_file(input)['file']:



More information about the grass-commit mailing list