Skip to content

Commit

Permalink
allow --relocatable to work on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenney committed Mar 5, 2013
1 parent cd9fbfe commit 6dbfb99
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1695,14 +1695,20 @@ def make_environment_relocatable(home_dir):
'activate', 'activate.bat', 'activate_this.py']

def fixup_scripts(home_dir):
# This is what we expect at the top of scripts:
shebang = '#!%s/bin/python' % os.path.normcase(os.path.abspath(home_dir))
# This is what we'll put:
new_shebang = '#!/usr/bin/env python%s' % sys.version[:3]
interpreter_ext = ''

This comment has been minimized.

Copy link
@piotr-dobrogost

piotr-dobrogost Mar 6, 2013

Sorry for nitpicking but having some variables initialized outside if statement and others inside (bin_suffix) is not coherent. I would move this inside if statement.

if is_win:
comspec = os.path.normcase(os.environ.get('COMSPEC', 'cmd.exe'))
# This is what we'll put:
new_shebang = '#!%s /c python.exe' % comspec
bin_suffix = 'Scripts'

This comment has been minimized.

Copy link
@piotr-dobrogost

piotr-dobrogost Mar 6, 2013

At pypa#49 (comment) Sylvain Prat states "I guess the path_locations function have to be used here." I'm not sure if path_locations is still in the codebase but I guess there are already functions choosing the right path based on OS and it would be better to use them here instead of hardcoding the path.

This comment has been minimized.

Copy link
@jpenney

jpenney Mar 6, 2013

Author Owner

Are you referring to setting bin_suffix to 'bin' vs 'Scripts'? That was already hard-coded before. Is there a better way to get it?

EDIT: Oh I see. The path_locations function should return the proper bin_suffix. Let me see if I can get that working.

interpreter_ext = '.exe'
else:
# This is what we'll put:
new_shebang = '#!/usr/bin/env python%s' % (sys.version[:3])
bin_suffix = 'bin'
# This is what we expect at the top of scripts:
shebang = '#!%s' % os.path.normcase(os.path.join(
os.path.abspath(home_dir), bin_suffix, 'python%s' % interpreter_ext))
bin_dir = os.path.join(home_dir, bin_suffix)
home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
for filename in os.listdir(bin_dir):
Expand All @@ -1723,7 +1729,11 @@ def fixup_scripts(home_dir):
if not lines:
logger.warn('Script %s is an empty file' % filename)
continue
if not lines[0].strip().startswith(shebang):

old_shebang = lines[0].strip()
old_shebang = old_shebang[0:2] + os.path.normcase(old_shebang[2:])

if not old_shebang.startswith(shebang):
if os.path.basename(filename) in OK_ABS_SCRIPTS:
logger.debug('Cannot make script %s relative' % filename)
elif lines[0].strip() == new_shebang:
Expand Down

0 comments on commit 6dbfb99

Please sign in to comment.