[GRASS-SVN] r65190 - grass/trunk/lib/python/pygrass/modules/interface

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 4 06:48:35 PDT 2015


Author: zarch
Date: 2015-05-04 06:48:35 -0700 (Mon, 04 May 2015)
New Revision: 65190

Added:
   grass/trunk/lib/python/pygrass/modules/interface/docstring.py
Modified:
   grass/trunk/lib/python/pygrass/modules/interface/Makefile
   grass/trunk/lib/python/pygrass/modules/interface/flag.py
   grass/trunk/lib/python/pygrass/modules/interface/module.py
   grass/trunk/lib/python/pygrass/modules/interface/parameter.py
   grass/trunk/lib/python/pygrass/modules/interface/typedict.py
Log:
pygrass: Remove import from utils, because utils require ctypes

Modified: grass/trunk/lib/python/pygrass/modules/interface/Makefile
===================================================================
--- grass/trunk/lib/python/pygrass/modules/interface/Makefile	2015-05-04 09:51:57 UTC (rev 65189)
+++ grass/trunk/lib/python/pygrass/modules/interface/Makefile	2015-05-04 13:48:35 UTC (rev 65190)
@@ -9,7 +9,7 @@
 PGDIR = $(GDIR)/pygrass
 DSTDIR= $(PGDIR)/modules/interface
 
-MODULES = read typedict flag parameter module
+MODULES = docstring read typedict flag parameter module
 
 PYFILES := $(patsubst %,$(DSTDIR)/%.py,$(MODULES) __init__)
 PYCFILES := $(patsubst %,$(DSTDIR)/%.pyc,$(MODULES) __init__)
@@ -29,4 +29,4 @@
 	$(INSTALL_DATA) $< $@
 
 #doxygen:
-DOXNAME = pythonpygrass
\ No newline at end of file
+DOXNAME = pythonpygrass

Added: grass/trunk/lib/python/pygrass/modules/interface/docstring.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/interface/docstring.py	                        (rev 0)
+++ grass/trunk/lib/python/pygrass/modules/interface/docstring.py	2015-05-04 13:48:35 UTC (rev 65190)
@@ -0,0 +1,55 @@
+# -*- coding: utf-8 -*-
+
+
+def docstring_property(class_doc):
+    """Property attribute for docstrings.
+    Took from: https://gist.github.com/bfroehle/4041015
+
+    >>> class A(object):
+    ...     '''Main docstring'''
+    ...     def __init__(self, x):
+    ...         self.x = x
+    ...     @docstring_property(__doc__)
+    ...     def __doc__(self):
+    ...         return "My value of x is %s." % self.x
+
+    >>> A.__doc__
+    'Main docstring'
+
+    >>> a = A(10)
+    >>> a.__doc__
+    'My value of x is 10.'
+    """
+    def wrapper(fget):
+        return DocstringProperty(class_doc, fget)
+    return wrapper
+
+
+class DocstringProperty(object):
+    """Property for the `__doc__` attribute.
+
+    Different than `property` in the following two ways:
+
+    * When the attribute is accessed from the main class, it returns the value
+      of `class_doc`, *not* the property itself. This is necessary so Sphinx
+      and other documentation tools can access the class docstring.
+
+    * Only supports getting the attribute; setting and deleting raise an
+      `AttributeError`.
+    """
+
+    def __init__(self, class_doc, fget):
+        self.class_doc = class_doc
+        self.fget = fget
+
+    def __get__(self, obj, type=None):
+        if obj is None:
+            return self.class_doc
+        else:
+            return self.fget(obj)
+
+    def __set__(self, obj, value):
+        raise AttributeError("can't set attribute")
+
+    def __delete__(self, obj):
+        raise AttributeError("can't delete attribute")

Modified: grass/trunk/lib/python/pygrass/modules/interface/flag.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/interface/flag.py	2015-05-04 09:51:57 UTC (rev 65189)
+++ grass/trunk/lib/python/pygrass/modules/interface/flag.py	2015-05-04 13:48:35 UTC (rev 65190)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 from __future__ import (nested_scopes, generators, division, absolute_import,
                         with_statement, print_function, unicode_literals)
-from grass.pygrass.utils import docstring_property
+from grass.pygrass.modules.interface.docstring import docstring_property
 from grass.pygrass.modules.interface import read
 
 

Modified: grass/trunk/lib/python/pygrass/modules/interface/module.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/interface/module.py	2015-05-04 09:51:57 UTC (rev 65189)
+++ grass/trunk/lib/python/pygrass/modules/interface/module.py	2015-05-04 13:48:35 UTC (rev 65190)
@@ -15,7 +15,7 @@
 from grass.exceptions import CalledModuleError
 from grass.script.core import Popen, PIPE
 from grass.pygrass.errors import GrassError, ParameterError
-from grass.pygrass.utils import docstring_property
+from grass.pygrass.modules.interface.docstring import docstring_property
 from grass.pygrass.modules.interface.parameter import Parameter
 from grass.pygrass.modules.interface.flag import Flag
 from grass.pygrass.modules.interface.typedict import TypeDict

Modified: grass/trunk/lib/python/pygrass/modules/interface/parameter.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/interface/parameter.py	2015-05-04 09:51:57 UTC (rev 65189)
+++ grass/trunk/lib/python/pygrass/modules/interface/parameter.py	2015-05-04 13:48:35 UTC (rev 65190)
@@ -8,7 +8,7 @@
                         with_statement, print_function, unicode_literals)
 import re
 
-from grass.pygrass.utils import docstring_property
+from grass.pygrass.modules.interface.docstring import docstring_property
 from grass.pygrass.modules.interface.read import GETTYPE, element2dict, DOC
 
 

Modified: grass/trunk/lib/python/pygrass/modules/interface/typedict.py
===================================================================
--- grass/trunk/lib/python/pygrass/modules/interface/typedict.py	2015-05-04 09:51:57 UTC (rev 65189)
+++ grass/trunk/lib/python/pygrass/modules/interface/typedict.py	2015-05-04 13:48:35 UTC (rev 65190)
@@ -12,7 +12,7 @@
 except ImportError:
     from grass.pygrass.orderdict import OrderedDict
 
-from grass.pygrass.utils import docstring_property
+from grass.pygrass.modules.interface.docstring import docstring_property
 
 
 class TypeDict(OrderedDict):



More information about the grass-commit mailing list