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

Let Figure.savefig support filenames with spaces #1116

Merged
merged 9 commits into from
Jun 14, 2021
Merged

Conversation

seisman
Copy link
Member

@seisman seisman commented Mar 24, 2021

Description of proposed changes

Figure.savefig() doesn't work if filenames contain spaces.

Here is an minimal example to reproduce the issue:

import pygmt
fig = pygmt.Figure()
fig.basemap(projection="X10c/10c", frame=True, region=[0, 10, 0, 10])
fig.savefig("map 2.png")

This PR fixes the issue by adding double quotes around filenames.

NOTE: Using filenames with spaces is NOT recommended.
However, we have to support it, because sometimes filenames of some
baseline images must contain spaces.
See https://github.com/GenericMappingTools/pygmt/runs/2179626599 for an example failure.

Reminders

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst.
  • Write detailed docstrings for all functions/methods.
  • If adding new functionality, add an example to docstrings or tutorials.

Slash Commands

You can write slash commands (/command) in the first line of a comment to perform
specific operations. Supported slash commands are:

  • /format: automatically format and lint the code
  • /test-gmt-dev: run full tests on the latest GMT development version

@seisman seisman mentioned this pull request Mar 24, 2021
5 tasks
@seisman seisman marked this pull request as ready for review March 24, 2021 05:05
@seisman seisman added the bug Something isn't working label Mar 24, 2021
@seisman seisman added this to the 0.4.0 milestone Mar 24, 2021
@weiji14
Copy link
Member

weiji14 commented Mar 25, 2021

NOTE: Using filenames with spaces is NOT recommended.
However, we have to support it, because sometimes filenames of some
baseline images must contain spaces.

See my comment at #804 (comment) on how to fix the space issue. If the tests pass, do we still need this PR?

@seisman
Copy link
Member Author

seisman commented Mar 25, 2021

Nice fix in #804 (comment).

I think this PR is still needed for people who want to use spaces. It's allowed in GMT (https://docs.generic-mapping-tools.org/dev/begin.html#examples).

pygmt/figure.py Outdated Show resolved Hide resolved
@seisman
Copy link
Member Author

seisman commented Apr 1, 2021

@weiji14 Any other concerns?

@seisman
Copy link
Member Author

seisman commented May 9, 2021

Ping @GenericMappingTools/pygmt-contributors for comments if we should allow whitespace in figure names.

@core-man
Copy link
Member

core-man commented May 9, 2021

Ping @GenericMappingTools/pygmt-contributors for comments if we should allow whitespace in figure names.

I think so and this PR is simple enough.

Copy link
Member

@weiji14 weiji14 left a comment

Choose a reason for hiding this comment

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

I'm still reluctant to allow spaces since it adds an if-clause to the code, but ok with supporting it if three or more people agree.

pygmt/tests/test_figure.py Outdated Show resolved Hide resolved
@willschlitzer
Copy link
Contributor

Ping @GenericMappingTools/pygmt-contributors for comments if we should allow whitespace in figure names.

I think it is good to allow this. I'm glad there is the disclaimer that spaces in filenames isn't recommended, but better to increase compatibility.

@seisman seisman requested a review from a team June 10, 2021 15:56
@seisman seisman added final review call This PR requires final review and approval from a second reviewer and removed final review call This PR requires final review and approval from a second reviewer labels Jun 10, 2021
@seisman seisman merged commit 64a34d2 into master Jun 14, 2021
@seisman seisman deleted the filename-with-spaces branch June 14, 2021 05:29
sixy6e pushed a commit to sixy6e/pygmt that referenced this pull request Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants