[GRASS-dev] [GRASS GIS] #3257: Do not require ctypes for compilation in temporal modules

#3257: Do not require ctypes for compilation in temporal modules
-------------------------------------------------+-------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 7.2.1
Component: Temporal | Version: unspecified
Keywords: ctypes, compilation, build, | CPU: Unspecified
  homebrew, brew, conda, macos, osx, |
  v.what.strds, t.create |
Platform: All |
-------------------------------------------------+-------------------------
The temporal modules require ctypes even during compilation. This makes
the whole compilation more fragile. When ctypes fails compilation fails.
This currently happens for example with Homebrew on Mac or in Conda
environment (see below examples of error messages). The errors are
somewhere else and the modules won't work, but I think the failure should
come only when user actually needs them. The temporal modules should not
break the build with ctypes not present or the dynamic libraries broken.

The list of directories with errors:

{{{
/usr/local/src/grass/scripts/v.what.strds
/usr/local/src/grass/temporal/t.create
/usr/local/src/grass/temporal/t.support
...
/usr/local/src/grass/temporal/t.vect.what.strds
/usr/local/src/grass/temporal/t.vect.observe.strds
/usr/local/src/grass/temporal/t.vect.univar
}}}

Examples of actual errors:

{{{
Traceback (most recent call last):
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/scripts/v.what.strds", line 53, in <module>
         import grass.temporal as tgis
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/temporal/init.py", line 3, in <module>
         from .core import *
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/temporal/core.py", line 44, in <module>
         from .c_libraries_interface import *
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/temporal/c_libraries_interface.py", line 23, in
<module>
         import grass.lib.vector as libvector
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/lib/vector.py", line 23, in <module>
         _libs["grass_vector.7.3.svn"] =
load_library("grass_vector.7.3.svn")
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/lib/ctypes_loader.py", line 62, in load_library
         return self.load(path)
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/lib/ctypes_loader.py", line 78, in load
         raise ImportError(e)
ImportError: /home/main/anaconda2/bin/../lib/libgfortran.so.3: version
`GFORTRAN_1.4' not found (required by /usr/lib/liblapack.so.3)
make[3]: *** [v.what.strds.tmp.html] Error 1
../../include/Make/Html.make:14: recipe for target 'v.what.strds.tmp.html'
failed
}}}

{{{
Traceback (most recent call last):
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/scripts/v.what.strds", line 53, in <module>
         import grass.temporal as tgis
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/temporal/init.py", line 3, in <module>
         from .core import *
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/temporal/core.py", line 44, in <module>
         from .c_libraries_interface import *
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/temporal/c_libraries_interface.py", line 23, in
<module>
         import grass.lib.vector as libvector
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/lib/vector.py", line 23, in <module>
         _libs["grass_vector.7.3.svn"] =
load_library("grass_vector.7.3.svn")
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/lib/ctypes_loader.py", line 62, in load_library
         return self.load(path)
   File "/usr/local/src/grass/dist.x86_64-pc-linux-
gnu/etc/python/grass/lib/ctypes_loader.py", line 78, in load
         raise ImportError(e)
ImportError: /usr/lib/libgdal.so.1: undefined symbol:
sqlite3_column_table_name
../../include/Make/Html.make:14: recipe for target 'v.what.strds.tmp.html'
failed
make[3]: *** [v.what.strds.tmp.html] Error 1
}}}

{{{
ImportError...image not found...library not loaded libgis_datetime...
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3257&gt;
GRASS GIS <https://grass.osgeo.org>

#3257: Do not require ctypes for compilation in temporal modules
-------------------------+-------------------------------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.1
Component: Temporal | Version: unspecified
Resolution: | Keywords: ctypes, compilation, build,
                         | homebrew, brew, conda, macos, osx,
       CPU: | v.what.strds, t.create
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by wenzeslaus):

In [changeset:"70357" 70357]:
{{{
#!CommitTicketReference repository="" revision="70357"
use lazy imports for the temporal package

This avoids ctypes-related issues during compilation (see #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).
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3257#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3257: Do not require ctypes for compilation in temporal modules
-------------------------+-------------------------------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.1
Component: Temporal | Version: unspecified
Resolution: | Keywords: ctypes, compilation, build,
                         | homebrew, brew, conda, macos, osx,
       CPU: | v.what.strds, t.create
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by neteler):

Backport this...?

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3257#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#3257: Do not require ctypes for compilation in temporal modules
-------------------------+-------------------------------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: new
  Priority: normal | Milestone: 7.2.1
Component: Temporal | Version: unspecified
Resolution: | Keywords: ctypes, compilation, build,
                         | homebrew, brew, conda, macos, osx,
       CPU: | v.what.strds, t.create
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by wenzeslaus):

In [changeset:"70588" 70588]:
{{{
#!CommitTicketReference repository="" revision="70588"
use lazy imports for the temporal package (backport r70357, see #3257)
}}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3257#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>

#3257: Do not require ctypes for compilation in temporal modules
-------------------------+-------------------------------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 7.2.1
Component: Temporal | Version: unspecified
Resolution: fixed | Keywords: ctypes, compilation, build,
                         | homebrew, brew, conda, macos, osx,
       CPU: | v.what.strds, t.create
  Unspecified | Platform: All
-------------------------+-------------------------------------------------
Changes (by wenzeslaus):

* status: new => closed
* resolution: => fixed

Comment:

It likely fixes much more than it potentially breaks. Backported to 7.2
branch. Will be in 7.2.1.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3257#comment:4&gt;
GRASS GIS <https://grass.osgeo.org>