Skip to content
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

Add docformatter to format plain text in docstrings #642

Merged
merged 10 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

- name: Install packages
run: |
pip install black blackdoc flake8 pylint isort
pip install black blackdoc docformatter flake8 pylint isort
sudo apt-get install dos2unix

- name: Formatting check (black and flake8)
seisman marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,11 @@ We use some tools:

- [Black](https://github.com/ambv/black)
- [blackdoc](https://github.com/keewis/blackdoc)
- [docformatter](https://github.com/myint/docformatter)
- [isort](https://pycqa.github.io/isort/)

to format the code so we don't have to think about it.
Black loosely follows the [PEP8](http://pep8.org) guide but with a few differences.
Black and blackdoc loosely follows the [PEP8](http://pep8.org) guide but with a few differences.
Regardless, you won't have to worry about formatting the code yourself.
Before committing, run it to automatically format your code:

Expand All @@ -273,7 +274,7 @@ common errors.
The [`Makefile`](Makefile) contains rules for running both checks:

```bash
make check # Runs flake8, black, blackdoc and isort (in check mode)
make check # Runs flake8, black, blackdoc, docformatter and isort (in check mode)
seisman marked this conversation as resolved.
Show resolved Hide resolved
make lint # Runs pylint, which is a bit slower
```

Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PYTEST_COV_ARGS=--cov=$(PROJECT) --cov-config=../pyproject.toml \
--pyargs ${PYTEST_EXTRA}
BLACK_FILES=$(PROJECT) setup.py doc/conf.py examples
BLACKDOC_OPTIONS=--line-length 79
DOCFORMATTER_FILES=$(PROJECT) setup.py doc/conf.py examples
DOCFORMATTER_OPTIONS=--recursive --pre-summary-newline --wrap-summaries 79 --wrap-descriptions 79
Copy link
Member

@weiji14 weiji14 Jan 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DOCFORMATTER_OPTIONS=--recursive --pre-summary-newline --wrap-summaries 79 --wrap-descriptions 79
DOCFORMATTER_OPTIONS=--recursive --pre-summary-newline --make-summary-multi-line --wrap-summaries 79 --wrap-descriptions 79

Do we want to force --make-summary-multi-line (see https://github.com/myint/docformatter/tree/v1.4#options)? This will turn every description (even short ones) into:

"""
This is a description.
"""

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it looks cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just find that PEP 257 says:

Unless the entire docstring fits on a line, place the closing quotes on a line by themselves.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, seems like docformatter didn't implement that one-line docstring PEP 257 guideline correctly? I think it's ok to just force multi-line though, as long as there's an automated solution.

FLAKE8_FILES=$(PROJECT) setup.py doc/conf.py
LINT_FILES=$(PROJECT) setup.py doc/conf.py

Expand All @@ -14,8 +16,8 @@ help:
@echo ""
@echo " install install in editable mode"
@echo " test run the test suite (including doctests) and report coverage"
@echo " format run black and blackdoc to automatically format the code"
@echo " check run code style and quality checks (black, blackdoc, isort and flake8)"
@echo " format run black, blackdoc, docformatter and isort to automatically format the code"
@echo " check run code style and quality checks (black, blackdoc, docformatter, isort and flake8)"
seisman marked this conversation as resolved.
Show resolved Hide resolved
@echo " lint run pylint for a deeper (and slower) quality check"
@echo " clean clean up build and generated files"
@echo " distclean clean up build and generated files, including project metadata files"
Expand All @@ -37,11 +39,13 @@ test:

format:
isort .
docformatter --in-place $(DOCFORMATTER_OPTIONS) $(DOCFORMATTER_FILES)
black $(BLACK_FILES)
blackdoc $(BLACKDOC_OPTIONS) $(BLACK_FILES)

check:
isort . --check
docformatter --check $(DOCFORMATTER_OPTIONS) $(DOCFORMATTER_FILES)
black --check $(BLACK_FILES)
blackdoc --check $(BLACKDOC_OPTIONS) $(BLACK_FILES)
flake8 $(FLAKE8_FILES)
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies:
- black
- blackdoc
- isort>=5
- docformatter
weiji14 marked this conversation as resolved.
Show resolved Hide resolved
- pylint
- flake8
- sphinx
Expand Down
2 changes: 1 addition & 1 deletion pygmt/tests/test_grdcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def fixture_grid():


def test_grdcut_file_in_file_out():
"grduct an input grid file, and output to a grid file"
"grdcut an input grid file, and output to a grid file"
with GMTTempFile(suffix=".nc") as tmpfile:
result = grdcut("@earth_relief_01d", outgrid=tmpfile.name, region="0/180/0/90")
assert result is None # return value is None
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ coverage[toml]
black
blackdoc
isort>=5
docformatter
weiji14 marked this conversation as resolved.
Show resolved Hide resolved
pylint
flake8
sphinx
Expand Down