Skip to content

Better way to document the aliases in docstrings #4011

Open

Description

@seisman

In the initial version of the alias system, each GMT option flag is aliased to a single parameter PyGMT, so documenting the aliases in docstrings is simple and can be fully automatic. The aliases docstrings are like:

**Aliases:**

- J=projection
- B=frame
- R=region

Then we realized that sometimes an option flag is too complicated and should be aliased to multiple parameters, and they're documented like below since #3965:

**Aliases:**

- J=projection
- B=frame
- R=region
- A=constantfill/gridfill/neighborfill/splinefill

With the new alias system introduced in #4000, we have to manually maintain the aliases in docstrings.

We need to discuss what the docstrings look like, especially for option flags that are aliased to multiple parameters. Let me take -U as an example. The GMT CLI syntax is -U[label][+jjustify][+odx[/dy]][+ttext], then the docstrings can be:

U=label, justify (+j), offset (+o), text (+t)

or

U=label, +j: justify, +o: offset, +t: text

We also need to add a documentation explaining how the new alias system works and how to read and understand the aliases in docstrings.

Originally posted by @seisman in #4000 (comment)

Activity

  1. added
    discussions
    on Jul 24, 2025
  2. added this to the 0.17.0 milestone on Aug 3, 2025
  3. seisman commented on Aug 3, 2025

    @seisman
    MemberAuthor

    Ping @GenericMappingTools/pygmt-maintainers Any comments on the docstring styles for aliases?

  4. yvonnefroehlich commented on Aug 3, 2025

    @yvonnefroehlich
    Member

    U=label, justify (+j), offset (+o), text (+t)

    or

    U=label, +j: justify, +o: offset, +t: text

    I prefer the second version for the syntax, as the GMT flag or modifier is consistently followed by the alias.


    Hm, maybe this was only an example with focus on modifiers which have or will have their own alias. Or do we now also want to mention the flags which are implemented as standalone methods? -U (as well as -X and -Y) are not anymore supported but we have Figure.timestamp and Figure.shift_origin.

  5. seisman commented on Aug 4, 2025

    @seisman
    MemberAuthor

    do we now also want to mention the flags which are implemented as standalone methods? -U (as well as -X and -Y) are not anymore supported but we have Figure.timestamp and Figure.shift_origin.

    I prefer not to list these flags in the docstrings.

  6. yvonnefroehlich commented on Aug 4, 2025

    @yvonnefroehlich
    Member

    When adding the aliases for the modifiers the lines get longer. Maybe this does not look nice with the multi-column layout we have currently and we have to go back to a one-column layout.

  7. seisman commented on Aug 4, 2025

    @seisman
    MemberAuthor

    Maybe this does not look nice with the multi-column layout we have currently and we have to go back to a one-column layout.

    That's a good point. Will try and see how it looks like.

  8. seisman commented on Aug 4, 2025

    @seisman
    MemberAuthor

    Maybe this does not look nice with the multi-column layout we have currently and we have to go back to a one-column layout.

    That's a good point. Will try and see how it looks like.

    Image

    You're right that it looks bad when an option flag is aliased to many parameters.

  9. seisman commented on Aug 7, 2025

    @seisman
    MemberAuthor

    Maybe we can still use a three-column layout for most simple option flags (like -J, -R) and use a one-column layout for a few option flags that are aliased to multiple parameters, although it means the option flags won't be sorted alphabetically.

  10. modified the milestones: 0.17.0, 0.18.0 on Sep 18, 2025
  11. removed this from the 0.18.0 milestone on Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions