Example #1
0
def _rewrite_env_path(filename, new_env_path):
    with open(filename, 'rb') as f:
        lines = f.read().decode('utf-8').splitlines()

    script = relative_script([new_env_path] + lines[1:])

    with open(filename, 'wb') as f:
        f.write('\n'.join(script).encode('utf-8'))
Example #2
0
def _rewrite_shebang(filename, new_shebang):
    """Replace the first line of the file with the new shebang"""
    with open(filename, 'rb') as f:
        lines = f.read().decode('utf-8').splitlines()

    script = relative_script([new_shebang] + lines[1:])

    with open(filename, 'wb') as f:
        f.write('\n'.join(script).encode('utf-8'))
Example #3
0
def _rewrite_shebang(filename, new_shebang):
    """Replace the first line of the file with the new shebang"""
    with open(filename, 'rb') as f:
        lines = f.read().decode('utf-8').splitlines()

    script = relative_script([new_shebang] + lines[1:])

    with open(filename, 'wb') as f:
        f.write('\n'.join(script).encode('utf-8'))
Example #4
0
def test_activate_after_future_statements():
    """Should insert activation line after last future statement"""
    script = [
        '#!/usr/bin/env python', 'from __future__ import with_statement',
        'from __future__ import print_function', 'print("Hello, world!")'
    ]
    assert virtualenv.relative_script(script) == [
        '#!/usr/bin/env python', 'from __future__ import with_statement',
        'from __future__ import print_function', '',
        "import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); execfile(activate_this, dict(__file__=activate_this)); del os, activate_this",
        '', 'print("Hello, world!")'
    ]
Example #5
0
def test_activate_after_future_statements():
    """Should insert activation line after last future statement"""
    script = [
        "#!/usr/bin/env python",
        "from __future__ import with_statement",
        "from __future__ import print_function",
        'print("Hello, world!")',
    ]
    assert virtualenv.relative_script(script) == [
        "#!/usr/bin/env python",
        "from __future__ import with_statement",
        "from __future__ import print_function",
        "",
        "import os; activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); exec(compile(open(activate_this).read(), activate_this, 'exec'), dict(__file__=activate_this)); del os, activate_this",
        "",
        'print("Hello, world!")',
    ]
def test_activate_after_future_statements():
    """Should insert activation line after last future statement"""
    script = [
        "#!/usr/bin/env python",
        "from __future__ import with_statement",
        "from __future__ import print_function",
        'print("Hello, world!")',
    ]
    assert virtualenv.relative_script(script) == [
        "#!/usr/bin/env python",
        "from __future__ import with_statement",
        "from __future__ import print_function",
        "",
        "import os; "
        "activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); "
        "exec(compile(open(activate_this).read(), activate_this, 'exec'), dict(__file__=activate_this)); "
        "del os, activate_this",
        "",
        'print("Hello, world!")',
    ]