pygmt.config: Support tab auto-completion for all GMT defaults#2213
pygmt.config: Support tab auto-completion for all GMT defaults#2213
Conversation
46e85c5 to
3d8acc7
Compare
3d8acc7 to
ab69392
Compare
weiji14
left a comment
There was a problem hiding this comment.
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
| """ | ||
|
|
||
| # Manually set the __signature__ attribute to enable tab autocompletion | ||
| _keywords = ["FONT_LABEL", "FONT_TAG", "FONT_TITLE"] |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
Yeah, I was thinking about that too. Maybe create a _special_params variable to hold that dictionary.
There was a problem hiding this comment.
Done in 318501b, and the variable name is _special_keywords instead of _special_params.
There was a problem hiding this comment.
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 formatandmake checkto 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