Skip to content

Commit

Permalink
Add back our changes from
Browse files Browse the repository at this point in the history
  • Loading branch information
Kami committed Apr 17, 2018
1 parent 3db71ee commit 340be0e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions dh_virtualenv/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,20 @@ def run_tests(self):
def find_script_files(self):
"""Find list of files containing python shebangs in the bin directory"""
command = ['grep', '-l', '-r', '-e',
r'^#!.*bin/\(env \)\?{0}'.format(_PYTHON_INTERPRETERS_REGEX),
r'^#!\(python\|.*bin/\(env \)\?{0}\)'.format(_PYTHON_INTERPRETERS_REGEX),
self.bin_dir]
grep_proc = subprocess.Popen(command, stdout=subprocess.PIPE)
files, stderr = grep_proc.communicate()
return files.decode('utf-8').strip().split('\n')

def fix_shebangs(self):
"""Translate /usr/bin/python and /usr/bin/env python shebang
lines to point to our virtualenv python.
"""
Translate shebang lines: '.*bin/python', '.*/bin/env python' and 'python'
to point to our virtualenv python.
"""
pythonpath = os.path.join(self.virtualenv_install_dir, 'bin/python')
for f in self.find_script_files():
regex = r's-^#!.*bin/\(env \)\?{names}\"\?-#!{pythonpath}-'\
regex = r's-^#!\(python\|.*bin/\(env \)\?{names}\"\?\)-#!{pythonpath}-'\
.format(names=_PYTHON_INTERPRETERS_REGEX, pythonpath=re.escape(pythonpath))
subprocess.check_call(['sed', '-i', regex, f])

Expand Down

0 comments on commit 340be0e

Please sign in to comment.