浏览代码

cleanup pygrass: change method of import, add newline at the end of files

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54882 15284696-431f-4ddb-bdfa-cd5b030d7da7
Luca Delucchi 12 年之前
父节点
当前提交
d3a6843693

+ 1 - 5
lib/python/pygrass/__init__.py

@@ -9,13 +9,9 @@ _libgis.G_gisinit('')
 import os as _os
 import sys as _sys
 
-_pygrasspath = _os.path.dirname(_os.path.realpath(__file__)).split(_os.sep)
-
-_sys.path.append(_os.path.join(_os.sep, *_pygrasspath[:-1]))
-
 import gis
 import raster
 import vector
 import modules
 import errors
-import functions
+import functions

+ 2 - 1
lib/python/pygrass/errors.py

@@ -7,6 +7,7 @@ Created on Wed Aug 15 17:33:27 2012
 
 from grass.script import warning
 
+
 class GrassError(Exception):
     def __init__(self, value):
         self.value = value
@@ -29,4 +30,4 @@ def must_be_open(method):
             return method(self, *args, **kargs)
         else:
             warning(_("The map is close!"))
-    return wrapper
+    return wrapper

+ 3 - 5
lib/python/pygrass/functions.py

@@ -11,8 +11,8 @@ import grass.lib.gis as libgis
 import grass.lib.raster as libraster
 from grass.script import core as grasscore
 
-from pygrass.errors import GrassError
-from pygrass.gis.region import Region
+from grass.pygrass.errors import GrassError
+from grass.pygrass.gis.region import Region
 
 
 def looking(obj, filter_string):
@@ -83,7 +83,6 @@ def clean_map_name(name):
 def coor2pixel((east, north), region):
     """Convert coordinates into a pixel row and col ::
 
-        >>> from pygrass.region import Region
         >>> reg = Region()
         >>> coor2pixel((reg.west, reg.north), reg)
         (0.0, 0.0)
@@ -97,7 +96,6 @@ def coor2pixel((east, north), region):
 def pixel2coor((col, row), region):
     """Convert row and col of a pixel into a coordinates ::
 
-        >>> from pygrass.region import Region
         >>> reg = Region()
         >>> pixel2coor((0, 0), reg) == (reg.north, reg.west)
         True
@@ -124,4 +122,4 @@ def get_raster_for_points(point, raster):
     if point.num_primitive_of('point') == 0:
         raise GrassError(_("Vector doesn't contain points"))
     values = [raster.get_value(poi.coords, reg) for poi in point.viter('point')]
-    return values
+    return values

+ 3 - 7
lib/python/pygrass/gis/__init__.py

@@ -21,8 +21,9 @@ from grass import script
 script.gisenv()
 
 import grass.lib.gis as libgis
-from pygrass.functions import getenv
-from pygrass.errors import GrassError
+from grass.pygrass.functions import getenv
+from grass.pygrass.errors import GrassError
+import region
 
 
 #write dec to check if user have permissions or not
@@ -279,8 +280,3 @@ class Mapset(object):
                 if pattern:
                     return fnmatch.filter(elist, pattern)
                 return elist
-
-
-if __name__ == "__main__":
-    import doctest
-    doctest.testmod(verbose=False)

+ 3 - 3
lib/python/pygrass/gis/region.py

@@ -8,7 +8,7 @@ import ctypes
 import grass.lib.gis as libgis
 import grass.script as grass
 
-from pygrass.errors import GrassError
+from grass.pygrass.errors import GrassError
 
 
 class Region(object):
@@ -224,7 +224,7 @@ class Region(object):
             raise GrassError("Cannot change region (WIND file).")
 
     def bbox(self):
-        from pygrass.vector.basic import Bbox
+        from grass.pygrass.vector.basic import Bbox
         return Bbox(north=self.north, south=self.south,
                     east=self.east, west=self.west,
-                    top=self.top, bottom=self.bottom)
+                    top=self.top, bottom=self.bottom)

+ 3 - 3
lib/python/pygrass/modules/__init__.py

@@ -13,14 +13,14 @@ import re
 try:
     from collections import OrderedDict
 except ImportError:
-    from pygrass.orderdict import OrderedDict
+    from grass.pygrass.orderdict import OrderedDict
 
 from itertools import izip_longest
 from xml.etree.ElementTree import fromstring
 
 import grass
 
-from pygrass.errors import GrassError
+from grass.pygrass.errors import GrassError
 
 #
 # this dictionary is used to extract the value of interest from the xml
@@ -662,4 +662,4 @@ postscript = MetaModule('ps')
 raster = MetaModule('r')
 raster3D = MetaModule('r3')
 temporal = MetaModule('t')
-vector = MetaModule('v')
+vector = MetaModule('v')

+ 1 - 1
lib/python/pygrass/orderdict.py

@@ -256,4 +256,4 @@ class OrderedDict(dict):
 
     def viewitems(self):
         "od.viewitems() -> a set-like object providing a view on od's items"
-        return ItemsView(self)
+        return ItemsView(self)

+ 4 - 9
lib/python/pygrass/raster/__init__.py

@@ -22,9 +22,9 @@ import grass.lib.rowio as librowio
 #
 # import pygrass modules
 #
-from pygrass.errors import OpenError, must_be_open
-from pygrass.gis.region import Region
-from pygrass import functions
+from grass.pygrass.errors import OpenError, must_be_open
+from grass.pygrass.gis.region import Region
+from grass.pygrass import functions
 
 #
 # import raster classes
@@ -462,7 +462,7 @@ class RasterNumpy(np.memmap, RasterAbstractBase):
     * Overrides the open and close methods
     * Be aware of the 2Gig file size limit
 
-    >>> import pygrass
+    >>> import grass.pygrass as pygrass
     >>> elev = pygrass.raster.RasterNumpy('elevation')
     >>> elev.open()
     >>> elev[:5, :3]
@@ -687,8 +687,3 @@ def random_map(mapname, mtype, overwrite=True, factor=100):
         random_map.put_row(row_buf)
     random_map.close()
     return random_map
-
-
-if __name__ == "__main__":
-    import doctest
-    doctest.testmod()

+ 6 - 4
lib/python/pygrass/raster/abstract.py

@@ -8,6 +8,8 @@ Created on Fri Aug 17 16:05:25 2012
 
 import ctypes
 
+from numpy import isnan
+
 #
 # import GRASS modules
 #
@@ -21,9 +23,9 @@ import grass.lib.raster as libraster
 #
 # import pygrass modules
 #
-from pygrass import functions
-from pygrass.gis.region import Region
-from pygrass.errors import must_be_open
+from grass.pygrass import functions
+from grass.pygrass.gis.region import Region
+from grass.pygrass.errors import must_be_open
 
 #
 # import raster classes
@@ -368,4 +370,4 @@ class RasterAbstractBase(object):
     @must_be_open
     def set_cat(self, label, min_cat, max_cat=None, index=None):
         """Set or update a category"""
-        self.cats.set_cat(index, (label, min_cat, max_cat))
+        self.cats.set_cat(index, (label, min_cat, max_cat))

+ 1 - 1
lib/python/pygrass/raster/buffer.py

@@ -39,4 +39,4 @@ class Buffer(np.ndarray):
             # there is not support for boolean maps, so convert into integer
             out_arr = out_arr.astype(np.int32)
         out_arr.p = out_arr.ctypes.data_as(out_arr.pointer_type)
-        return np.ndarray.__array_wrap__(self, out_arr, context)
+        return np.ndarray.__array_wrap__(self, out_arr, context)

+ 3 - 3
lib/python/pygrass/raster/category.py

@@ -9,7 +9,7 @@ from operator import itemgetter
 
 import grass.lib.raster as libraster
 
-from pygrass.errors import GrassError
+from grass.pygrass.errors import GrassError
 
 from raster_type import TYPE as RTYPE
 
@@ -53,7 +53,7 @@ class Category(list):
 
     >>> import grass.lib.raster as libraster
     >>> import ctypes
-    >>> import pygrass
+    >>> import grass.pygrass as pygrass
     >>> land = pygrass.raster.RasterRow('landcover_1m')
     >>> cats = pygrass.raster.Category()
     >>> cats.read(land) # or with cats.read(land.name, land.mapset, land.mtype)
