Browse Source

use lazy imports for the temporal package

This avoids ctypes-related issues during compilation (see https://trac.osgeo.org/grass/ticket/3257).

Using beginning of main function if possible.
If not adding to the if __name__... global part with a note
about imports being at the end of the file.
Adding pygrass imports if used (even modules import ctypes through __init__.py).


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@70357 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 8 years ago
parent
commit
cdaad7e9dc
49 changed files with 151 additions and 65 deletions
  1. 6 4
      scripts/v.what.strds/v.what.strds.py
  2. 2 1
      temporal/t.create/t.create.py
  3. 2 1
      temporal/t.info/t.info.py
  4. 3 1
      temporal/t.list/t.list.py
  5. 3 1
      temporal/t.merge/t.merge.py
  6. 5 1
      temporal/t.rast.accdetect/t.rast.accdetect.py
  7. 4 2
      temporal/t.rast.accumulate/t.rast.accumulate.py
  8. 3 1
      temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py
  9. 3 1
      temporal/t.rast.aggregate/t.rast.aggregate.py
  10. 4 1
      temporal/t.rast.algebra/t.rast.algebra.py
  11. 2 1
      temporal/t.rast.colors/t.rast.colors.py
  12. 3 2
      temporal/t.rast.contour/t.rast.contour.py
  13. 2 1
      temporal/t.rast.export/t.rast.export.py
  14. 3 1
      temporal/t.rast.extract/t.rast.extract.py
  15. 3 3
      temporal/t.rast.gapfill/t.rast.gapfill.py
  16. 2 1
      temporal/t.rast.import/t.rast.import.py
  17. 3 1
      temporal/t.rast.list/t.rast.list.py
  18. 3 1
      temporal/t.rast.mapcalc/t.rast.mapcalc.py
  19. 3 2
      temporal/t.rast.neighbors/t.rast.neighbors.py
  20. 2 1
      temporal/t.rast.out.vtk/t.rast.out.vtk.py
  21. 2 1
      temporal/t.rast.series/t.rast.series.py
  22. 2 1
      temporal/t.rast.to.rast3/t.rast.to.rast3.py
  23. 3 2
      temporal/t.rast.to.vect/t.rast.to.vect.py
  24. 3 1
      temporal/t.rast.univar/t.rast.univar.py
  25. 3 2
      temporal/t.rast.what/t.rast.what.py
  26. 4 1
      temporal/t.rast3d.algebra/t.rast3d.algebra.py
  27. 3 1
      temporal/t.rast3d.extract/t.rast3d.extract.py
  28. 3 1
      temporal/t.rast3d.list/t.rast3d.list.py
  29. 3 1
      temporal/t.rast3d.mapcalc/t.rast3d.mapcalc.py
  30. 3 1
      temporal/t.rast3d.univar/t.rast3d.univar.py
  31. 4 2
      temporal/t.register/t.register.py
  32. 8 4
      temporal/t.remove/t.remove.py
  33. 2 1
      temporal/t.rename/t.rename.py
  34. 3 1
      temporal/t.sample/t.sample.py
  35. 2 1
      temporal/t.select/t.select.py
  36. 3 1
      temporal/t.shift/t.shift.py
  37. 3 1
      temporal/t.snap/t.snap.py
  38. 3 1
      temporal/t.support/t.support.py
  39. 3 1
      temporal/t.topology/t.topology.py
  40. 7 3
      temporal/t.unregister/t.unregister.py
  41. 3 1
      temporal/t.vect.algebra/t.vect.algebra.py
  42. 3 1
      temporal/t.vect.db.select/t.vect.db.select.py
  43. 2 1
      temporal/t.vect.export/t.vect.export.py
  44. 3 1
      temporal/t.vect.extract/t.vect.extract.py
  45. 2 1
      temporal/t.vect.import/t.vect.import.py
  46. 3 1
      temporal/t.vect.list/t.vect.list.py
  47. 2 1
      temporal/t.vect.observe.strds/t.vect.observe.strds.py
  48. 3 1
      temporal/t.vect.univar/t.vect.univar.py
  49. 2 1
      temporal/t.vect.what.strds/t.vect.what.strds.py

+ 6 - 4
scripts/v.what.strds/v.what.strds.py

@@ -50,10 +50,6 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
-from grass.pygrass.utils import copy as gcopy
-from grass.pygrass.messages import Messenger
-from grass.pygrass.vector import Vector
 from grass.exceptions import CalledModuleError
 
 ############################################################################
@@ -95,6 +91,12 @@ class Sample(object):
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
+    from grass.pygrass.utils import copy as gcopy
+    from grass.pygrass.messages import Messenger
+    from grass.pygrass.vector import Vector
+    
     # Get the options
     input = options["input"]
     output = options["output"]

+ 2 - 1
temporal/t.create/t.create.py

@@ -59,12 +59,13 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     name = options["output"]

+ 2 - 1
temporal/t.info/t.info.py

@@ -50,12 +50,13 @@
 from __future__ import print_function
 
 import grass.script as grass
-import grass.temporal as tgis
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     name = options["input"]
     type_ = options["type"]

+ 3 - 1
temporal/t.list/t.list.py

@@ -80,15 +80,17 @@
 #% description: Print the column names as first row
 #% guisection: Formatting
 #%end
+
 from __future__ import print_function
 import grass.script as gscript
-import grass.temporal as tgis
 import sys
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     type = options["type"]

+ 3 - 1
temporal/t.merge/t.merge.py

@@ -33,13 +33,15 @@
 #% guisection: Required
 #%end
 
-import grass.temporal as tgis
 import grass.script as grass
 
+
 ############################################################################
 grass.set_raise_on_error(True)
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     inputs = options["inputs"]

+ 5 - 1
temporal/t.rast.accdetect/t.rast.accdetect.py

@@ -130,7 +130,9 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
+
+# lazy imports at the end of the file
 
 
 ############################################################################
@@ -585,4 +587,6 @@ def compute_occurrence(occurrence_maps, input_strds, input_maps, start, base,
 
 if __name__ == "__main__":
     options, flags = grass.parser()
+    # lazy imports
+    import grass.temporal as tgis
     main()

+ 4 - 2
temporal/t.rast.accumulate/t.rast.accumulate.py

@@ -149,13 +149,15 @@
 from __future__ import print_function
 
 import grass.script as grass
-import grass.temporal as tgis
-from grass.pygrass.modules import Module
 from copy import copy
 
 ############################################################################
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
+    from grass.pygrass.modules import Module
+
     # Get the options
     input = options["input"]
     output = options["output"]

+ 3 - 1
temporal/t.rast.aggregate.ds/t.rast.aggregate.ds.py

@@ -98,12 +98,14 @@
 #%end
 
 import grass.script as gcore
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 3 - 1
temporal/t.rast.aggregate/t.rast.aggregate.py

@@ -106,11 +106,13 @@
 #%end
 
 import grass.script as gcore
-import grass.temporal as tgis
+
 
 ############################################################################
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 4 - 1
temporal/t.rast.algebra/t.rast.algebra.py

@@ -69,10 +69,13 @@
 #%end
 
 import grass.script
-import grass.temporal as tgis
 import sys
 
+
 def main():
+    # lazy imports
+    import grass.temporal as tgis
+
     expression = options['expression']
     basename = options['basename']
     nprocs = options["nprocs"]

+ 2 - 1
temporal/t.rast.colors/t.rast.colors.py

@@ -97,13 +97,14 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
 from grass.exceptions import CalledModuleError
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 3 - 2
temporal/t.rast.contour/t.rast.contour.py

@@ -114,14 +114,15 @@
 import sys
 import copy
 import grass.script as gscript
-import grass.temporal as tgis
-import grass.pygrass.modules as pymod
 from grass.exceptions import FatalError
 
 
 ############################################################################
 
 def main(options, flags):
+    # lazy imports
+    import grass.temporal as tgis
+    import grass.pygrass.modules as pymod
 
     # Get the options
     input = options["input"]

+ 2 - 1
temporal/t.rast.export/t.rast.export.py

@@ -71,11 +71,12 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
 
 
 ############################################################################
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     _input = options["input"]

+ 3 - 1
temporal/t.rast.extract/t.rast.extract.py

@@ -74,12 +74,14 @@
 
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 3 - 3
temporal/t.rast.gapfill/t.rast.gapfill.py

@@ -65,15 +65,15 @@ import sys
 import copy
 from multiprocessing import Process
 import grass.script as grass
-import grass.temporal as tgis
-
-import grass.pygrass.modules as pymod
 from grass.exceptions import FatalError
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
+    import grass.pygrass.modules as pymod
 
     # Get the options
     input = options["input"]

+ 2 - 1
temporal/t.rast.import/t.rast.import.py

@@ -105,10 +105,11 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 3 - 1
temporal/t.rast.list/t.rast.list.py

@@ -86,12 +86,14 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 3 - 1
temporal/t.rast.mapcalc/t.rast.mapcalc.py

@@ -68,12 +68,14 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     inputs = options["inputs"]

+ 3 - 2
temporal/t.rast.neighbors/t.rast.neighbors.py

@@ -93,13 +93,14 @@ from __future__ import print_function
 
 import copy
 import grass.script as grass
-import grass.temporal as tgis
-import grass.pygrass.modules as pymod
 
 
 ############################################################################
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
+    import grass.pygrass.modules as pymod
 
     # Get the options
     input = options["input"]

+ 2 - 1
temporal/t.rast.out.vtk/t.rast.out.vtk.py

@@ -67,13 +67,14 @@
 
 import os
 import grass.script as grass
-import grass.temporal as tgis
 from grass.exceptions import CalledModuleError
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 2 - 1
temporal/t.rast.series/t.rast.series.py

@@ -65,13 +65,14 @@
 
 
 import grass.script as grass
-import grass.temporal as tgis
 from grass.exceptions import CalledModuleError
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 2 - 1
temporal/t.rast.to.rast3/t.rast.to.rast3.py

@@ -33,7 +33,6 @@ from __future__ import print_function
 
 import os
 import grass.script as grass
-import grass.temporal as tgis
 from datetime import datetime
 from grass.exceptions import CalledModuleError
 
@@ -41,6 +40,8 @@ from grass.exceptions import CalledModuleError
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 3 - 2
temporal/t.rast.to.vect/t.rast.to.vect.py

@@ -113,13 +113,14 @@
 import sys
 import copy
 import grass.script as gscript
-import grass.temporal as tgis
-import grass.pygrass.modules as pymod
 
 
 ############################################################################
 
 def main(options, flags):
+    # lazy imports
+    import grass.temporal as tgis
+    import grass.pygrass.modules as pymod
 
     # Get the options
     input = options["input"]

+ 3 - 1
temporal/t.rast.univar/t.rast.univar.py

@@ -55,12 +55,14 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 3 - 2
temporal/t.rast.what/t.rast.what.py

@@ -112,13 +112,14 @@
 import sys
 import copy
 import grass.script as gscript
-import grass.temporal as tgis
-import grass.pygrass.modules as pymod
 
 
 ############################################################################
 
 def main(options, flags):
+    # lazy imports
+    import grass.temporal as tgis
+    import grass.pygrass.modules as pymod
 
     # Get the options
     points = options["points"]

+ 4 - 1
temporal/t.rast3d.algebra/t.rast3d.algebra.py

@@ -66,10 +66,13 @@
 
 
 import grass.script
-import grass.temporal as tgis
 import sys
 
+
 def main():
+    # lazy imports
+    import grass.temporal as tgis
+
     expression = options['expression']
     basename = options['basename']
     nprocs = options["nprocs"]

+ 3 - 1
temporal/t.rast3d.extract/t.rast3d.extract.py

@@ -72,12 +72,14 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 3 - 1
temporal/t.rast3d.list/t.rast3d.list.py

@@ -78,12 +78,14 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 3 - 1
temporal/t.rast3d.mapcalc/t.rast3d.mapcalc.py

@@ -74,12 +74,14 @@
 from multiprocessing import Process
 import copy
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     inputs = options["inputs"]

+ 3 - 1
temporal/t.rast3d.univar/t.rast3d.univar.py

@@ -52,12 +52,14 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 4 - 2
temporal/t.register/t.register.py

@@ -99,13 +99,12 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
-
     # Get the options
     name = options["input"]
     maps = options["maps"]
@@ -131,6 +130,9 @@ def main():
 if __name__ == "__main__":
     options, flags = grass.parser()
 
+    # lazy imports
+    import grass.temporal as tgis
+
     try:
         from builtins import StandardError
     except ImportError:

+ 8 - 4
temporal/t.remove/t.remove.py

@@ -56,13 +56,13 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
-import grass.pygrass.modules as pyg
+
+
+# lazy imports at the end of the file
 
 ############################################################################
 
 def main():
-
     # Get the options
     datasets = options["inputs"]
     file = options["file"]
@@ -163,5 +163,9 @@ def main():
 
 if __name__ == "__main__":
     options, flags = grass.parser()
-    
+
+    # lazy imports
+    import grass.temporal as tgis
+    import grass.pygrass.modules as pyg
+
     tgis.profile_function(main)

+ 2 - 1
temporal/t.rename/t.rename.py

@@ -33,13 +33,14 @@
 #% guisection: Required
 #%end
 
-import grass.temporal as tgis
 import grass.script as grass
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 3 - 1
temporal/t.sample/t.sample.py

@@ -61,11 +61,13 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     inputs = options["inputs"]

+ 2 - 1
temporal/t.select/t.select.py

@@ -47,12 +47,13 @@
 
 
 import grass.script as grass
-import grass.temporal as tgis
 import sys
 
 ############################################################################
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     expression = options['expression']
     spatial = flags["s"]

+ 3 - 1
temporal/t.shift/t.shift.py

@@ -41,12 +41,14 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     name = options["input"]
     type = options["type"]

+ 3 - 1
temporal/t.snap/t.snap.py

@@ -32,12 +32,14 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     name = options["input"]
     type = options["type"]

+ 3 - 1
temporal/t.support/t.support.py

@@ -76,11 +76,13 @@
 
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     name = options["input"]

+ 3 - 1
temporal/t.topology/t.topology.py

@@ -44,12 +44,14 @@
 from __future__ import print_function
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     name = options["input"]

+ 7 - 3
temporal/t.unregister/t.unregister.py

@@ -43,13 +43,14 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
+
+# lazy imports at the end of the file
 
 ############################################################################
 
 
 def main():
-
     # Get the options
     file = options["file"]
     input = options["input"]
@@ -175,5 +176,8 @@ def main():
 
 if __name__ == "__main__":
     options, flags = grass.parser()
-    
+
+    # lazy imports
+    import grass.temporal as tgis
+
     tgis.profile_function(main)

+ 3 - 1
temporal/t.vect.algebra/t.vect.algebra.py

@@ -47,10 +47,12 @@
 #%end
 
 import grass.script
-import grass.temporal as tgis
 import sys
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
+
     expression = options['expression']
     basename = options['basename']
     spatial = flags["s"]

+ 3 - 1
temporal/t.vect.db.select/t.vect.db.select.py

@@ -46,12 +46,14 @@
 from __future__ import print_function
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 2 - 1
temporal/t.vect.export/t.vect.export.py

@@ -61,11 +61,12 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
 
 
 ############################################################################
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     _input = options["input"]

+ 3 - 1
temporal/t.vect.extract/t.vect.extract.py

@@ -75,12 +75,14 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 2 - 1
temporal/t.vect.import/t.vect.import.py

@@ -83,10 +83,11 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 3 - 1
temporal/t.vect.list/t.vect.list.py

@@ -78,12 +78,14 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 
 def main():
+    #lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 2 - 1
temporal/t.vect.observe.strds/t.vect.observe.strds.py

@@ -49,7 +49,6 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
 import grass.script.raster as raster
 from grass.exceptions import CalledModuleError
 
@@ -70,6 +69,8 @@ class Sample(object):
 ############################################################################
 
 def main():
+    #lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 3 - 1
temporal/t.vect.univar/t.vect.univar.py

@@ -68,11 +68,13 @@
 #%end
 
 import grass.script as grass
-import grass.temporal as tgis
+
 
 ############################################################################
 
 def main():
+    #lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]

+ 2 - 1
temporal/t.vect.what.strds/t.vect.what.strds.py

@@ -60,7 +60,6 @@
 
 import os
 import grass.script as grass
-import grass.temporal as tgis
 import grass.script.raster as raster
 from grass.exceptions import CalledModuleError
 
@@ -68,6 +67,8 @@ from grass.exceptions import CalledModuleError
 
 
 def main():
+    # lazy imports
+    import grass.temporal as tgis
 
     # Get the options
     input = options["input"]