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
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
Ensure spaces in pygmt.config arguments can work
Also added a regression test for
FORMAT_DATE_MAP="o dd".
  • Loading branch information
weiji14 committed Jan 10, 2022
commit c29e63229f6c46aeb47cfe068b9f6c959728f64a
2 changes: 1 addition & 1 deletion pygmt/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, **kwargs):
self.old_defaults[key] = lib.get_default(key)

# call gmt set to change GMT defaults
arg_str = " ".join([f"{key}={value}" for key, value in kwargs.items()])
arg_str = " ".join([f'{key}="{value}"' for key, value in kwargs.items()])
Copy link
Member Author

Choose a reason for hiding this comment

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

xref: https://forum.generic-mapping-tools.org/t/errors-in-pygmt-when-there-are-spaces-in-string-arguments/2494/3

Ok, I've fixed the FORMAT_DATE_MAP="o dd" issue reported in the forum by wrapping the arguments in double quotes here in commit c29e632. Didn't use \040 because o\040dd doesn't work. The problem with this solution is that the workaround suggested in the forum (use FORMAT_DATE_MAP='"o dd"') will break in PyGMT v0.6.0, but I think that's acceptable since that workaround isn't intuitive anyway.

with Session() as lib:
lib.call_module("set", arg_str)

Expand Down
4 changes: 4 additions & 0 deletions pygmt/tests/baseline/test_config_format_date_map.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
outs:
- md5: 3619720cdfcd857cbdbb49ed7fe6e930
size: 1392
path: test_config_format_date_map.png
19 changes: 19 additions & 0 deletions pygmt/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,25 @@ def test_config_font_annot():
return fig


@pytest.mark.mpl_image_compare
def test_config_format_date_map():
"""
Test that setting FORMAT_DATE_MAP config changes how the output date string
is plotted.
Note the space in 'o dd', this acts as a regression test for
https://github.com/GenericMappingTools/pygmt/issues/247.
"""
fig = Figure()
with config(FORMAT_DATE_MAP="o dd"):
fig.basemap(
region=["1969-7-21T", "1969-7-23T", 0, 1],
projection="X2.5c/0.1c",
frame=["sxa1D", "S"],
)
return fig


@pytest.mark.mpl_image_compare
def test_config_format_time_map():
"""
Expand Down