@@ -345,4 +345,4 @@ class Category(list):
         libraster.Rast_sort_cats(ctypes.byref(self._cats))
 
     def labels(self):
-        return map(itemgetter(0), self)
+        return map(itemgetter(0), self)

+ 2 - 2
lib/python/pygrass/raster/history.py

@@ -15,7 +15,7 @@ class History(object):
 
     ::
 
-        >>> import pygrass
+        >>> import grass.pygrass as pygrass
         >>> hist = pygrass.raster.History()
         >>> hist.read('aspect')
         >>> hist.creator
@@ -233,4 +233,4 @@ class History(object):
         """Rast_short_history"""
         libraster.Rast_short_history(ctypes.c_char_p(name),
                                      ctypes.c_char_p(maptype),
-                                     ctypes.byref(self.hist))
+                                     ctypes.byref(self.hist))

+ 1 - 1
lib/python/pygrass/raster/raster_type.py

@@ -25,4 +25,4 @@ TYPE = {'CELL':  {'grass type':  libraster.CELL_TYPE,
         'DCELL': {'grass type':  libraster.DCELL_TYPE,
                   'grass def':   libraster.DCELL,
                   'numpy':       np.float64,
-                  'ctypes':      ctypes.c_double}}
+                  'ctypes':      ctypes.c_double}}

+ 2 - 2
lib/python/pygrass/raster/rowio.py

@@ -9,7 +9,7 @@ import ctypes
 import grass.lib.rowio as librowio
 import grass.lib.raster as librast
 
-from pygrass.errors import GrassError
+from grass.pygrass.errors import GrassError
 from raster_type import TYPE as RTYPE
 
 
@@ -75,4 +75,4 @@ class RowIO(object):
     def get(self, row_index, buf):
         rowio_buf = librowio.Rowio_get(ctypes.byref(self.crowio), row_index)
         ctypes.memmove(buf.p, rowio_buf, self.row_size)
-        return buf
+        return buf

+ 1 - 1
lib/python/pygrass/raster/segment.py

@@ -126,4 +126,4 @@ class Segment(object):
         Releases the allocated memory associated with the segment file seg.
         Note: Does not close the file. Does not flush the data which may be
         pending from previous segment_put() calls."""
-        libseg.segment_release(ctypes.byref(self.cseg))
+        libseg.segment_release(ctypes.byref(self.cseg))

+ 3 - 3
lib/python/pygrass/vector/__init__.py

@@ -12,7 +12,7 @@ from vector_type import VTYPE, GV_TYPE
 #
 # import pygrass modules
 #
-from pygrass.errors import GrassError, must_be_open
+from grass.pygrass.errors import GrassError, must_be_open
 
 import geometry
 from abstract import Info
@@ -52,7 +52,7 @@ _GEOOBJ = {"areas": geometry.Area,
 class Vector(Info):
     """ ::
 
-        >>> from pygrass.vector import Vector
+        >>> from grass.pygrass.vector import Vector
         >>> municip = Vector('boundary_municp_sqlite')
         >>> municip.is_open()
         False
@@ -151,7 +151,7 @@ class Vector(Info):
             >>> new.open('w', tab_name='newvect', tab_cols=cols)
 
         import a geometry feature ::
-            >>> from pygrass.vector.geometry import Point
+            >>> from grass.pygrass.vector.geometry import Point
 
         create two points ::
 

+ 3 - 3
lib/python/pygrass/vector/abstract.py

@@ -9,8 +9,8 @@ import datetime
 import grass.lib.vector as libvect
 from vector_type import MAPTYPE
 
-from pygrass import functions
-from pygrass.errors import GrassError, OpenError, must_be_open
+from grass.pygrass import functions
+from grass.pygrass.errors import GrassError, OpenError, must_be_open
 from table import DBlinks, Link
 
 #=============================================
@@ -354,4 +354,4 @@ class Info(object):
         if libvect.Vect_build(self.c_mapinfo) != 1:
             str_err = 'Error when trying build topology with Vect_build'
             raise GrassError(str_err)
-        libvect.Vect_close(self.c_mapinfo)
+        libvect.Vect_close(self.c_mapinfo)

+ 1 - 1
lib/python/pygrass/vector/basic.py

@@ -456,4 +456,4 @@ class CatsList(object):
     def __contains__(self, cat):
         """Check if category number is in list.
         int 	Vect_cat_in_cat_list (int cat, const struct cat_list *list)"""
-        return bool(libvect.Vect_cat_in_cat_list(cat, self.c_cat_list))
+        return bool(libvect.Vect_cat_in_cat_list(cat, self.c_cat_list))

+ 2 - 2
lib/python/pygrass/vector/geometry.py

@@ -13,7 +13,7 @@ import numpy as np
 import grass.lib.gis as libgis
 import grass.lib.vector as libvect
 
-from pygrass.errors import GrassError
+from grass.pygrass.errors import GrassError
 
 from basic import Ilist, Bbox, Cats
 import sql
@@ -1354,4 +1354,4 @@ class Area(Geo):
 
         """
         border = self.points()
-        return libvect.Vect_area_perimeter(border.c_points)
+        return libvect.Vect_area_perimeter(border.c_points)

+ 1 - 1
lib/python/pygrass/vector/sql.py

@@ -48,4 +48,4 @@ UPDATE_COL_WHERE = "UPDATE {tname} SET {new_col} = {old_col} WHERE {condition};"
 
 
 # GET INFO
-PRAGMA = "PRAGMA table_info({tname});"
+PRAGMA = "PRAGMA table_info({tname});"

+ 6 - 6
lib/python/pygrass/vector/table.py

@@ -12,10 +12,10 @@ import ctypes
 try:
     from collections import OrderedDict
 except:
-    from pygrass.orderdict import OrderedDict
+    from grass.pygrass.orderdict import OrderedDict
 
 import grass.lib.vector as libvect
-from pygrass.gis import Mapset
+from grass.pygrass.gis import Mapset
 
 import sql
 
@@ -665,7 +665,7 @@ class Link(object):
 class DBlinks(object):
     """Interface containing link to the table DB. ::
 
-        >>> from pygrass.vector import VectorTopo
+        >>> from grass.pygrass.vector import VectorTopo
         >>> municip = VectorTopo('boundary_municp_sqlite')
         >>> municip.open()
         >>> dblinks = DBlinks(municip.c_mapinfo)
@@ -722,7 +722,7 @@ class DBlinks(object):
     def add(self, link):
         """Add a new link. ::
 
-            >>> from pygrass.vector import VectorTopo
+            >>> from grass.pygrass.vector import VectorTopo
             >>> municip = VectorTopo('boundary_municp_sqlite')
             >>> municip.open()
             >>> dblinks = DBlinks(municip.c_mapinfo)
@@ -744,7 +744,7 @@ class DBlinks(object):
     def remove(self, key):
         """Remove a link. ::
 
-            >>> from pygrass.vector import VectorTopo
+            >>> from grass.pygrass.vector import VectorTopo
             >>> municip = VectorTopo('boundary_municp_sqlite')
             >>> municip.open()
             >>> dblinks = DBlinks(municip.c_mapinfo)
@@ -871,4 +871,4 @@ class Table(object):
         cur = self.conn.cursor()
         vals = list(values)
         vals.append(key)
-        return cur.execute(self.columns.update_str, vals)
+        return cur.execute(self.columns.update_str, vals)

+ 1 - 1
lib/python/pygrass/vector/vector_type.py

@@ -29,4 +29,4 @@ GV_TYPE = {libvect.GV_POINT:    {'label': 'point',    'obj': geo.Point},
            libvect.GV_FACE:     {'label': 'face',     'obj': None},
            libvect.GV_KERNEL:   {'label': 'kernel',   'obj': None},
            libvect.GV_AREA:     {'label': 'area',     'obj': geo.Area},
-           libvect.GV_VOLUME:   {'label': 'volume',   'obj': None}, }
+           libvect.GV_VOLUME:   {'label': 'volume',   'obj': None}, }