Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 92 additions & 2 deletions doc/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ To increase the chances of getting your pull request accepted quickly, try to:
- Include an example of new features in the gallery or tutorials.
Please refer to [Gallery plots](contributing.md#contributing-gallery-plots)
or [Tutorials](contributing.md#contributing-tutorials).
If adding a new method/function/class, the gallery example or tutorial should
be submitted in a separate pull request.
* Have a good coding style
- Use readable code, as it is better than clever code (even with comments).
- Follow the [PEP8](https://pep8.org) style guide for code and the
Expand Down Expand Up @@ -467,8 +469,9 @@ function/class/module/method.
### PyGMT Code Overview

The source code for PyGMT is located in the `pygmt/` directory. When contributing
code, be sure to follow the general guidelines in the
[pull request workflow](contributing.md#pull-request-workflow) section.
code, please open an issue first to discuss the feature and its implementation
and be sure to follow the general guidelines in the
[pull request workflow](#pull-request-workflow) section.

### Code Style

Expand Down Expand Up @@ -511,6 +514,93 @@ contains rules for running the linter checks:
make check # Runs ruff in check mode
```

### Wrapping a GMT Module

Wrapping a GMT module in PyGMT is usually a big task, but it can progress more smoothly
and efficiently when divided into **small, manageable chunks**. This section gives an
overview of the main tasks involved.

1. Create a feature request ("wrapper request issue") for wrapping a GMT module and
discuss what users would like to see in the new feature. [optional, usually done by
users].
2. Create a tracking issue ("wrapper tracking issue"), using the "Wrapper for a GMT
module" issue template, to track the progress of wrapping the module. Link it to the
Project board, and close the "wrapper request issue" with a comment such as
> Thank you for opening the feature request. The progress of wrapping the module will
> be tracked in issue #XXX and
> the [Project board](https://github.com/orgs/GenericMappingTools/projects/3)".
[usually done by maintainers].
3. Open one PR for the initial implementation, focusing on required and essential
parameters.
4. Close the "wrapper tracking issue" once the initial implementation is merged. Leave a
comment such as:
> The initial implementation of wrapping the XXX module was completed in PR #XXX.
> Not all functionalities are implemented yet. Further progress will be tracked in
> the Project board.
This is necessary to avoid having hundreds of long-term open issues.
5. Open one or more PRs to implement the remaining features and missing aliases.
6. Open one PR to add a gallery example or a tutorial.

These pull requests can be split among multiple contributors. There is no obligation for
a single contributor to complete all steps. Please comment on the "wrapper tracking
issue" if you would like to open a pull request for any of these tasks to avoid
redundant efforts.

#### Feature Request Issue for Wrapping a GMT Module

* Find the [*Issues*](https://github.com/GenericMappingTools/pygmt/issues) tab at the
top of the GitHub repository and click *New Issue*.
* Choose the *Feature request* issue template.
* Follow the prompts for filling out the issue template.

#### Central Issue for Tracking the Progress

*This step is usually done by maintainers.*

* Find the [*Issues*](https://github.com/GenericMappingTools/pygmt/issues) tab on the
top of the GitHub repository and click *New Issue*.
* Choose the "Wrapper for a module" issue template.
* Fill out the issue template.

#### Initial Feature Implementation

First, comment on the "Wrapper tracking issue" that you will be working on the initial
implementation. This first pull request should be as minimal as possible - only adding
the required functionality (i.e., wrapping the required GMT parameters and supporting
the primary input/output types).

The following steps are common to all initial implementation pull requests that wrap a
GMT module:

* Create a new module `<module-name>.py` in `pygmt/src`. The module docstring should
include the module name and a short description of the functionality (e.g.,
`grdfill - Fill blank areas from a grid.`).
* Add a function `<module-name>` to the module. When writing the new function, it is
generally easiest to reference the source code for other functions that input/output
similar object types.
* Write a detailed docstring following the [numpy style guide](https://numpydoc.readthedocs.io/en/latest/format.html).
* Add the function to the import statements in `pygmt/src/__init__.py`.
* Add the function to the import statements in `pygmt/__init__.py`.
* Add the function to appropriate section of the API documentation in `doc/api/index.rst`.
* Add a testing module `test_<module-name>.py` in `pygmt/tests`, following
the guidelines in the [testing your code](#testing-your-code) section.

#### Add Missing Aliases

After the initial implementation, missing aliases can be added in separate PRs:

* Select a suitable alias for each GMT option, following the guidelines in the
[code style](#code-style) section. Before creating a new alias, check:

- whether the parameter is listed in the `COMMON_DOCSTRINGS` dictionary in
`pygmt/helpers/decorators.py`
- whether other wrapped GMT modules have a similar parameter
- whether [GMT.jl](https://www.generic-mapping-tools.org/GMT.jl/dev/) has defined an alias
* Add the alias to the `AliasSystem` class and the function signature.
* Add the alias and description to the parameters section of the docstring, using the
`fmt_docstring` decorator to add descriptions for parameters included in the
`COMMON_DOCSTRINGS` dictionary.

### Testing your Code

Automated testing helps ensure that our code is as free of bugs as it can be.
Expand Down