Skip to content

Conversation

@seisman
Copy link
Member

@seisman seisman commented Mar 21, 2022

Description of proposed changes

  1. Show the GMT binary version available from the API parameter API_BIN_VERSION.
  2. Don't show the GMT version by calling gmt --version
  3. Don't show GMT's binary directory.

Fixes #1830.

@seisman seisman added the maintenance Boring but important stuff for the core devs label Mar 21, 2022
@seisman seisman added this to the 0.6.1 milestone Mar 21, 2022
@seisman
Copy link
Member Author

seisman commented Mar 21, 2022

Here is the output when geopandas is not installed:

PyGMT information:
  version: v0.6.1.dev6+g813142bb.d20220321
System information:
  python: 3.9.5 (default, May 18 2021, 12:31:01)  [Clang 10.0.0 ]
  executable: /Users/user/opt/miniconda/bin/python
  machine: macOS-10.16-x86_64-i386-64bit
Dependency information:
  numpy: 1.21.4
  pandas: 1.3.4
  xarray: 0.20.1
  netCDF4: 1.5.8
  packaging: 21.3
  geopandas: None
  ghostscript: 9.55.0
GMT library information:
  cores: 8
  grid layout: rows
  library path: /Users/user/opt/GMT-master/lib/libgmt.dylib
  padding: 2
  plugin dir: /Users/user/opt/GMT-master/lib/gmt/plugins
  share dir: /Users/user/opt/GMT-master/share
  version: 6.4.0

When geopandas is installed:

PyGMT information:
  version: v0.6.1.dev6+g813142bb.d20220321
System information:
  python: 3.9.5 (default, May 18 2021, 12:31:01)  [Clang 10.0.0 ]
  executable: /Users/user/opt/miniconda/bin/python
  machine: macOS-10.16-x86_64-i386-64bit
Dependency information:
  numpy: 1.21.4
  pandas: 1.3.4
  xarray: 0.20.1
  netCDF4: 1.5.8
  packaging: 21.3
  geopandas: 0.10.2
  ghostscript: 9.55.0
GMT library information:
  cores: 8
  grid layout: rows
  library path: /Users/user/opt/GMT-master/lib/libgmt.dylib
  padding: 2
  plugin dir: /Users/user/opt/GMT-master/lib/gmt/plugins
  share dir: /Users/user/opt/GMT-master/share
  version: 6.4.0

