-
Notifications
You must be signed in to change notification settings - Fork 235
pygmt.show_versions: Show GMT binary version and hide the Python interpreter path #1838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
83242e9
3dfae7b
9b16f59
8df1b55
05e2394
ded0018
de70261
2fbc80a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,7 +158,8 @@ def info(self): | |
| self._info = { # pylint: disable=attribute-defined-outside-init | ||
| "version": self.get_default("API_VERSION"), | ||
| "padding": self.get_default("API_PAD"), | ||
| "binary dir": self.get_default("API_BINDIR"), | ||
| # API_BINDIR points to the directory of the Python interpreter | ||
| # "binary dir": self.get_default("API_BINDIR"), | ||
| "share dir": self.get_default("API_SHAREDIR"), | ||
| # This segfaults for some reason | ||
| # 'data dir': self.get_default("API_DATADIR"), | ||
|
|
@@ -169,6 +170,9 @@ def info(self): | |
| # "image layout": self.get_default("API_IMAGE_LAYOUT"), | ||
| "grid layout": self.get_default("API_GRID_LAYOUT"), | ||
| } | ||
| # API_BIN_VERSION is new in GMT 6.4.0. | ||
| if Version(self._info["version"]) >= Version("6.4.0"): | ||
| self._info["binary version"] = self.get_default("API_BIN_VERSION") | ||
|
Comment on lines
+174
to
+175
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the binary version supposed to be just and output of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For official releases, the version string is |
||
| return self._info | ||
|
|
||
| def __enter__(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -873,16 +873,22 @@ def mock_defaults(api, name, value): # pylint: disable=unused-argument | |
| """ | ||
| Put 'bla' in the value buffer. | ||
| """ | ||
| value.value = b"bla" | ||
| 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" | ||
|
Comment on lines
+876
to
+891
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there also be a mock for
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At line 173 in The There is no such problem for |
||
| ses.destroy() | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
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:
So we will only have
6.4.0printed out. This is ok for most users who install the offficial release versions, but for those who install thedevversions, 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.0and6.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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree.
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.
I just checked the GMT source code. It's impossible to get the version string
6.4.0_434ed18_2022.03.11from 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 string6.4.0_434ed18_2022.03.11through GMT API?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
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.