Skip to content

Commit

Permalink
Merge pull request #1633 from takluyver/i1479
Browse files Browse the repository at this point in the history
Fix installing extension from local file on Windows.

Closes gh-1479
  • Loading branch information
takluyver committed Apr 23, 2012
2 parents e544c6d + 80f4581 commit add0161
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions IPython/core/extensions.py
Expand Up @@ -18,6 +18,7 @@
#-----------------------------------------------------------------------------

import os
from shutil import copyfile
import sys
from urllib import urlretrieve
from urlparse import urlparse
Expand Down Expand Up @@ -132,15 +133,25 @@ def install_extension(self, url, filename=None):
If filename is given, the file will be so named (inside the extension
directory). Otherwise, the name from the URL will be used. The file must
have a .py or .zip extension; otherwise, a ValueError will be raised.
Returns the full path to the installed file.
"""
# Ensure the extension directory exists
if not os.path.isdir(self.ipython_extension_dir):
os.makedirs(self.ipython_extension_dir, mode = 0777)

if os.path.isfile(url):
src_filename = os.path.basename(url)
copy = copyfile
else:
src_filename = urlparse(url).path.split('/')[-1]
copy = urlretrieve

if filename is None:
filename = urlparse(url).path.split('/')[-1]
filename = src_filename
if os.path.splitext(filename)[1] not in ('.py', '.zip'):
raise ValueError("The file must have a .py or .zip extension", filename)

filename = os.path.join(self.ipython_extension_dir, filename)
return urlretrieve(url, filename)
copy(url, filename)
return filename
2 changes: 1 addition & 1 deletion IPython/core/magic.py
Expand Up @@ -3456,7 +3456,7 @@ def magic_install_ext(self, parameter_s):
"""
opts, args = self.parse_options(parameter_s, 'n:')
try:
filename, headers = self.extension_manager.install_extension(args, opts.get('n'))
filename = self.extension_manager.install_extension(args, opts.get('n'))
except ValueError as e:
print e
return
Expand Down

0 comments on commit add0161

Please sign in to comment.