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

Handle a compound extension in new_untitled #2949

Merged
merged 5 commits into from Oct 20, 2017

Conversation

Projects
None yet
3 participants
@blink1073
Copy link
Member

blink1073 commented Oct 18, 2017

This allows file names with compound extensions (e.g. .tar.gz) to be properly incremented when creating a new file. Previously we would end up with untitled.tar1.gz.

cf jupyterlab/jupyterlab#3113

basename, ext = os.path.splitext(filename)
# Extract the full suffix from the filename (e.g. .tar.gz)
dirname = os.path.dirname(filename)
basename = os.path.basename(filename)

This comment has been minimized.

@takluyver

takluyver Oct 20, 2017

Member

This can be summarised as dirname, basename = os.path.split(filename).

Also, I think we should leave in the .strip('/') that was there before, so that passing in foo/bar/ gives you foo/bar1, not foo/bar/1.

basename = os.path.join(dirname, parts[0])
suffix = '.' + '.'.join(parts[1:])
if suffix == '.':
suffix = ''

This comment has been minimized.

@takluyver

takluyver Oct 20, 2017

Member

How about using str.partition():

name, dot, ext = basename.partition('.')
basename = os.path.join(dirname, name)
suffix = dot+ext

This comment has been minimized.

@blink1073

blink1073 Oct 20, 2017

Author Member

Thanks! Updated.

blink1073 added some commits Oct 20, 2017

if not self.exists(u'{}/{}'.format(path, name)):
name = u'{basename}{insert}{suffix}'.format(basename=basename,
insert=insert_i, suffix=suffix)
if not self.exists(os.path.join(path, name)):

This comment has been minimized.

@takluyver

takluyver Oct 20, 2017

Member

Ah, hang on. This function works with an API path, which is always / separated, rather than a platform-dependent native path. So using os.path.split and os.path.join is wrong here.

This comment has been minimized.

@blink1073

blink1073 Oct 20, 2017

Author Member

Updated. Looking again, filename should never have a directory in it.

blink1073 added some commits Oct 20, 2017

@takluyver takluyver added this to the 5.3 milestone Oct 20, 2017

@takluyver

This comment has been minimized.

Copy link
Member

takluyver commented Oct 20, 2017

Thanks, merging.

@takluyver takluyver merged commit c888b6a into jupyter:master Oct 20, 2017

4 checks passed

codecov/patch 100% of diff hit (target 0%)
Details
codecov/project Absolute coverage decreased by -0.09% but relative coverage increased by +20.88% compared to f763c03
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@blink1073

This comment has been minimized.

Copy link
Member Author

blink1073 commented Oct 20, 2017

Ha, that was easy, thanks for your patience ;).

@gnestor

This comment has been minimized.

Copy link
Contributor

gnestor commented Oct 26, 2017

@meeseeksdev backport to 5.2.1

meeseeksdev bot pushed a commit that referenced this pull request Oct 26, 2017

gnestor added a commit that referenced this pull request Oct 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.