Commit c2dfed9f authored by Reinout van Rees's avatar Reinout van Rees

Breaking after finding first import line.

Fixes a bug with multiple import lines. We want to insert ourselves after the
*first* found import line, not the last one...

Also simplified an if/else for when there's no import statement at all.
parent 2eefee6e
...@@ -1072,7 +1072,7 @@ def _distutils_script(path, dest, script_content, initialization, rsetup): ...@@ -1072,7 +1072,7 @@ def _distutils_script(path, dest, script_content, initialization, rsetup):
# The script doesn't follow distutil's rules. Ignore it. # The script doesn't follow distutil's rules. Ignore it.
return [] return []
lines = lines[1:] # Strip off the first hashbang line. lines = lines[1:] # Strip off the first hashbang line.
line_with_first_import = None line_with_first_import = len(lines)
for line_number, line in enumerate(lines): for line_number, line in enumerate(lines):
if not 'import' in line: if not 'import' in line:
continue continue
...@@ -1081,10 +1081,8 @@ def _distutils_script(path, dest, script_content, initialization, rsetup): ...@@ -1081,10 +1081,8 @@ def _distutils_script(path, dest, script_content, initialization, rsetup):
if '__future__' in line: if '__future__' in line:
continue continue
line_with_first_import = line_number line_with_first_import = line_number
if line_with_first_import is None: break
before = ''.join(lines)
after = ''
else:
before = ''.join(lines[:line_with_first_import]) before = ''.join(lines[:line_with_first_import])
after = ''.join(lines[line_with_first_import:]) after = ''.join(lines[line_with_first_import:])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment