From 56dfd851b053e332feeac9a6b40d406e44271d9d Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Tue, 17 Mar 2020 21:53:50 -0400 Subject: [PATCH] Update GMT constant GMT_STR16 to GMT_VF_LEN for GMT API change in 6.1.0 (#397) PyGMT fails with the latest GMT master branch with the following error message: ``` GMTCLibError: Constant 'GMT_STR16' doesn't exits in libgmt. ``` To reproduce the issue, you can run: ``` import pygmt fig = pygmt.Figure() fig.basemap(region='0/10/0/10', projection='X10c', frame=True) fig.plot(x=5, y=5, style='c0.2c') ``` The error is caused by the recent change of the length of virtual file names from `GMT_STR16` to `GMT_VF_LEN` in the core GMT (see https://github.com/GenericMappingTools/gmt/pull/2861). Changing `GMT_STR16` to `GMT_VF_LEN` is the easiest fix. To keep compatibility with both GMT 6.0.0 and the upcomming 6.1.0, this PR checks GMT version and use `GMT_STR16` for 6.0.0, otherwise use `GMT_VF_LEN`. --- pygmt/clib/session.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pygmt/clib/session.py b/pygmt/clib/session.py index bb39b57e384..e6148659540 100644 --- a/pygmt/clib/session.py +++ b/pygmt/clib/session.py @@ -987,7 +987,12 @@ def open_virtual_file(self, family, geometry, direction, data): valid_modifiers=["GMT_IS_REFERENCE", "GMT_IS_DUPLICATE"], ) - buff = ctp.create_string_buffer(self["GMT_STR16"]) + # The core GMT changes GMT_STR16 to GMT_VF_LEN in 6.1.0 + # See https://github.com/GenericMappingTools/gmt/pull/2861 + if Version(self.info["version"]) < Version("6.1.0"): + buff = ctp.create_string_buffer(self["GMT_STR16"]) + else: + buff = ctp.create_string_buffer(self["GMT_VF_LEN"]) status = c_open_virtualfile( self.session_pointer, family_int, geometry_int, direction_int, data, buff