Skip to content

Remove the support of non-aliased aliases in use_alias/fmt_docstrings #4042

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
32 changes: 1 addition & 31 deletions pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,7 @@ def fmt_docstring(module_func):
aliases.append(" :columns: 3\n")
for arg in sorted(module_func.aliases):
alias = module_func.aliases[arg]
# Trailing dash means it's not aliased but should be listed.
# Remove the trailing dash if it exists.
aliases.append(f" - {arg} = {alias.rstrip('-')}")
aliases.append(f" - {arg} = {alias}")
filler_text["aliases"] = "\n".join(aliases)

filler_text["table-classes"] = (
Expand Down Expand Up @@ -486,9 +484,6 @@ def _insert_alias(module_func, default_value=None):
kwargs_param = wrapped_params.pop(-1)
# Add new parameters from aliases
for alias in module_func.aliases.values():
if alias.endswith("-"):
# Trailing dash means it's not aliased but should be listed.
continue
if alias not in sig.parameters:
new_param = Parameter(
alias, kind=Parameter.KEYWORD_ONLY, default=default_value
Expand Down Expand Up @@ -553,31 +548,6 @@ def new_module(*args, **kwargs):
New module that parses and replaces the registered aliases.
"""
for short_param, long_alias in aliases.items():
if long_alias.endswith("-"):
_long_alias = long_alias.rstrip("-")
# Trailing dash means it's not aliased but should be listed.
_alias_list = _long_alias.split("/")
if (
any(_alias in kwargs for _alias in _alias_list)
and short_param in kwargs
): # Both long- and short- forms are given.
msg = (
f"Parameters in short-form ({short_param}) and "
f"long-form ({_long_alias}) can't coexist."
)
raise GMTInvalidInput(msg)
if short_param in kwargs: # Only short-alias is given
if len(_alias_list) > 1: # Aliased to multiple long-forms
msg = (
f"Short-form parameter ({short_param}) is not "
f"recognized. Use long-form parameter(s) "
f"'{_long_alias}' instead."
)
raise GMTInvalidInput(msg)
# If there is only one long-form parameter, use it.
kwargs[_long_alias] = kwargs.pop(short_param)
continue

if long_alias in kwargs and short_param in kwargs:
msg = (
f"Parameters in short-form ({short_param}) and "
Expand Down
4 changes: 2 additions & 2 deletions pygmt/src/meca.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def _auto_offset(spec) -> bool:
L="outline",
N="no_clip",
R="region",
S="scale/convention/component-",
T="nodal",
V="verbose",
W="pen",
Expand Down Expand Up @@ -202,7 +201,8 @@ def meca( # noqa: PLR0913
Full GMT docs at :gmt-docs:`supplements/seis/meca.html`.

{aliases}
- J=projection
- J = projection
- S = scale/convention/component

Parameters
----------
Expand Down
4 changes: 2 additions & 2 deletions pygmt/src/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
B="frame",
C="clearance",
D="offset",
F="position/angle/font/justify-",
G="fill",
N="no_clip",
V="verbose",
Expand Down Expand Up @@ -73,7 +72,8 @@ def text_( # noqa: PLR0912
Full GMT docs at :gmt-docs:`text.html`.

{aliases}
- J=projection
- F = **+a**: angle, **+c**: position, **+j**: justify, **+f**: font
- J = projection

Parameters
----------
Expand Down
1 change: 0 additions & 1 deletion pygmt/src/wiggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
@use_alias(
B="frame",
D="position",
G="fillpositive/fillnegative-",
R="region",
T="track",
V="verbose",
Expand Down
Loading