-
Notifications
You must be signed in to change notification settings - Fork 224
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
pygmt.config: Support tab auto-completion for all GMT defaults #2213
Conversation
46e85c5
to
3d8acc7
Compare
3d8acc7
to
ab69392
Compare
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.
The tab autocomplete is nice! Just need to decide how to list the 135 (if I didn't miscount) parameters in https://docs.generic-mapping-tools.org/6.4/gmt.conf.html 😅
pygmt/src/config.py
Outdated
@@ -20,6 +22,15 @@ class config: # pylint: disable=invalid-name | |||
Full GMT defaults list at :gmt-docs:`gmt.conf.html` | |||
""" | |||
|
|||
# Manually set the __signature__ attribute to enable tab autocompletion | |||
_keywords = ["FONT_LABEL", "FONT_TAG", "FONT_TITLE"] |
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.
Hmm, would we need to manually list all the possible parameters here? I'm looking at gmt.conf.rst
and https://github.com/GenericMappingTools/gmt/blob/34aa940e7a30a6dca4fc554b8dcd747dcef3e93e/src/gmt_defaults.h#L60-L211, but not sure if there's a smart way to get the whole list from the GMT C 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.
gmt defaults
can output all the keywords and their current values. So at least we can call gmt defaults
and extract the keywords from the output.
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.
Calling gmt defaults
is not a perfect idea, because the code will be executed when importing the pygmt
package. Perhaps manually maintaining the the long list of keywords is not a bad idea because the list of GMT keywords don't change much between versions.
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.
Ok I guess. Even if the list gets out of date because GMT adds new configs, people can still use it, just without tab completion.
f3a9c16
to
2fa17a5
Compare
I've manually added the long list of keywords to The long list contains 128 normal keywords as listed by the following command:
plus 8 special keywords like |
pygmt/src/config.py
Outdated
] + [ # special keywords | ||
"FONT", | ||
"FONT_ANNOT", | ||
"FORMAT_TIME_MAP", | ||
"MAP_ANNOT_OFFSET", | ||
"MAP_GRID_CROSS_SIZE", | ||
"MAP_GRID_PEN", | ||
"MAP_TICK_LENGTH", | ||
"MAP_TICK_PEN", | ||
] |
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 think it makes more sense to also put the self.special_params
attribute out of the __init__
function.
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.
Yeah, I was thinking about that too. Maybe create a _special_params
variable to hold that dictionary.
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.
Done in 318501b, and the variable name is _special_keywords
instead of _special_params
.
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.
Nice work, just double checked one by one and it looks good!
Description of proposed changes
Let
pygmt.config()
support tab auto-completion by manually setting the__signature__
attribute of thepygmt.config()
class, inspired by the implementation in #1282.Screenshot:
Fixes #
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.Slash Commands
You can write slash commands (
/command
) in the first line of a comment to performspecific operations. Supported slash commands are:
/format
: automatically format and lint the code/test-gmt-dev
: run full tests on the latest GMT development version