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

WIP: Toy implementation of automatic translation of GMT docs to PyGMT docstrings #917

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Set maximum line length and indentation length of docstrings
  • Loading branch information
seisman committed Feb 17, 2021
commit e12bfeeaaeb1989d0cfd4676e858cb31c2963b72
12 changes: 8 additions & 4 deletions sandbox/pygmt_docstrings.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import textwrap
import difflib
import pygmt
import textwrap

import pygmt

# Raw GMT docstrings
gmt_doc = r"""
Select painting or dumping country polygons from the Digital Chart of the World.
This is another dataset independent of GSHHG and hence the **-A** and **-D** options do not apply.
Expand All @@ -25,6 +26,9 @@
If neither **-J** nor **-M** are set then we just print the **-R**\ *wesn* string.
"""

line_length = 79
indentation_length = 8 # 8 whitspaces for most docstrings

# function to document
function = pygmt.Figure.coast

Expand All @@ -34,7 +38,6 @@
for key, value in function.aliases.items():
pygmt_doc = pygmt_doc.replace(f"**-{key}**", f"**{value}**")


# output
diff = difflib.unified_diff(gmt_doc.splitlines(), pygmt_doc.splitlines(), lineterm="")
print("Diff view:\n")
Expand All @@ -46,6 +49,7 @@

print("Translate PyGMT docstring:\n")
pygmt_doc = textwrap.indent(
textwrap.fill(textwrap.dedent(pygmt_doc), width=72), " " * 8
textwrap.fill(textwrap.dedent(pygmt_doc), width=line_length - indentation_length),
" " * indentation_length,
)
print(pygmt_doc)