Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Suggest non-existing default filename (Implement #3608) #4221

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

Merged
merged 6 commits into from
Mar 17, 2015
Merged

Suggest non-existing default filename (Implement #3608) #4221

merged 6 commits into from
Mar 17, 2015

Conversation

umairidris
Copy link

No description provided.

@umairidris umairidris changed the title Suggest unexisting default filename (Implement #3608) Suggest non-existing default filename (Implement #3608) Mar 15, 2015
@tacaswell tacaswell added this to the next point release milestone Mar 15, 2015
i = 1
while os.path.isfile(os.path.join(save_dir, default_filename)):
# attach numerical value to basename
default_filename = '{}-{}.{}'.format(default_basename, i, default_filetype)
Copy link
Member

Choose a reason for hiding this comment

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

Can't use this type of string formatting. It was introduced in py2.7 and we support py2.6. You will need "{0}-{1}.{2}" instead.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the catch! It has been fixed via 4da2db8.

@tacaswell
Copy link
Member

Can you also add a test? I would suggest something like

import tempfile
@cleanup
def test_filename():
    test_dir = tempfile.mkdtemp()
    rcParams['saving.directory'] = test_dir
    target_name = os.path.join(test_dir, 'figure_1.png')
    target_name2 = os.path.join(test_dir, 'figure_1-1.png')
    fig = plt.figure()
    fn = fig.get_default_filename()
    assert_equal(fn, target_name)
    fig.save_fig(fn)
    fn2 = fig.get_default_filename()
    assert_equal(fn2, target_name2)

@umairidris
Copy link
Author

Done. Should the created temp directories/files be cleaned up after the test? From Python docs: "The user of mkdtemp() is responsible for deleting the temporary directory and its contents when done with it."

@tacaswell
Copy link
Member

Yes please to cleaning up the temp directory.

On Mon, Mar 16, 2015, 05:13 Umair Idris [email protected] wrote:

Done. Should the created temp directoies/files be cleaned up after the
test? From Python docs: "The user of mkdtemp() is responsible for deleting
the temporary directory and its contents when done with it."


Reply to this email directly or view it on GitHub
#4221 (comment)
.

@umairidris
Copy link
Author

Yes please to cleaning up the temp directory.

Done.

tacaswell added a commit that referenced this pull request Mar 17, 2015
ENH : Suggest non-existing default filename in gui save window

closes #3608
@tacaswell tacaswell merged commit 51576d4 into matplotlib:master Mar 17, 2015
@tacaswell
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants