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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing arguments containing spaces into pygmt functions #1487

Merged
merged 23 commits into from
Mar 13, 2022
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b5ad405
Replace spaces in arguments with octal code 040
weiji14 Sep 7, 2021
14648c2
Remove workarounds for spaces in fig.subplot's autolabel and title args
weiji14 Sep 7, 2021
924f439
Remove workaround for spaces in fig.text's -F argument
weiji14 Sep 7, 2021
707745f
Remove double quotes around legend label test examples
weiji14 Sep 7, 2021
03e4308
Edit test_rose_no_sectors to remove single quotes from title
weiji14 Sep 7, 2021
095449a
Remove workaround for spaces in fig.psconvert prefix
weiji14 Sep 7, 2021
d81b80b
Format using blackdoc and fix flake8 error
weiji14 Sep 7, 2021
dd849cb
Merge branch 'main' into arg_with_space
weiji14 Jan 10, 2022
c29e632
Ensure spaces in pygmt.config arguments can work
weiji14 Jan 10, 2022
83c8c3b
Manually handle prefix -F in psconvert
weiji14 Jan 13, 2022
2ba8420
Merge branch 'main' into arg_with_space
weiji14 Jan 13, 2022
b58af8b
Merge branch 'main' into arg_with_space
weiji14 Mar 6, 2022
3ec7727
Handle PROJ4 strings with spaces
weiji14 Mar 6, 2022
f19c41b
Use Modifier Letter Colon instead of regular colon to fix WIndows tests
weiji14 Mar 6, 2022
7a518a1
Merge branch 'main' into arg_with_space
weiji14 Mar 7, 2022
9774d5e
Try using underscore instead of Modifier Letter Colon
weiji14 Mar 7, 2022
ff40d27
Refactor the whole function using a single loop
weiji14 Mar 10, 2022
36fdec5
Merge branch 'main' into arg_with_space
weiji14 Mar 10, 2022
6c399ba
Merge branch 'main' into arg_with_space
weiji14 Mar 11, 2022
4770396
Merge branch 'main' into arg_with_space
weiji14 Mar 12, 2022
801ba01
Raise GMTInvalidInput if no prefix argument is passed to psconvert
weiji14 Mar 13, 2022
ecb580e
Merge branch 'main' into arg_with_space
weiji14 Mar 13, 2022
a526d45
Fix rst syntax in pygmt/helpers/utils.py
weiji14 Mar 13, 2022
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
Next Next commit
Replace spaces in arguments with octal code 040
Modifying build_arg_string function to replace blank space
characters with octal code 040, and added a doctest to
check various combinations with single and double quotes
included.
  • Loading branch information
weiji14 committed Sep 7, 2021
commit b5ad4056ca0a39f9c98438c9722de0eaf7e0f5e6
17 changes: 14 additions & 3 deletions pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def dummy_context(arg):


def build_arg_string(kwargs):
"""
r"""
Transform keyword arguments into a GMT argument string.

Make sure all arguments have been previously converted to a string
Expand Down Expand Up @@ -159,6 +159,15 @@ def build_arg_string(kwargs):
... )
... )
-BWSen -Bxaf -Byaf -I1/1p,blue -I2/0.25p,blue -JX4i -R1/2/3/4
>>> print(
... build_arg_string(
... dict(
... B=["af", "WSne+tBlank Space"],
... F='+t"Empty Spaces"',
... l="'Void Space'"),
... )
... )
-BWSne+tBlank\040Space -Baf -F+t"Empty\040\040Spaces" -l'Void\040Space'
"""
gmt_args = []
# Exclude arguments that are None and False
Expand All @@ -168,11 +177,13 @@ def build_arg_string(kwargs):
for key in filtered_kwargs:
if is_nonstr_iter(kwargs[key]):
for value in kwargs[key]:
gmt_args.append(f"-{key}{value}")
_value = str(value).replace(" ", r"\040")
gmt_args.append(rf"-{key}{_value}")
elif kwargs[key] is True:
gmt_args.append(f"-{key}")
else:
gmt_args.append(f"-{key}{kwargs[key]}")
_value = str(kwargs[key]).replace(" ", r"\040")
gmt_args.append(rf"-{key}{_value}")
return " ".join(sorted(gmt_args))


Expand Down