"""
if not hasattr(self, "_info"):
self._info = { # pylint: disable=attribute-defined-outside-init
"version": self.get_default("API_VERSION"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From #1830 (comment), you said:

2. The GMT version information gmt: 6.4.0_434ed18_2022.03.11 is obtained by calling gmt --version. However, when multiple GMT versions are installed, the command gmt and the library libgmt may come from different GMT versions. For example, if I have GMT 6.3 in my conda environment and GMT dev in another installation path, PyGMT may load the GMT 6.3 library but find GMT dev comman, or vice versa, depending on the settings of PATH and GMT_LIBRARY_PATH. It causes some confusion because PyGMT reports inconsistent GMT versions. I think we should remove the gmt: 6.4.0_434ed18_2022.03.11 information.

So we will only have 6.4.0 printed out. This is ok for most users who install the offficial release versions, but for those who install the dev versions, I think it's useful to have the git short-hash and date part too, so that we can know the exact GMT dev version we've installed.

Just as an idea, how about we check the two strings? If there are equal (e.g. 6.4.0 and 6.4.0), we just print one. But if they are different, then print both? Alternatively, is there a way to get the exact version from the GMT API somehow?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From #1830 (comment), you said:

  1. The GMT version information gmt: 6.4.0_434ed18_2022.03.11 is obtained by calling gmt --version. However, when multiple GMT versions are installed, the command gmt and the library libgmt may come from different GMT versions. For example, if I have GMT 6.3 in my conda environment and GMT dev in another installation path, PyGMT may load the GMT 6.3 library but find GMT dev comman, or vice versa, depending on the settings of PATH and GMT_LIBRARY_PATH. It causes some confusion because PyGMT reports inconsistent GMT versions. I think we should remove the gmt: 6.4.0_434ed18_2022.03.11 information.

So we will only have 6.4.0 printed out. This is ok for most users who install the offficial release versions, but for those who install the dev versions, I think it's useful to have the git short-hash and date part too, so that we can know the exact GMT dev version we've installed.

Yes, I agree.

Just as an idea, how about we check the two strings? If there are equal (e.g. 6.4.0 and 6.4.0), we just print one. But if they are different, then print both?

We still have the same problem. When multiple GMT versions are installed, we may load the libgmt from GMT version A and call GMT CLI from GMT version B.

Alternatively, is there a way to get the exact version from the GMT API somehow?

I just checked the GMT source code. It's impossible to get the version string 6.4.0_434ed18_2022.03.11 from GMT API.

Since we can know the GMT library path library path: /Users/user/opt/GMT-master/lib/libgmt.dylib, perhaps we can assume that the relative path to the GMT command is {library path}/../bin/gmt? Or we can ask GMT to report the version string 6.4.0_434ed18_2022.03.11 through GMT API?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, is there a way to get the exact version from the GMT API somehow?

I just checked the GMT source code. It's impossible to get the version string 6.4.0_434ed18_2022.03.11 from GMT API.

Since we can know the GMT library path library path: /Users/user/opt/GMT-master/lib/libgmt.dylib, perhaps we can assume that the relative path to the GMT command is {library path}/../bin/gmt? Or we can ask GMT to report the version string 6.4.0_434ed18_2022.03.11 through GMT API?

Getting it through the GMT API seems like the most robust solution, rather than having to guess where the actual GMT binary PyGMT is using is located on the filesystem. Not sure if this is possible though to get the git hash information in C?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refer to the git commit information often when debugging (while careful to not have GMT installed via conda), so I added this option to the GMT_Get_Default API function in GenericMappingTools/gmt#6493 so that we can keep this information in show_versions.

@seisman seisman marked this pull request as draft March 25, 2022 14:32
@seisman seisman changed the title Add geopandas version and remove GMT binary path and version from pygmt.show_versions() Remove GMT binary path and version from pygmt.show_versions() Mar 26, 2022
@seisman seisman added the upstream Bug or missing feature of upstream core GMT label Mar 29, 2022
@seisman seisman removed this from the 0.6.1 milestone Mar 29, 2022
@seisman seisman force-pushed the improve-show_versions branch from c8f7282 to 3dfae7b Compare April 2, 2022 04:41
@seisman
Copy link
Member Author

seisman commented Apr 2, 2022

I've updated this PR to show the GMT version from the API parameter API_BIN_VERSION. We can only merge this PR after we bump the required GMT version to 6.4.0.

@seisman seisman added this to the 0.8.0 milestone Jul 2, 2022
@seisman
Copy link
Member Author

seisman commented Jul 7, 2022

We need to make it backward compatible with the old GMT versions if we decide to
follow the suggestions in #1991.

@seisman
Copy link
Member Author

seisman commented Aug 28, 2022

I've made the commit 8df1b55 to make sure the new show_versions() function is backward compatible with GMT 6.3.0.

Here are the outputs for different cases:

GMT 6.3.0 with geopandas

PyGMT information:
  version: v0.7.1.dev56+g0e1ec564.d20220823
System information:
  python: 3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:43:32) [Clang 12.0.1 ]
  executable: /Users/seisman/opt/miniconda/envs/dev/bin/python
  machine: macOS-12.5.1-x86_64-i386-64bit
Dependency information:
  numpy: 1.22.4
  pandas: 1.4.2
  xarray: 2022.3.0
  netCDF4: 1.5.8
  packaging: 21.3
  geopandas: 0.10.2
  ghostscript: 9.54.0
GMT library information:
  cores: 8
  grid layout: rows
  library path: /Users/seisman/opt/miniconda/envs/dev/lib/libgmt.dylib
  padding: 2
  plugin dir: /Users/seisman/opt/miniconda/envs/dev/lib/gmt/plugins
  share dir: /Users/seisman/opt/miniconda/envs/dev/share/gmt
  version: 6.3.0

GMT 6.3.0 without geopandas

PyGMT information:
  version: v0.7.1.dev56+g0e1ec564.d20220823
System information:
  python: 3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:43:32) [Clang 12.0.1 ]
  executable: /Users/seisman/opt/miniconda/envs/dev/bin/python
  machine: macOS-12.5.1-x86_64-i386-64bit
Dependency information:
  numpy: 1.22.4
  pandas: 1.4.2
  xarray: 2022.3.0
  netCDF4: 1.5.8
  packaging: 21.3
  geopandas: None
  ghostscript: 9.54.0
GMT library information:
  cores: 8
  grid layout: rows
  library path: /Users/seisman/opt/miniconda/envs/dev/lib/libgmt.dylib
  padding: 2
  plugin dir: /Users/seisman/opt/miniconda/envs/dev/lib/gmt/plugins
  share dir: /Users/seisman/opt/miniconda/envs/dev/share/gmt
  version: 6.3.0

GMT 6.5.0 (dev) with geopandas

PyGMT information:
  version: v0.7.1.dev56+g0e1ec564.d20220823
System information:
  python: 3.9.10 | packaged by conda-forge | (main, Feb  1 2022, 21:28:27)  [Clang 11.1.0 ]
  executable: /Users/seisman/opt/miniconda/bin/python
  machine: macOS-12.5.1-x86_64-i386-64bit
Dependency information:
  numpy: 1.22.4
  pandas: 1.4.2
  xarray: 2022.3.0
  netCDF4: 1.5.8
  packaging: 21.3
  geopandas: 0.11.0
  ghostscript: 9.56.1
GMT library information:
  binary version: 6.5.0_566ed34_2022.08.08
  cores: 8
  grid layout: rows
  library path: /Users/seisman/opt/GMT-master/lib/libgmt.dylib
  padding: 2
  plugin dir: /Users/seisman/opt/GMT-master/lib/gmt/plugins
  share dir: /Users/seisman/opt/GMT-master/share
  version: 6.5.0

GMT 6.5.0 (dev) without geopandas

PyGMT information:
  version: v0.7.1.dev56+g0e1ec564.d20220823
System information:
  python: 3.9.10 | packaged by conda-forge | (main, Feb  1 2022, 21:28:27)  [Clang 11.1.0 ]
  executable: /Users/seisman/opt/miniconda/bin/python
  machine: macOS-12.5.1-x86_64-i386-64bit
Dependency information:
  numpy: 1.22.4
  pandas: 1.4.2
  xarray: 2022.3.0
  netCDF4: 1.5.8
  packaging: 21.3
  geopandas: None
  ghostscript: 9.56.1
GMT library information:
  binary version: 6.5.0_566ed34_2022.08.08
  cores: 8
  grid layout: rows
  library path: /Users/seisman/opt/GMT-master/lib/libgmt.dylib
  padding: 2
  plugin dir: /Users/seisman/opt/GMT-master/lib/gmt/plugins
  share dir: /Users/seisman/opt/GMT-master/share
  version: 6.5.0

@seisman seisman marked this pull request as ready for review August 28, 2022 15:12
@seisman seisman added the needs review This PR has higher priority and needs review. label Aug 28, 2022
@seisman seisman marked this pull request as draft August 28, 2022 15:47
@seisman seisman removed the needs review This PR has higher priority and needs review. label Aug 28, 2022
@seisman seisman marked this pull request as ready for review August 28, 2022 16:38
@seisman seisman added the needs review This PR has higher priority and needs review. label Aug 28, 2022
@seisman seisman changed the title Remove GMT binary path and version from pygmt.show_versions() Improve pygmt.show_versions() to show GMT binary Remove GMT binary path and version from pygmt.show_versions() Aug 29, 2022
@seisman seisman changed the title Improve pygmt.show_versions() to show GMT binary Remove GMT binary path and version from pygmt.show_versions() pygmt.show_versions: Show GMT binary version and don't show the Python interpreter path Aug 29, 2022
@seisman seisman changed the title pygmt.show_versions: Show GMT binary version and don't show the Python interpreter path Improve pygmt.show_versions to show GMT binary version and hide the Python interpreter path Aug 29, 2022
@seisman seisman changed the title Improve pygmt.show_versions to show GMT binary version and hide the Python interpreter path pygmt.show_versions: Show GMT binary version and hide the Python interpreter path Aug 29, 2022
@seisman seisman requested review from maxrjones and weiji14 September 9, 2022 15:29
Comment on lines +174 to +175
if Version(self._info["version"]) >= Version("6.4.0"):
self._info["binary version"] = self.get_default("API_BIN_VERSION")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the binary version supposed to be just 6.4.0 (with no hash or date) for the official GMT 6.4 conda-forge package added in conda-forge/gmt-feedstock#212? I was expecting a string like 6.4.0_434ed18_2022.03.11, but am getting this output from python -c 'import pygmt; pygmt.show_versions()'

PyGMT information:
  version: v0.7.1.dev92+gde7026137
System information:
  python: 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:04:59) [GCC 10.3.0]
  executable: /home/username/mambaforge/envs/pygmt/bin/python
  machine: Linux-5.17.0-1016-oem-x86_64-with-glibc2.35
Dependency information:
  numpy: 1.23.2
  pandas: 1.4.3
  xarray: 2022.6.0
  netCDF4: 1.6.0
  packaging: 21.3
  geopandas: 0.11.1
  ghostscript: 9.54.0
GMT library information:
  binary version: 6.4.0
  cores: 12
  grid layout: rows
  library path: /home/username/mambaforge/envs/pygmt/lib/libgmt.so
  padding: 2
  plugin dir: /home/username/mambaforge/envs/pygmt/lib/gmt/plugins
  share dir: /home/username/mambaforge/envs/pygmt/share/gmt
  version: 6.4.0

and output of mamba list | grep gmt is:

dcw-gmt                   2.1.1                ha770c72_0    conda-forge
gmt                       6.4.0                h78e8b95_2    conda-forge
gshhg-gmt                 2.3.7             ha770c72_1003    conda-forge
pygmt                     0.7.1.dev92+gde7026137          pypi_0    pypi

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the binary version supposed to be just 6.4.0 (with no hash or date) for the official GMT 6.4 conda-forge package added in conda-forge/gmt-feedstock#212? I was expecting a string like 6.4.0_434ed18_2022.03.11.

For official releases, the version string is 6.4.0 without hash and date. 6.4.0_434ed18_2022.03.11 is the version string for dev versions.

Comment on lines +876 to +891
if name == b"API_VERSION":
value.value = b"1.2.3"
else:
value.value = b"bla"
return 0

ses = clib.Session()
ses.create("test-session")
with mock(ses, "GMT_Get_Default", mock_func=mock_defaults):
# Check for an empty dictionary
assert ses.info
for value in ses.info.values():
assert value == "bla"
for key, value in ses.info.items():
if key == "version":
assert value == "1.2.3"
else:
assert value == "bla"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there also be a mock for if name == b"API_BIN_VERSION" and if key == "binary_version"? Or would that break with #2079?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At line 173 in pygmt/clib/session.py, we have the following code:

            if Version(self._info["version"]) >= Version("6.4.0"):
                self._info["binary version"] = self.get_default("API_BIN_VERSION")

The Version() class requires self._info["version"] being a valid version string, so we can't give a value like bla to API_VERSION.

There is no such problem for API_BIN_VERSION, so no special operation is done for it.

@seisman seisman requested a review from weiji14 September 14, 2022 05:46
@weiji14 weiji14 added final review call This PR requires final review and approval from a second reviewer and removed needs review This PR has higher priority and needs review. labels Sep 14, 2022
@seisman seisman removed the final review call This PR requires final review and approval from a second reviewer label Sep 15, 2022
@seisman seisman merged commit 3e90b26 into main Sep 15, 2022
@seisman seisman deleted the improve-show_versions branch September 15, 2022 09:20
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Boring but important stuff for the core devs upstream Bug or missing feature of upstream core GMT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve the pygmt.show_versions() function

5 participants