virtualenv/web/virtualenv.py
author ymh <ymh.work@gmail.com>
Sun, 21 Jul 2024 18:54:00 +0200
changeset 127 982e67670c2f
parent 98 a14feef87fd7
permissions -rwxr-xr-x
add maintenance info
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/env python
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
     2
"""Create a "virtual" Python installation"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
     3
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
     4
# fmt: off
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
     5
import os  # isort:skip
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
     6
import sys  # isort:skip
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
     7
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
     8
# If we are running in a new interpreter to create a virtualenv,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
     9
# we do NOT want paths from our existing location interfering with anything,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    10
# So we remove this file's directory from sys.path - most likely to be
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    11
# the previous interpreter's site-packages. Solves #705, #763, #779
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    12
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    14
if os.environ.get("VIRTUALENV_INTERPRETER_RUNNING"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    15
    for path in sys.path[:]:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    16
        if os.path.realpath(os.path.dirname(__file__)) == os.path.realpath(path):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    17
            sys.path.remove(path)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    18
# fmt: on
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    20
import ast
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
import base64
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    22
import codecs
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    23
import contextlib
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    24
import distutils.spawn
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    25
import distutils.sysconfig
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    26
import errno
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    27
import glob
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    28
import logging
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    29
import optparse
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
import os
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
import re
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
import shutil
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    33
import struct
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    34
import subprocess
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    35
import sys
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
import tempfile
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    37
import textwrap
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    38
import zipfile
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
import zlib
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
from distutils.util import strtobool
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    41
from os.path import join
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
try:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    import ConfigParser
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
except ImportError:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    46
    # noinspection PyPep8Naming
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
    import configparser as ConfigParser
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    49
__version__ = "16.7.9"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    50
virtualenv_version = __version__  # legacy
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    51
DEBUG = os.environ.get("_VIRTUALENV_DEBUG", None) == "1"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    52
if sys.version_info < (2, 7):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    53
    print("ERROR: {}".format(sys.exc_info()[1]))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    54
    print("ERROR: this script requires Python 2.7 or greater.")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    55
    sys.exit(101)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    57
HERE = os.path.dirname(os.path.abspath(__file__))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    58
IS_ZIPAPP = os.path.isfile(HERE)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    59
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    60
try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    61
    # noinspection PyUnresolvedReferences,PyUnboundLocalVariable
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    62
    basestring
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    63
except NameError:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    64
    basestring = str
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    65
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    66
VERSION = "{}.{}".format(*sys.version_info)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    67
PY_VERSION = "python{}.{}".format(*sys.version_info)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    69
IS_PYPY = hasattr(sys, "pypy_version_info")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    70
IS_WIN = sys.platform == "win32"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    71
IS_CYGWIN = sys.platform == "cygwin"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    72
IS_DARWIN = sys.platform == "darwin"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    73
ABI_FLAGS = getattr(sys, "abiflags", "")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    74
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    75
USER_DIR = os.path.expanduser("~")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    76
if IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    77
    DEFAULT_STORAGE_DIR = os.path.join(USER_DIR, "virtualenv")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    79
    DEFAULT_STORAGE_DIR = os.path.join(USER_DIR, ".virtualenv")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    80
DEFAULT_CONFIG_FILE = os.path.join(DEFAULT_STORAGE_DIR, "virtualenv.ini")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    82
if IS_PYPY:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    83
    EXPECTED_EXE = "pypy"
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    85
    EXPECTED_EXE = "python"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    86
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    87
# Return a mapping of version -> Python executable
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    88
# Only provided for Windows, where the information in the registry is used
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    89
if not IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    90
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    91
    def get_installed_pythons():
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    92
        return {}
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    95
else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    96
    try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    97
        import winreg
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    98
    except ImportError:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
    99
        # noinspection PyUnresolvedReferences
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   100
        import _winreg as winreg
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   101
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   102
    def get_installed_pythons():
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   103
        final_exes = dict()
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   105
        # Grab exes from 32-bit registry view
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   106
        exes = _get_installed_pythons_for_view("-32", winreg.KEY_WOW64_32KEY)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   107
        # Grab exes from 64-bit registry view
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   108
        exes_64 = _get_installed_pythons_for_view("-64", winreg.KEY_WOW64_64KEY)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   109
        # Check if exes are unique
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   110
        if set(exes.values()) != set(exes_64.values()):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   111
            exes.update(exes_64)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   112
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   113
        # Create dict with all versions found
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   114
        for version, bitness in sorted(exes):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   115
            exe = exes[(version, bitness)]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   116
            # Add minor version (X.Y-32 or X.Y-64)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   117
            final_exes[version + bitness] = exe
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   118
            # Add minor extensionless version (X.Y); 3.2-64 wins over 3.2-32
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   119
            final_exes[version] = exe
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   120
            # Add major version (X-32 or X-64)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   121
            final_exes[version[0] + bitness] = exe
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   122
            # Add major extensionless version (X); 3.3-32 wins over 3.2-64
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   123
            final_exes[version[0]] = exe
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   124
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   125
        return final_exes
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   127
    def _get_installed_pythons_for_view(bitness, view):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   128
        exes = dict()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   129
        # If both system and current user installations are found for a
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   130
        # particular Python version, the current user one is used
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   131
        for key in (winreg.HKEY_LOCAL_MACHINE, winreg.HKEY_CURRENT_USER):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   132
            try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   133
                python_core = winreg.OpenKey(key, "Software\\Python\\PythonCore", 0, view | winreg.KEY_READ)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   134
            except WindowsError:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   135
                # No registered Python installations
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   136
                continue
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   137
            i = 0
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   138
            while True:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   139
                try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   140
                    version = winreg.EnumKey(python_core, i)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   141
                    i += 1
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   142
                    try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   143
                        at_path = winreg.QueryValue(python_core, "{}\\InstallPath".format(version))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   144
                    except WindowsError:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   145
                        continue
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   146
                    # Remove bitness from version
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   147
                    if version.endswith(bitness):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   148
                        version = version[: -len(bitness)]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   149
                    exes[(version, bitness)] = join(at_path, "python.exe")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   150
                except WindowsError:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   151
                    break
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   152
            winreg.CloseKey(python_core)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   153
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   154
        return exes
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   155
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   156
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   157
REQUIRED_MODULES = [
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   158
    "os",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   159
    "posix",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   160
    "posixpath",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   161
    "nt",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   162
    "ntpath",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   163
    "genericpath",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   164
    "fnmatch",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   165
    "locale",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   166
    "encodings",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   167
    "codecs",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   168
    "stat",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   169
    "UserDict",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   170
    "readline",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   171
    "copy_reg",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   172
    "types",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   173
    "re",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   174
    "sre",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   175
    "sre_parse",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   176
    "sre_constants",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   177
    "sre_compile",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   178
    "zlib",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   179
]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   180
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   181
REQUIRED_FILES = ["lib-dynload", "config"]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   182
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   183
MAJOR, MINOR = sys.version_info[:2]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   184
if MAJOR == 2:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   185
    if MINOR >= 6:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   186
        REQUIRED_MODULES.extend(["warnings", "linecache", "_abcoll", "abc"])
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   187
    if MINOR >= 7:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   188
        REQUIRED_MODULES.extend(["_weakrefset"])
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   189
elif MAJOR == 3:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
    # Some extra modules are needed for Python 3, but different ones
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
    # for different versions.
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   192
    REQUIRED_MODULES.extend(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   193
        [
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   194
            "_abcoll",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   195
            "warnings",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   196
            "linecache",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   197
            "abc",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   198
            "io",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   199
            "_weakrefset",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   200
            "copyreg",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   201
            "tempfile",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   202
            "random",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   203
            "__future__",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   204
            "collections",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   205
            "keyword",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   206
            "tarfile",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   207
            "shutil",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   208
            "struct",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   209
            "copy",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   210
            "tokenize",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   211
            "token",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   212
            "functools",
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
            "heapq",
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   214
            "bisect",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   215
            "weakref",
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
            "reprlib",
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   217
        ]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   218
    )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   219
    if MINOR >= 2:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   220
        REQUIRED_FILES[-1] = "config-{}".format(MAJOR)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   221
    if MINOR >= 3:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   222
        import sysconfig
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   224
        platform_dir = sysconfig.get_config_var("PLATDIR")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   225
        REQUIRED_FILES.append(platform_dir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   226
        REQUIRED_MODULES.extend(["base64", "_dummy_thread", "hashlib", "hmac", "imp", "importlib", "rlcompleter"])
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   227
    if MINOR >= 4:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   228
        REQUIRED_MODULES.extend(["operator", "_collections_abc", "_bootlocale"])
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   229
    if MINOR >= 6:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   230
        REQUIRED_MODULES.extend(["enum"])
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   231
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   232
if IS_PYPY:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
    # these are needed to correctly display the exceptions that may happen
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
    # during the bootstrap
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   235
    REQUIRED_MODULES.extend(["traceback", "linecache"])
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   236
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   237
    if MAJOR == 3:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   238
        # _functools is needed to import locale during stdio initialization and
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   239
        # needs to be copied on PyPy because it's not built in
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   240
        REQUIRED_MODULES.append("_functools")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   241
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
class Logger(object):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
    Logging object for use in command-line script.  Allows ranges of
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
    levels, to avoid some redundancy of displayed information.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
    DEBUG = logging.DEBUG
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
    INFO = logging.INFO
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   252
    NOTIFY = (logging.INFO + logging.WARN) / 2
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
    WARN = WARNING = logging.WARN
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
    ERROR = logging.ERROR
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
    FATAL = logging.FATAL
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
    LEVELS = [DEBUG, INFO, NOTIFY, WARN, ERROR, FATAL]
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
    def __init__(self, consumers):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
        self.consumers = consumers
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
        self.indent = 0
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
        self.in_progress = None
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
        self.in_progress_hanging = False
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
    def debug(self, msg, *args, **kw):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
        self.log(self.DEBUG, msg, *args, **kw)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   267
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
    def info(self, msg, *args, **kw):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
        self.log(self.INFO, msg, *args, **kw)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   270
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
    def notify(self, msg, *args, **kw):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
        self.log(self.NOTIFY, msg, *args, **kw)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   273
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
    def warn(self, msg, *args, **kw):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
        self.log(self.WARN, msg, *args, **kw)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   276
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
    def error(self, msg, *args, **kw):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   278
        self.log(self.ERROR, msg, *args, **kw)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   279
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
    def fatal(self, msg, *args, **kw):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
        self.log(self.FATAL, msg, *args, **kw)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   282
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
    def log(self, level, msg, *args, **kw):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
        if args:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
            if kw:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   286
                raise TypeError("You may give positional or keyword arguments, not both")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
        args = args or kw
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
        rendered = None
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
        for consumer_level, consumer in self.consumers:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
            if self.level_matches(level, consumer_level):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   291
                if self.in_progress_hanging and consumer in (sys.stdout, sys.stderr):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
                    self.in_progress_hanging = False
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   293
                    print("")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
                    sys.stdout.flush()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
                if rendered is None:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
                    if args:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
                        rendered = msg % args
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
                    else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
                        rendered = msg
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   300
                    rendered = " " * self.indent + rendered
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   301
                if hasattr(consumer, "write"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   302
                    consumer.write(rendered + "\n")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
                else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
                    consumer(rendered)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
    def start_progress(self, msg):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   307
        assert not self.in_progress, "Tried to start_progress({!r}) while in_progress {!r}".format(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   308
            msg, self.in_progress
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   309
        )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
        if self.level_matches(self.NOTIFY, self._stdout_level()):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   311
            print(msg)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
            sys.stdout.flush()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
            self.in_progress_hanging = True
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
        else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
            self.in_progress_hanging = False
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
        self.in_progress = msg
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   318
    def end_progress(self, msg="done."):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   319
        assert self.in_progress, "Tried to end_progress without start_progress"
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
        if self.stdout_level_matches(self.NOTIFY):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
            if not self.in_progress_hanging:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
                # Some message has been printed out since start_progress
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   323
                print("...{}{}".format(self.in_progress, msg))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
                sys.stdout.flush()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
            else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   326
                print(msg)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
                sys.stdout.flush()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
        self.in_progress = None
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
        self.in_progress_hanging = False
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
    def show_progress(self):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
        """If we are in a progress scope, and no log messages have been
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
        shown, write out another '.'"""
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
        if self.in_progress_hanging:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   335
            print(".")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
            sys.stdout.flush()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
    def stdout_level_matches(self, level):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
        """Returns true if a message at this level will go to stdout"""
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
        return self.level_matches(level, self._stdout_level())
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
    def _stdout_level(self):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
        """Returns the level that stdout runs at"""
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
        for level, consumer in self.consumers:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
            if consumer is sys.stdout:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
                return level
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
        return self.FATAL
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   349
    @staticmethod
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   350
    def level_matches(level, consumer_level):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
        """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
        >>> l = Logger([])
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
        >>> l.level_matches(3, 4)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
        False
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
        >>> l.level_matches(3, 2)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
        True
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
        >>> l.level_matches(slice(None, 3), 3)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
        False
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
        >>> l.level_matches(slice(None, 3), 2)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
        True
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
        >>> l.level_matches(slice(1, 3), 1)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
        True
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
        >>> l.level_matches(slice(2, 3), 1)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
        False
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
        """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
        if isinstance(level, slice):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
            start, stop = level.start, level.stop
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
            if start is not None and start > consumer_level:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
                return False
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
            if stop is not None and stop <= consumer_level:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
                return False
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
            return True
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
        else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
            return level >= consumer_level
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   376
    @classmethod
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
    def level_for_integer(cls, level):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
        levels = cls.LEVELS
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
        if level < 0:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
            return levels[0]
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
        if level >= len(levels):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
            return levels[-1]
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
        return levels[level]
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
# create a silent logger just to prevent this from being undefined
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
# will be overridden with requested verbosity main() is called.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
logger = Logger([(Logger.LEVELS[-1], sys.stdout)])
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   390
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   391
def mkdir(at_path):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   392
    if not os.path.exists(at_path):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   393
        logger.info("Creating %s", at_path)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   394
        os.makedirs(at_path)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
    else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   396
        logger.info("Directory %s already exists", at_path)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   397
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   399
def copy_file_or_folder(src, dest, symlink=True):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
    if os.path.isdir(src):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   401
        shutil.copytree(src, dest, symlink)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
    else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
        shutil.copy2(src, dest)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   405
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
def copyfile(src, dest, symlink=True):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
    if not os.path.exists(src):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
        # Some bad symlink in the src
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   409
        logger.warn("Cannot find file %s (bad symlink)", src)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
        return
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
    if os.path.exists(dest):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   412
        logger.debug("File %s already exists", dest)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
        return
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
    if not os.path.exists(os.path.dirname(dest)):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   415
        logger.info("Creating parent directories for %s", os.path.dirname(dest))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
        os.makedirs(os.path.dirname(dest))
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   417
    if symlink and hasattr(os, "symlink") and not IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   418
        logger.info("Symlinking %s", dest)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   419
        try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   420
            os.symlink(os.path.realpath(src), dest)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   421
        except (OSError, NotImplementedError):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   422
            logger.info("Symlinking failed, copying to %s", dest)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   423
            copy_file_or_folder(src, dest, symlink)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
    else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   425
        logger.info("Copying to %s", dest)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   426
        copy_file_or_folder(src, dest, symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   427
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
def writefile(dest, content, overwrite=True):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
    if not os.path.exists(dest):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   431
        logger.info("Writing %s", dest)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   432
        with open(dest, "wb") as f:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   433
            f.write(content.encode("utf-8"))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
        return
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
    else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   436
        with open(dest, "rb") as f:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   437
            c = f.read()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   438
        if c != content.encode("utf-8"):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
            if not overwrite:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   440
                logger.notify("File %s exists with different content; not overwriting", dest)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
                return
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   442
            logger.notify("Overwriting %s with new content", dest)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   443
            with open(dest, "wb") as f:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   444
                f.write(content.encode("utf-8"))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
        else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   446
            logger.info("Content %s already in place", dest)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   447
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   449
def rm_tree(folder):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   450
    if os.path.exists(folder):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   451
        logger.notify("Deleting tree %s", folder)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   452
        shutil.rmtree(folder)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
    else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   454
        logger.info("Do not need to delete %s; already gone", folder)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   455
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
def make_exe(fn):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   458
    if hasattr(os, "chmod"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   459
        old_mode = os.stat(fn).st_mode & 0xFFF  # 0o7777
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   460
        new_mode = (old_mode | 0x16D) & 0xFFF  # 0o555, 0o7777
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   461
        os.chmod(fn, new_mode)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   462
        logger.info("Changed mode of %s to %s", fn, oct(new_mode))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   465
def _find_file(filename, folders):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   466
    for folder in reversed(folders):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   467
        files = glob.glob(os.path.join(folder, filename))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   468
        if files and os.path.isfile(files[0]):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   469
            return True, files[0]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   470
    return False, filename
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   473
@contextlib.contextmanager
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   474
def virtualenv_support_dirs():
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   475
    """Context manager yielding either [virtualenv_support_dir] or []"""
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   477
    # normal filesystem installation
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   478
    if os.path.isdir(join(HERE, "virtualenv_support")):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   479
        yield [join(HERE, "virtualenv_support")]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   480
    elif IS_ZIPAPP:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   481
        tmpdir = tempfile.mkdtemp()
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
        try:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   483
            with zipfile.ZipFile(HERE) as zipf:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   484
                for member in zipf.namelist():
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   485
                    if os.path.dirname(member) == "virtualenv_support":
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   486
                        zipf.extract(member, tmpdir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   487
            yield [join(tmpdir, "virtualenv_support")]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   488
        finally:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   489
            shutil.rmtree(tmpdir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   490
    # probably a bootstrap script
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   491
    elif os.path.splitext(os.path.dirname(__file__))[0] != "virtualenv":
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   492
        try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   493
            # noinspection PyUnresolvedReferences
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
            import virtualenv
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
        except ImportError:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   496
            yield []
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
        else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   498
            yield [join(os.path.dirname(virtualenv.__file__), "virtualenv_support")]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   499
    # we tried!
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
    else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   501
        yield []
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
class UpdatingDefaultsHelpFormatter(optparse.IndentedHelpFormatter):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
    Custom help formatter for use in ConfigOptionParser that updates
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
    the defaults before expanding them, allowing them to show up correctly
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
    in the help listing
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
    """
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   510
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
    def expand_default(self, option):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
        if self.parser is not None:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
            self.parser.update_defaults(self.parser.defaults)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
        return optparse.IndentedHelpFormatter.expand_default(self, option)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
class ConfigOptionParser(optparse.OptionParser):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
    """
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   519
    Custom option parser which updates its defaults by checking the
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
    configuration files and environmental variables
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
    """
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   522
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
    def __init__(self, *args, **kwargs):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
        self.config = ConfigParser.RawConfigParser()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
        self.files = self.get_config_files()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
        self.config.read(self.files)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
        optparse.OptionParser.__init__(self, *args, **kwargs)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   529
    @staticmethod
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   530
    def get_config_files():
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   531
        config_file = os.environ.get("VIRTUALENV_CONFIG_FILE", False)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
        if config_file and os.path.exists(config_file):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
            return [config_file]
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   534
        return [DEFAULT_CONFIG_FILE]
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
    def update_defaults(self, defaults):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
        """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
        Updates the given defaults with values from the config files and
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
        the environ. Does a little special handling for certain types of
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
        options (lists).
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
        """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
        # Then go and look for the other sources of configuration:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
        config = {}
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
        # 1. config files
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   545
        config.update(dict(self.get_config_section("virtualenv")))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
        # 2. environmental variables
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
        config.update(dict(self.get_environ_vars()))
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
        # Then set the options with those values
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
        for key, val in config.items():
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   550
            key = key.replace("_", "-")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   551
            if not key.startswith("--"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   552
                key = "--{}".format(key)  # only prefer long opts
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
            option = self.get_option(key)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
            if option is not None:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
                # ignore empty values
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
                if not val:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
                    continue
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
                # handle multiline configs
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   559
                if option.action == "append":
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
                    val = val.split()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
                else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
                    option.nargs = 1
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   563
                if option.action == "store_false":
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   564
                    val = not strtobool(val)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   565
                elif option.action in ("store_true", "count"):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
                    val = strtobool(val)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
                try:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
                    val = option.convert_value(key, val)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
                except optparse.OptionValueError:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
                    e = sys.exc_info()[1]
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   571
                    print("An error occurred during configuration: {!r}".format(e))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
                    sys.exit(3)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
                defaults[option.dest] = val
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
        return defaults
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
    def get_config_section(self, name):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
        """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
        Get a section of a configuration
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
        """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
        if self.config.has_section(name):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
            return self.config.items(name)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
        return []
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   584
    def get_environ_vars(self, prefix="VIRTUALENV_"):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
        """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
        Returns a generator with all environmental vars with prefix VIRTUALENV
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
        """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
        for key, val in os.environ.items():
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
            if key.startswith(prefix):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   590
                yield (key.replace(prefix, "").lower(), val)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
    def get_default_values(self):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
        """
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   594
        Overriding to make updating the defaults after instantiation of
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
        the option parser possible, update_defaults() does the dirty work.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
        """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
        if not self.process_default_values:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
            # Old, pre-Optik 1.5 behaviour.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
            return optparse.Values(self.defaults)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   601
        defaults = self.update_defaults(self.defaults.copy())  # ours
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
        for option in self._get_all_options():
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
            default = defaults.get(option.dest)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
            if isinstance(default, basestring):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
                opt_str = option.get_opt_string()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
                defaults[option.dest] = option.check_value(opt_str, default)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
        return optparse.Values(defaults)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
def main():
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
    parser = ConfigOptionParser(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   612
        version=virtualenv_version, usage="%prog [OPTIONS] DEST_DIR", formatter=UpdatingDefaultsHelpFormatter()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   613
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
    parser.add_option(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   616
        "-v", "--verbose", action="count", dest="verbose", default=5 if DEBUG else 0, help="Increase verbosity."
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   617
    )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   618
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   619
    parser.add_option("-q", "--quiet", action="count", dest="quiet", default=0, help="Decrease verbosity.")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
    parser.add_option(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   622
        "-p",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   623
        "--python",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   624
        dest="python",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   625
        metavar="PYTHON_EXE",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   626
        help="The Python interpreter to use, e.g., --python=python3.5 will use the python3.5 "
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   627
        "interpreter to create the new environment.  The default is the interpreter that "
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   628
        "virtualenv was installed with ({})".format(sys.executable),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   629
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
    parser.add_option(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   632
        "--clear", dest="clear", action="store_true", help="Clear out the non-root install and start from scratch."
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   633
    )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   634
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   635
    parser.set_defaults(system_site_packages=False)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   636
    parser.add_option(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   637
        "--no-site-packages",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   638
        dest="system_site_packages",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   639
        action="store_false",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   640
        help="DEPRECATED. Retained only for backward compatibility. "
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   641
        "Not having access to global site-packages is now the default behavior.",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   642
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
    parser.add_option(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   645
        "--system-site-packages",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   646
        dest="system_site_packages",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   647
        action="store_true",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   648
        help="Give the virtual environment access to the global site-packages.",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   649
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
    parser.add_option(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   652
        "--always-copy",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   653
        dest="symlink",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   654
        action="store_false",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   655
        default=True,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   656
        help="Always copy files rather than symlinking.",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   657
    )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   658
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   659
    parser.add_option(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   660
        "--relocatable",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   661
        dest="relocatable",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   662
        action="store_true",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   663
        help="Make an EXISTING virtualenv environment relocatable. "
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   664
        "This fixes up scripts and makes all .pth files relative.",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   665
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
    parser.add_option(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   668
        "--no-setuptools",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   669
        dest="no_setuptools",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   670
        action="store_true",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   671
        help="Do not install setuptools in the new virtualenv.",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   672
    )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   673
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   674
    parser.add_option("--no-pip", dest="no_pip", action="store_true", help="Do not install pip in the new virtualenv.")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   675
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   676
    parser.add_option(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   677
        "--no-wheel", dest="no_wheel", action="store_true", help="Do not install wheel in the new virtualenv."
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   678
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
    parser.add_option(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   681
        "--extra-search-dir",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   682
        dest="search_dirs",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   683
        action="append",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   684
        metavar="DIR",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   685
        default=[],
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   686
        help="Directory to look for setuptools/pip distributions in. " "This option can be used multiple times.",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   687
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
    parser.add_option(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   690
        "--download",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   691
        dest="download",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   692
        default=True,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   693
        action="store_true",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   694
        help="Download pre-installed packages from PyPI.",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   695
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
    parser.add_option(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   698
        "--no-download",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   699
        "--never-download",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   700
        dest="download",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   701
        action="store_false",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   702
        help="Do not download pre-installed packages from PyPI.",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   703
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   705
    parser.add_option("--prompt", dest="prompt", help="Provides an alternative prompt prefix for this environment.")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
    parser.add_option(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   708
        "--setuptools",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   709
        dest="setuptools",
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
        action="store_true",
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   711
        help="DEPRECATED. Retained only for backward compatibility. This option has no effect.",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   712
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
    parser.add_option(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   715
        "--distribute",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   716
        dest="distribute",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   717
        action="store_true",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   718
        help="DEPRECATED. Retained only for backward compatibility. This option has no effect.",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   719
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   721
    parser.add_option(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   722
        "--unzip-setuptools",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   723
        action="store_true",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   724
        help="DEPRECATED.  Retained only for backward compatibility. This option has no effect.",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   725
    )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   726
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   727
    if "extend_parser" in globals():
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   728
        # noinspection PyUnresolvedReferences
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   729
        extend_parser(parser)  # noqa: F821
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
    options, args = parser.parse_args()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
    global logger
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   735
    if "adjust_options" in globals():
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   736
        # noinspection PyUnresolvedReferences
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   737
        adjust_options(options, args)  # noqa: F821
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
    verbosity = options.verbose - options.quiet
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   740
    logger = Logger([(Logger.level_for_integer(2 - verbosity), sys.stdout)])
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   741
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   742
    def should_reinvoke(options):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   743
        """Do we need to reinvoke ourself?"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   744
        # Did the user specify the --python option?
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   745
        if options.python and not os.environ.get("VIRTUALENV_INTERPRETER_RUNNING"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   746
            interpreter = resolve_interpreter(options.python)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   747
            if interpreter != sys.executable:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   748
                # The user specified a different interpreter, so we have to reinvoke.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   749
                return interpreter
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   751
        # At this point, we know the user wants to use sys.executable to create the
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   752
        # virtual environment. But on Windows, sys.executable may be a venv redirector,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   753
        # in which case we still need to locate the underlying actual interpreter, and
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   754
        # reinvoke using that.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   755
        if IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   756
            # OK. Now things get really fun...
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   757
            #
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   758
            # If we are running from a venv, with a redirector, then what happens is as
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   759
            # follows:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   760
            #
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   761
            #   1. The redirector sets __PYVENV_LAUNCHER__ in the environment to point
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   762
            #      to the redirector executable.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   763
            #   2. The redirector launches the "base" Python (from the home value in
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   764
            #      pyvenv.cfg).
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   765
            #   3. The base Python executable sees __PYVENV_LAUNCHER__ in the environment
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   766
            #      and sets sys.executable to that value.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   767
            #   4. If site.py gets run, it sees __PYVENV_LAUNCHER__, and sets
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   768
            #      sys._base_executable to _winapi.GetModuleFileName(0) and removes
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   769
            #      __PYVENV_LAUNCHER__.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   770
            #
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   771
            # Unfortunately, that final step (site.py) may not happen. There are 2 key
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   772
            # times when that is the case:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   773
            #
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   774
            #   1. Python 3.7.2, which had the redirector but not the site.py code.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   775
            #   2. Running a venv from a virtualenv, which uses virtualenv's custom
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   776
            #      site.py.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   777
            #
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   778
            # So, we check for sys._base_executable, but if it's not present and yet we
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   779
            # have __PYVENV_LAUNCHER__, we do what site.py would have done and get our
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   780
            # interpreter from GetModuleFileName(0). We also remove __PYVENV_LAUNCHER__
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   781
            # from the environment, to avoid loops (actually, mainly because site.py
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   782
            # does so, and my head hurts enough buy now that I just want to be safe!)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   783
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   784
            # In Python 3.7.4, the rules changed so that sys._base_executable is always
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   785
            # set. So we now only return sys._base_executable if it's set *and does not
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   786
            # match sys.executable* (we still have to check that it's set, as we need to
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   787
            # support Python 3.7.3 and earlier).
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   788
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   789
            # Phew.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   790
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   791
            if getattr(sys, "_base_executable", sys.executable) != sys.executable:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   792
                return sys._base_executable
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   793
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   794
            if "__PYVENV_LAUNCHER__" in os.environ:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   795
                import _winapi
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   796
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   797
                del os.environ["__PYVENV_LAUNCHER__"]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   798
                return _winapi.GetModuleFileName(0)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   799
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   800
        # We don't need to reinvoke
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   801
        return None
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   802
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   803
    interpreter = should_reinvoke(options)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   804
    if interpreter is None:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   805
        # We don't need to reinvoke - if the user asked us to, tell them why we
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   806
        # aren't.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   807
        if options.python:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   808
            logger.warn("Already using interpreter {}".format(sys.executable))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   809
    else:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
        env = os.environ.copy()
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   811
        logger.notify("Running virtualenv with interpreter {}".format(interpreter))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   812
        env["VIRTUALENV_INTERPRETER_RUNNING"] = "true"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   813
        # Remove the variable __PYVENV_LAUNCHER__ if it's present, as it causes the
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   814
        # interpreter to redirect back to the virtual environment.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   815
        if "__PYVENV_LAUNCHER__" in env:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   816
            del env["__PYVENV_LAUNCHER__"]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   817
        file = __file__
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   818
        if file.endswith(".pyc"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   819
            file = file[:-1]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   820
        elif IS_ZIPAPP:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   821
            file = HERE
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   822
        sub_process_call = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   823
        raise SystemExit(sub_process_call.wait())
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
    if not args:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   826
        print("You must provide a DEST_DIR")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
        parser.print_help()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
        sys.exit(2)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
    if len(args) > 1:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   830
        print("There must be only one argument: DEST_DIR (you gave {})".format(" ".join(args)))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
        parser.print_help()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
        sys.exit(2)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
    home_dir = args[0]
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   836
    if os.path.exists(home_dir) and os.path.isfile(home_dir):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   837
        logger.fatal("ERROR: File already exists and is not a directory.")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   838
        logger.fatal("Please provide a different path or delete the file.")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
        sys.exit(3)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   841
    if os.pathsep in home_dir:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   842
        logger.fatal("ERROR: target path contains the operating system path separator '{}'".format(os.pathsep))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   843
        logger.fatal("This is not allowed as would make the activation scripts unusable.".format(os.pathsep))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   844
        sys.exit(3)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   845
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   846
    if os.environ.get("WORKING_ENV"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   847
        logger.fatal("ERROR: you cannot run virtualenv while in a working env")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   848
        logger.fatal("Please deactivate your working env, then re-run this script")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   849
        sys.exit(3)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   850
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   851
    if "PYTHONHOME" in os.environ:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   852
        logger.warn("PYTHONHOME is set.  You *must* activate the virtualenv before using it")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   853
        del os.environ["PYTHONHOME"]
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
    if options.relocatable:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
        make_environment_relocatable(home_dir)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
        return
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   859
    with virtualenv_support_dirs() as search_dirs:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   860
        create_environment(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   861
            home_dir,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   862
            site_packages=options.system_site_packages,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   863
            clear=options.clear,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   864
            prompt=options.prompt,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   865
            search_dirs=search_dirs + options.search_dirs,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   866
            download=options.download,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   867
            no_setuptools=options.no_setuptools,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   868
            no_pip=options.no_pip,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   869
            no_wheel=options.no_wheel,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   870
            symlink=options.symlink,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   871
        )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   872
    if "after_install" in globals():
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   873
        # noinspection PyUnresolvedReferences
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   874
        after_install(options, home_dir)  # noqa: F821
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   877
def call_subprocess(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   878
    cmd,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   879
    show_stdout=True,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   880
    filter_stdout=None,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   881
    cwd=None,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   882
    raise_on_return_code=True,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   883
    extra_env=None,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   884
    remove_from_env=None,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   885
    stdin=None,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   886
):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
    cmd_parts = []
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
    for part in cmd:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
        if len(part) > 45:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   890
            part = part[:20] + "..." + part[-20:]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   891
        if " " in part or "\n" in part or '"' in part or "'" in part:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   892
            part = '"{}"'.format(part.replace('"', '\\"'))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   893
        if hasattr(part, "decode"):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
            try:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
                part = part.decode(sys.getdefaultencoding())
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
            except UnicodeDecodeError:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
                part = part.decode(sys.getfilesystemencoding())
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
        cmd_parts.append(part)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   899
    cmd_desc = " ".join(cmd_parts)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
    if show_stdout:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
        stdout = None
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
    else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
        stdout = subprocess.PIPE
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   904
    logger.debug("Running command {}".format(cmd_desc))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
    if extra_env or remove_from_env:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
        env = os.environ.copy()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
        if extra_env:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
            env.update(extra_env)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
        if remove_from_env:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   910
            for var_name in remove_from_env:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   911
                env.pop(var_name, None)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
    else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
        env = None
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
    try:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
        proc = subprocess.Popen(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   916
            cmd,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   917
            stderr=subprocess.STDOUT,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   918
            stdin=None if stdin is None else subprocess.PIPE,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   919
            stdout=stdout,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   920
            cwd=cwd,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   921
            env=env,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   922
        )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
    except Exception:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
        e = sys.exc_info()[1]
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   925
        logger.fatal("Error {} while executing command {}".format(e, cmd_desc))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
        raise
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
    all_output = []
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
    if stdout is not None:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   929
        if stdin is not None:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   930
            with proc.stdin:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   931
                proc.stdin.write(stdin)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   932
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
        encoding = sys.getdefaultencoding()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
        fs_encoding = sys.getfilesystemencoding()
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   935
        with proc.stdout as stdout:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   936
            while 1:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   937
                line = stdout.readline()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   938
                try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   939
                    line = line.decode(encoding)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   940
                except UnicodeDecodeError:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   941
                    line = line.decode(fs_encoding)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   942
                if not line:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   943
                    break
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   944
                line = line.rstrip()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   945
                all_output.append(line)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   946
                if filter_stdout:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   947
                    level = filter_stdout(line)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   948
                    if isinstance(level, tuple):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   949
                        level, line = level
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   950
                    logger.log(level, line)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   951
                    if not logger.stdout_level_matches(level):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   952
                        logger.show_progress()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   953
                else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   954
                    logger.info(line)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
    else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   956
        proc.communicate(stdin)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
    proc.wait()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
    if proc.returncode:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   959
        if raise_on_return_code:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
            if all_output:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   961
                logger.notify("Complete output from command {}:".format(cmd_desc))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   962
                logger.notify("\n".join(all_output) + "\n----------------------------------------")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   963
            raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
        else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   965
            logger.warn("Command {} had error code {}".format(cmd_desc, proc.returncode))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   966
    return all_output
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   967
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   968
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   969
def filter_install_output(line):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   970
    if line.strip().startswith("running"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   971
        return Logger.INFO
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   972
    return Logger.DEBUG
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   973
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   974
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   975
def find_wheels(projects, search_dirs):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   976
    """Find wheels from which we can import PROJECTS.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   977
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   978
    Scan through SEARCH_DIRS for a wheel for each PROJECT in turn. Return
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   979
    a list of the first wheel found for each PROJECT
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   980
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   981
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   982
    wheels = []
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   983
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   984
    # Look through SEARCH_DIRS for the first suitable wheel. Don't bother
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   985
    # about version checking here, as this is simply to get something we can
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   986
    # then use to install the correct version.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   987
    for project in projects:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   988
        for dirname in search_dirs:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   989
            # This relies on only having "universal" wheels available.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   990
            # The pattern could be tightened to require -py2.py3-none-any.whl.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   991
            files = glob.glob(os.path.join(dirname, "{}-*.whl".format(project)))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   992
            if files:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   993
                versions = list(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   994
                    reversed(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   995
                        sorted(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   996
                            [(tuple(int(i) for i in os.path.basename(f).split("-")[1].split(".")), f) for f in files]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   997
                        )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   998
                    )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
   999
                )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1000
                if project == "pip" and sys.version_info[0:2] == (3, 4):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1001
                    wheel = next(p for v, p in versions if v <= (19, 1, 1))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1002
                else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1003
                    wheel = versions[0][1]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1004
                wheels.append(wheel)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1005
                break
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1006
        else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1007
            # We're out of luck, so quit with a suitable error
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1008
            logger.fatal("Cannot find a wheel for {}".format(project))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1009
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1010
    return wheels
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1011
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1012
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1013
def install_wheel(project_names, py_executable, search_dirs=None, download=False):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1014
    if search_dirs is None:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1015
        search_dirs_context = virtualenv_support_dirs
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1016
    else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1017
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1018
        @contextlib.contextmanager
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1019
        def search_dirs_context():
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1020
            yield search_dirs
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1021
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1022
    with search_dirs_context() as search_dirs:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1023
        _install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1026
def _install_wheel_with_search_dir(download, project_names, py_executable, search_dirs):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1027
    wheels = find_wheels(["setuptools", "pip"], search_dirs)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1028
    python_path = os.pathsep.join(wheels)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1029
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1030
    # PIP_FIND_LINKS uses space as the path separator and thus cannot have paths
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1031
    # with spaces in them. Convert any of those to local file:// URL form.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1032
    try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1033
        from urlparse import urljoin
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1034
        from urllib import pathname2url
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1035
    except ImportError:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1036
        from urllib.parse import urljoin
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1037
        from urllib.request import pathname2url
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1038
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1039
    def space_path2url(p):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1040
        if " " not in p:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1041
            return p
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1042
        return urljoin("file:", pathname2url(os.path.abspath(p)))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1043
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1044
    find_links = " ".join(space_path2url(d) for d in search_dirs)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1045
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1046
    extra_args = ["--ignore-installed", "-v"]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1047
    if DEBUG:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1048
        extra_args.append("-v")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1049
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1050
    config = _pip_config(py_executable, python_path)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1051
    defined_cert = bool(config.get("install.cert") or config.get(":env:.cert") or config.get("global.cert"))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1052
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1053
    script = textwrap.dedent(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1054
        """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1055
        import sys
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1056
        import pkgutil
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1057
        import tempfile
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1058
        import os
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1059
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1060
        defined_cert = {defined_cert}
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1061
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1062
        try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1063
            from pip._internal import main as _main
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1064
            if type(_main) is type(sys):  # <type 'module'>
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1065
                _main = _main.main  # nested starting in Pip 19.3
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1066
            cert_data = pkgutil.get_data("pip._vendor.certifi", "cacert.pem")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1067
        except ImportError:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1068
            from pip import main as _main
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1069
            cert_data = pkgutil.get_data("pip._vendor.requests", "cacert.pem")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1070
        except IOError:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1071
            cert_data = None
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1072
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1073
        if not defined_cert and cert_data is not None:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1074
            cert_file = tempfile.NamedTemporaryFile(delete=False)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1075
            cert_file.write(cert_data)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1076
            cert_file.close()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1077
        else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1078
            cert_file = None
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1079
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1080
        try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1081
            args = ["install"] + [{extra_args}]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1082
            if cert_file is not None:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1083
                args += ["--cert", cert_file.name]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1084
            args += sys.argv[1:]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1085
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1086
            sys.exit(_main(args))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1087
        finally:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1088
            if cert_file is not None:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1089
                os.remove(cert_file.name)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1090
    """.format(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1091
            defined_cert=defined_cert, extra_args=", ".join(repr(i) for i in extra_args)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1092
        )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1093
    ).encode("utf8")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1094
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1095
    if sys.version_info[0:2] == (3, 4) and "pip" in project_names:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1096
        at = project_names.index("pip")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1097
        project_names[at] = "pip<19.2"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1098
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1099
    cmd = [py_executable, "-"] + project_names
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1100
    logger.start_progress("Installing {}...".format(", ".join(project_names)))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1101
    logger.indent += 2
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1102
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1103
    env = {
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1104
        "PYTHONPATH": python_path,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1105
        "PIP_FIND_LINKS": find_links,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1106
        "PIP_USE_WHEEL": "1",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1107
        "PIP_ONLY_BINARY": ":all:",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1108
        "PIP_USER": "0",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1109
        "PIP_NO_INPUT": "1",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1110
    }
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1111
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1112
    if not download:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1113
        env["PIP_NO_INDEX"] = "1"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1114
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1115
    try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1116
        call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1117
    finally:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1118
        logger.indent -= 2
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1119
        logger.end_progress()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1120
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1121
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1122
def _pip_config(py_executable, python_path):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1123
    cmd = [py_executable, "-m", "pip", "config", "list"]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1124
    config = {}
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1125
    for line in call_subprocess(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1126
        cmd,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1127
        show_stdout=False,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1128
        extra_env={"PYTHONPATH": python_path},
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1129
        remove_from_env=["PIP_VERBOSE", "PIP_QUIET"],
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1130
        raise_on_return_code=False,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1131
    ):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1132
        key, _, value = line.partition("=")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1133
        if value:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1134
            config[key] = ast.literal_eval(value)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1135
    return config
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1136
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1137
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1138
def create_environment(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1139
    home_dir,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1140
    site_packages=False,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1141
    clear=False,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1142
    prompt=None,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1143
    search_dirs=None,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1144
    download=False,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1145
    no_setuptools=False,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1146
    no_pip=False,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1147
    no_wheel=False,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1148
    symlink=True,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1149
):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1150
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1151
    Creates a new environment in ``home_dir``.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1152
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1153
    If ``site_packages`` is true, then the global ``site-packages/``
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1154
    directory will be on the path.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1155
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
    If ``clear`` is true (default False) then the environment will
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
    first be cleared.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
    home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1161
    py_executable = os.path.abspath(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1162
        install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1163
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
    install_distutils(home_dir)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1167
    to_install = []
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1168
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1169
    if not no_setuptools:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1170
        to_install.append("setuptools")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1172
    if not no_pip:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1173
        to_install.append("pip")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1174
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1175
    if not no_wheel:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1176
        to_install.append("wheel")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1177
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1178
    if to_install:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1179
        install_wheel(to_install, py_executable, search_dirs, download=download)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1181
    install_activate(home_dir, bin_dir, prompt)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1182
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1183
    install_python_config(home_dir, bin_dir, prompt)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1184
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1185
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1186
def is_executable_file(fpath):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1187
    return os.path.isfile(fpath) and is_executable(fpath)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1188
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1189
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1190
def path_locations(home_dir, dry_run=False):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1191
    """Return the path locations for the environment (where libraries are,
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1192
    where scripts go, etc)"""
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1193
    home_dir = os.path.abspath(home_dir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1194
    lib_dir, inc_dir, bin_dir = None, None, None
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1195
    # XXX: We'd use distutils.sysconfig.get_python_inc/lib but its
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1196
    # prefix arg is broken: http://bugs.python.org/issue3386
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1197
    if IS_WIN:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1198
        # Windows has lots of problems with executables with spaces in
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1199
        # the name; this function will remove them (using the ~1
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1200
        # format):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1201
        if not dry_run:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1202
            mkdir(home_dir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1203
        if " " in home_dir:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1204
            import ctypes
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1205
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1206
            get_short_path_name = ctypes.windll.kernel32.GetShortPathNameW
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1207
            size = max(len(home_dir) + 1, 256)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1208
            buf = ctypes.create_unicode_buffer(size)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1209
            try:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1210
                # noinspection PyUnresolvedReferences
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1211
                u = unicode
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1212
            except NameError:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1213
                u = str
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1214
            ret = get_short_path_name(u(home_dir), buf, size)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1215
            if not ret:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1216
                print('Error: the path "{}" has a space in it'.format(home_dir))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1217
                print("We could not determine the short pathname for it.")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1218
                print("Exiting.")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1219
                sys.exit(3)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1220
            home_dir = str(buf.value)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1221
        lib_dir = join(home_dir, "Lib")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1222
        inc_dir = join(home_dir, "Include")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1223
        bin_dir = join(home_dir, "Scripts")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1224
    if IS_PYPY:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1225
        lib_dir = home_dir
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1226
        inc_dir = join(home_dir, "include")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1227
        bin_dir = join(home_dir, "bin")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1228
    elif not IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1229
        lib_dir = join(home_dir, "lib", PY_VERSION)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1230
        inc_dir = join(home_dir, "include", PY_VERSION + ABI_FLAGS)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1231
        bin_dir = join(home_dir, "bin")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1232
    return home_dir, lib_dir, inc_dir, bin_dir
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
def change_prefix(filename, dst_prefix):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
    prefixes = [sys.prefix]
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1238
    if IS_DARWIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1239
        prefixes.extend(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1240
            (
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1241
                os.path.join("/Library/Python", VERSION, "site-packages"),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1242
                os.path.join(sys.prefix, "Extras", "lib", "python"),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1243
                os.path.join("~", "Library", "Python", VERSION, "site-packages"),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1244
                # Python 2.6 no-frameworks
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1245
                os.path.join("~", ".local", "lib", "python", VERSION, "site-packages"),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1246
                # System Python 2.7 on OSX Mountain Lion
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1247
                os.path.join("~", "Library", "Python", VERSION, "lib", "python", "site-packages"),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1248
            )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1249
        )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1251
    if hasattr(sys, "real_prefix"):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
        prefixes.append(sys.real_prefix)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1253
    if hasattr(sys, "base_prefix"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1254
        prefixes.append(sys.base_prefix)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1255
    prefixes = list(map(os.path.expanduser, prefixes))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
    prefixes = list(map(os.path.abspath, prefixes))
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1257
    # Check longer prefixes first so we don't split in the middle of a filename
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1258
    prefixes = sorted(prefixes, key=len, reverse=True)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
    filename = os.path.abspath(filename)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1260
    # On Windows, make sure drive letter is uppercase
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1261
    if IS_WIN and filename[0] in "abcdefghijklmnopqrstuvwxyz":
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1262
        filename = filename[0].upper() + filename[1:]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1263
    for i, prefix in enumerate(prefixes):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1264
        if IS_WIN and prefix[0] in "abcdefghijklmnopqrstuvwxyz":
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1265
            prefixes[i] = prefix[0].upper() + prefix[1:]
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
    for src_prefix in prefixes:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
        if filename.startswith(src_prefix):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1268
            _, relative_path = filename.split(src_prefix, 1)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1269
            if src_prefix != os.sep:  # sys.prefix == "/"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1270
                assert relative_path[0] == os.sep
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1271
                relative_path = relative_path[1:]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1272
            return join(dst_prefix, relative_path)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1273
    raise AssertionError("Filename {} does not start with any of these prefixes: {}".format(filename, prefixes))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1274
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1275
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1276
def find_module_filename(modname):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1277
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1278
    if sys.version_info < (3, 4):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1279
        # noinspection PyDeprecation
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1280
        import imp
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1281
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1282
        try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1283
            file_handler, filepath, _ = imp.find_module(modname)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1284
        except ImportError:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1285
            return None
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1286
        else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1287
            if file_handler is not None:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1288
                file_handler.close()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1289
            return filepath
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1290
    else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1291
        import importlib.util
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1292
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1293
        if sys.version_info < (3, 5):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1294
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1295
            def find_spec(modname):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1296
                # noinspection PyDeprecation
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1297
                loader = importlib.find_loader(modname)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1298
                if loader is None:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1299
                    return None
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1300
                else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1301
                    return importlib.util.spec_from_loader(modname, loader)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1302
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1303
        else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1304
            find_spec = importlib.util.find_spec
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1305
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1306
        spec = find_spec(modname)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1307
        if spec is None:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1308
            return None
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1309
        if not os.path.exists(spec.origin):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1310
            # https://bitbucket.org/pypy/pypy/issues/2944/origin-for-several-builtin-modules
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1311
            # on pypy3, some builtin modules have a bogus build-time file path, ignore them
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1312
            return None
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1313
        filepath = spec.origin
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1314
        # https://www.python.org/dev/peps/pep-3147/#file guarantee to be non-cached
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1315
        if os.path.basename(filepath) == "__init__.py":
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1316
            filepath = os.path.dirname(filepath)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1317
        return filepath
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1318
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1320
def copy_required_modules(dst_prefix, symlink):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1321
    for modname in REQUIRED_MODULES:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1322
        if modname in sys.builtin_module_names:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1323
            logger.info("Ignoring built-in bootstrap module: %s" % modname)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1324
            continue
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1325
        filename = find_module_filename(modname)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1326
        if filename is None:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1327
            logger.info("Cannot import bootstrap module: %s" % modname)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1328
        else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1329
            # special-case custom readline.so on OS X, but not for pypy:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1330
            if (
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1331
                modname == "readline"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1332
                and IS_DARWIN
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1333
                and not (IS_PYPY or filename.endswith(join("lib-dynload", "readline.so")))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1334
            ):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1335
                dst_filename = join(dst_prefix, "lib", PY_VERSION, "readline.so")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1336
            elif modname == "readline" and IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1337
                # special-case for Windows, where readline is not a standard module, though it may have been installed
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1338
                # in site-packages by a third-party package
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1339
                dst_filename = None
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
            else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
                dst_filename = change_prefix(filename, dst_prefix)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1342
            if dst_filename is not None:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1343
                copyfile(filename, dst_filename, symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1344
            if filename.endswith(".pyc"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1345
                py_file = filename[:-1]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1346
                if os.path.exists(py_file):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1347
                    copyfile(py_file, dst_filename[:-1], symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1348
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1349
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1350
def copy_required_files(src_dir, lib_dir, symlink):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1351
    if not os.path.isdir(src_dir):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1352
        return
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1353
    for fn in os.listdir(src_dir):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1354
        bn = os.path.splitext(fn)[0]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1355
        if fn != "site-packages" and bn in REQUIRED_FILES:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1356
            copyfile(join(src_dir, fn), join(lib_dir, fn), symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1357
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1358
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1359
def copy_license(prefix, dst_prefix, lib_dir, symlink):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1360
    """Copy the license file so `license()` builtin works"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1361
    lib64_dir = lib_dir.replace("lib", "lib64")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1362
    for license_path in (
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1363
        # posix cpython
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1364
        os.path.join(prefix, os.path.relpath(lib_dir, dst_prefix), "LICENSE.txt"),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1365
        # posix cpython installed in /usr/lib64
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1366
        os.path.join(prefix, os.path.relpath(lib64_dir, dst_prefix), "LICENSE.txt"),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1367
        # windows cpython
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1368
        os.path.join(prefix, "LICENSE.txt"),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1369
        # pypy
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1370
        os.path.join(prefix, "LICENSE"),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1371
    ):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1372
        if os.path.exists(license_path):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1373
            dest = subst_path(license_path, prefix, dst_prefix)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1374
            copyfile(license_path, dest, symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1375
            return
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1376
    logger.warn("No LICENSE.txt / LICENSE found in source")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1378
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1379
def copy_include_dir(include_src, include_dest, symlink):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1380
    """Copy headers from *include_src* to *include_dest* symlinking if required"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1381
    if not os.path.isdir(include_src):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1382
        return
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1383
    # PyPy headers are located in ``pypy-dir/include`` and following code
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1384
    # avoids making ``venv-dir/include`` symlink to it
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1385
    if IS_PYPY:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1386
        for fn in os.listdir(include_src):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1387
            copyfile(join(include_src, fn), join(include_dest, fn), symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1388
    else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1389
        copyfile(include_src, include_dest, symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1390
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1391
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1392
def copy_tcltk(src, dest, symlink):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1393
    """ copy tcl/tk libraries on Windows (issue #93) """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1394
    for lib_version in "8.5", "8.6":
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1395
        for libname in "tcl", "tk":
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1396
            src_dir = join(src, "tcl", libname + lib_version)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1397
            dest_dir = join(dest, "tcl", libname + lib_version)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1398
            # Only copy the dirs from the above combinations that exist
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1399
            if os.path.exists(src_dir) and not os.path.exists(dest_dir):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1400
                copy_file_or_folder(src_dir, dest_dir, symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1401
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1402
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1403
def subst_path(prefix_path, prefix, home_dir):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1404
    prefix_path = os.path.normpath(prefix_path)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1405
    prefix = os.path.normpath(prefix)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1406
    home_dir = os.path.normpath(home_dir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1407
    if not prefix_path.startswith(prefix):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1408
        logger.warn("Path not in prefix %r %r", prefix_path, prefix)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1409
        return
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1410
    return prefix_path.replace(prefix, home_dir, 1)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1411
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1412
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1413
def install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages, clear, symlink=True):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1414
    """Install just the base environment, no distutils patches etc"""
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
    if sys.executable.startswith(bin_dir):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1416
        print("Please use the *system* python to run this script")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
        return
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1418
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
    if clear:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1420
        rm_tree(lib_dir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1421
        # FIXME: why not delete it?
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1422
        # Maybe it should delete everything with #!/path/to/venv/python in it
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1423
        logger.notify("Not deleting %s", bin_dir)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1425
    if hasattr(sys, "real_prefix"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1426
        logger.notify("Using real prefix %r", sys.real_prefix)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
        prefix = sys.real_prefix
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1428
    elif hasattr(sys, "base_prefix"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1429
        logger.notify("Using base prefix %r", sys.base_prefix)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1430
        prefix = sys.base_prefix
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
    else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
        prefix = sys.prefix
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1433
    prefix = os.path.abspath(prefix)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
    mkdir(lib_dir)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1435
    fix_lib64(lib_dir, symlink)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
    stdlib_dirs = [os.path.dirname(os.__file__)]
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1437
    if IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1438
        stdlib_dirs.append(join(os.path.dirname(stdlib_dirs[0]), "DLLs"))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1439
    elif IS_DARWIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1440
        stdlib_dirs.append(join(stdlib_dirs[0], "site-packages"))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1441
    if hasattr(os, "symlink"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1442
        logger.info("Symlinking Python bootstrap modules")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1443
    else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1444
        logger.info("Copying Python bootstrap modules")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1445
    logger.indent += 2
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1446
    try:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1447
        # copy required files...
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1448
        for stdlib_dir in stdlib_dirs:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1449
            copy_required_files(stdlib_dir, lib_dir, symlink)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1450
        # ...and modules
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1451
        copy_required_modules(home_dir, symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1452
        copy_license(prefix, home_dir, lib_dir, symlink)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1453
    finally:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1454
        logger.indent -= 2
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1455
    # ...copy tcl/tk
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1456
    if IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1457
        copy_tcltk(prefix, home_dir, symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1458
    mkdir(join(lib_dir, "site-packages"))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1459
    import site
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1460
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1461
    site_filename = site.__file__
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1462
    if site_filename.endswith(".pyc") or site_filename.endswith(".pyo"):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1463
        site_filename = site_filename[:-1]
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1464
    elif site_filename.endswith("$py.class"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1465
        site_filename = site_filename.replace("$py.class", ".py")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1466
    site_filename_dst = change_prefix(site_filename, home_dir)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1467
    site_dir = os.path.dirname(site_filename_dst)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
    writefile(site_filename_dst, SITE_PY)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1469
    writefile(join(site_dir, "orig-prefix.txt"), prefix)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1470
    site_packages_filename = join(site_dir, "no-global-site-packages.txt")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1471
    if not site_packages:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1472
        writefile(site_packages_filename, "")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1473
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1474
    if IS_PYPY or IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1475
        standard_lib_include_dir = join(prefix, "include")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1476
    else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1477
        standard_lib_include_dir = join(prefix, "include", PY_VERSION + ABI_FLAGS)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1478
    if os.path.exists(standard_lib_include_dir):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1479
        copy_include_dir(standard_lib_include_dir, inc_dir, symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1480
    else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1481
        logger.debug("No include dir %s", standard_lib_include_dir)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1482
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1483
    platform_include_dir = distutils.sysconfig.get_python_inc(plat_specific=1)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1484
    if platform_include_dir != standard_lib_include_dir:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1485
        platform_include_dest = distutils.sysconfig.get_python_inc(plat_specific=1, prefix=home_dir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1486
        if platform_include_dir == platform_include_dest:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1487
            # Do platinc_dest manually due to a CPython bug;
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1488
            # not http://bugs.python.org/issue3386 but a close cousin
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1489
            platform_include_dest = subst_path(platform_include_dir, prefix, home_dir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1490
        if platform_include_dest:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1491
            # PyPy's stdinc_dir and prefix are relative to the original binary
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1492
            # (traversing virtualenvs), whereas the platinc_dir is relative to
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1493
            # the inner virtualenv and ignores the prefix argument.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1494
            # This seems more evolved than designed.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1495
            copy_include_dir(platform_include_dir, platform_include_dest, symlink)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1496
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1497
    # pypy never uses exec_prefix, just ignore it
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1498
    if os.path.realpath(sys.exec_prefix) != os.path.realpath(prefix) and not IS_PYPY:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1499
        if IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1500
            exec_dir = join(sys.exec_prefix, "lib")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1501
        else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1502
            exec_dir = join(sys.exec_prefix, "lib", PY_VERSION)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1503
        copy_required_files(exec_dir, lib_dir, symlink)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1504
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1505
    mkdir(bin_dir)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
    py_executable = join(bin_dir, os.path.basename(sys.executable))
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1507
    if "Python.framework" in prefix or "Python3.framework" in prefix:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1508
        # OS X framework builds cause validation to break
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1509
        # https://github.com/pypa/virtualenv/issues/322
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1510
        if os.environ.get("__PYVENV_LAUNCHER__"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1511
            del os.environ["__PYVENV_LAUNCHER__"]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1512
        if re.search(r"/Python(?:-32|-64)*$", py_executable):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1513
            # The name of the python executable is not quite what
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1514
            # we want, rename it.
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1515
            py_executable = os.path.join(os.path.dirname(py_executable), "python")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1517
    logger.notify("New %s executable in %s", EXPECTED_EXE, py_executable)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1518
    pc_build_dir = os.path.dirname(sys.executable)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1519
    pyd_pth = os.path.join(lib_dir, "site-packages", "virtualenv_builddir_pyd.pth")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1520
    if IS_WIN and os.path.exists(os.path.join(pc_build_dir, "build.bat")):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1521
        logger.notify("Detected python running from build directory %s", pc_build_dir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1522
        logger.notify("Writing .pth file linking to build directory for *.pyd files")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1523
        writefile(pyd_pth, pc_build_dir)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1524
    else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1525
        if os.path.exists(pyd_pth):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1526
            logger.info("Deleting %s (not Windows env or not build directory python)", pyd_pth)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
            os.unlink(pyd_pth)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1528
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
    if sys.executable != py_executable:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1530
        # FIXME: could I just hard link?
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1531
        executable = sys.executable
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1532
        shutil.copyfile(executable, py_executable)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1533
        make_exe(py_executable)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1534
        if IS_WIN or IS_CYGWIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1535
            python_w = os.path.join(os.path.dirname(sys.executable), "pythonw.exe")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1536
            if os.path.exists(python_w):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1537
                logger.info("Also created pythonw.exe")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1538
                shutil.copyfile(python_w, os.path.join(os.path.dirname(py_executable), "pythonw.exe"))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1539
            python_d = os.path.join(os.path.dirname(sys.executable), "python_d.exe")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1540
            python_d_dest = os.path.join(os.path.dirname(py_executable), "python_d.exe")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
            if os.path.exists(python_d):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1542
                logger.info("Also created python_d.exe")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
                shutil.copyfile(python_d, python_d_dest)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1544
            elif os.path.exists(python_d_dest):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1545
                logger.info("Removed python_d.exe as it is no longer at the source")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1546
                os.unlink(python_d_dest)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1547
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1548
            # we need to copy the DLL to enforce that windows will load the correct one.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
            # may not exist if we are cygwin.
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1550
            if IS_PYPY:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1551
                py_executable_dll_s = [("libpypy-c.dll", "libpypy_d-c.dll")]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1552
            else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1553
                py_executable_dll_s = [
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1554
                    ("python{}.dll".format(sys.version_info[0]), "python{}_d.dll".format(sys.version_info[0])),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1555
                    (
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1556
                        "python{}{}.dll".format(sys.version_info[0], sys.version_info[1]),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1557
                        "python{}{}_d.dll".format(sys.version_info[0], sys.version_info[1]),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1558
                    ),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1559
                ]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1560
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1561
            for py_executable_dll, py_executable_dll_d in py_executable_dll_s:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1562
                python_dll = os.path.join(os.path.dirname(sys.executable), py_executable_dll)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1563
                python_dll_d = os.path.join(os.path.dirname(sys.executable), py_executable_dll_d)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1564
                python_dll_d_dest = os.path.join(os.path.dirname(py_executable), py_executable_dll_d)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1565
                if os.path.exists(python_dll):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1566
                    logger.info("Also created %s", py_executable_dll)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1567
                    shutil.copyfile(python_dll, os.path.join(os.path.dirname(py_executable), py_executable_dll))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1568
                if os.path.exists(python_dll_d):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1569
                    logger.info("Also created %s", py_executable_dll_d)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1570
                    shutil.copyfile(python_dll_d, python_dll_d_dest)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1571
                elif os.path.exists(python_dll_d_dest):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1572
                    logger.info("Removed %s as the source does not exist", python_dll_d_dest)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1573
                    os.unlink(python_dll_d_dest)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1574
        if IS_PYPY:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1575
            # make a symlink python --> pypy-c
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1576
            python_executable = os.path.join(os.path.dirname(py_executable), "python")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1577
            if IS_WIN or IS_CYGWIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1578
                python_executable += ".exe"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1579
            logger.info("Also created executable %s", python_executable)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1580
            copyfile(py_executable, python_executable, symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1581
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1582
            if IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1583
                for name in ["libexpat.dll", "libeay32.dll", "ssleay32.dll", "sqlite3.dll", "tcl85.dll", "tk85.dll"]:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1584
                    src = join(prefix, name)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1585
                    if os.path.exists(src):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1586
                        copyfile(src, join(bin_dir, name), symlink)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1587
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1588
                for d in sys.path:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1589
                    if d.endswith("lib_pypy"):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1590
                        break
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1591
                else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1592
                    logger.fatal("Could not find lib_pypy in sys.path")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1593
                    raise SystemExit(3)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1594
                logger.info("Copying lib_pypy")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1595
                copyfile(d, os.path.join(home_dir, "lib_pypy"), symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1596
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1597
    if os.path.splitext(os.path.basename(py_executable))[0] != EXPECTED_EXE:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1598
        secondary_exe = os.path.join(os.path.dirname(py_executable), EXPECTED_EXE)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1599
        py_executable_ext = os.path.splitext(py_executable)[1]
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1600
        if py_executable_ext.lower() == ".exe":
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1601
            # python2.4 gives an extension of '.4' :P
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1602
            secondary_exe += py_executable_ext
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1603
        if os.path.exists(secondary_exe):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1604
            logger.warn(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1605
                "Not overwriting existing {} script {} (you must use {})".format(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1606
                    EXPECTED_EXE, secondary_exe, py_executable
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1607
                )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1608
            )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1609
        else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1610
            logger.notify("Also creating executable in %s", secondary_exe)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1611
            shutil.copyfile(sys.executable, secondary_exe)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1612
            make_exe(secondary_exe)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1613
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1614
    if ".framework" in prefix:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1615
        original_python = None
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1616
        if "Python.framework" in prefix or "Python3.framework" in prefix:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1617
            logger.debug("MacOSX Python framework detected")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1618
            # Make sure we use the embedded interpreter inside
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1619
            # the framework, even if sys.executable points to
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1620
            # the stub executable in ${sys.prefix}/bin
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1621
            # See http://groups.google.com/group/python-virtualenv/
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1622
            #                              browse_thread/thread/17cab2f85da75951
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1623
            original_python = os.path.join(prefix, "Resources/Python.app/Contents/MacOS/Python")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1624
        if "EPD" in prefix:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1625
            logger.debug("EPD framework detected")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1626
            original_python = os.path.join(prefix, "bin/python")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1627
        shutil.copy(original_python, py_executable)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1628
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1629
        # Copy the framework's dylib into the virtual
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1630
        # environment
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1631
        virtual_lib = os.path.join(home_dir, ".Python")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1632
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1633
        if os.path.exists(virtual_lib):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1634
            os.unlink(virtual_lib)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1635
        lib_name = "Python3" if "Python3.framework" in prefix else "Python"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1636
        copyfile(os.path.join(prefix, lib_name), virtual_lib, symlink)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1637
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1638
        # And then change the install_name of the copied python executable
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1639
        search = (
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1640
            "@executable_path/../../../../Python3" if "Python3.framework" in prefix else os.path.join(prefix, lib_name)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1641
        )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1642
        # noinspection PyBroadException
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1643
        try:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1644
            mach_o_change(py_executable, search, "@executable_path/../.Python")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1645
        except Exception:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1646
            e = sys.exc_info()[1]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1647
            logger.warn("Could not call mach_o_change: %s. " "Trying to call install_name_tool instead.", e)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1648
            try:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1649
                call_subprocess(["install_name_tool", "-change", search, "@executable_path/../.Python", py_executable])
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1650
            except Exception:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1651
                logger.fatal("Could not call install_name_tool -- you must " "have Apple's development tools installed")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1652
                raise
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1653
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1654
    if not IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1655
        # Ensure that 'python', 'pythonX' and 'pythonX.Y' all exist
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1656
        py_exe_version_major = "python{}".format(sys.version_info[0])
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1657
        py_exe_version_major_minor = "python{}.{}".format(sys.version_info[0], sys.version_info[1])
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1658
        py_exe_no_version = "python"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1659
        required_symlinks = [py_exe_no_version, py_exe_version_major, py_exe_version_major_minor]
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1660
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1661
        py_executable_base = os.path.basename(py_executable)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1662
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1663
        if py_executable_base in required_symlinks:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1664
            # Don't try to symlink to yourself.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1665
            required_symlinks.remove(py_executable_base)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1666
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1667
        for pth in required_symlinks:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1668
            full_pth = join(bin_dir, pth)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1669
            if os.path.exists(full_pth):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1670
                os.unlink(full_pth)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1671
            if symlink:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1672
                os.symlink(py_executable_base, full_pth)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1673
            else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1674
                copyfile(py_executable, full_pth, symlink)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1675
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1676
    cmd = [
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1677
        py_executable,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1678
        "-c",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1679
        "import sys;out=sys.stdout;" 'getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))',
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1680
    ]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1681
    logger.info('Testing executable with %s %s "%s"', *cmd)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1682
    try:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1683
        proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1684
        proc_stdout, proc_stderr = proc.communicate()
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1685
    except OSError:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1686
        e = sys.exc_info()[1]
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1687
        if e.errno == errno.EACCES:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1688
            logger.fatal("ERROR: The executable {} could not be run: {}".format(py_executable, e))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1689
            sys.exit(100)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1690
        else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1691
            raise e
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1692
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1693
    proc_stdout = proc_stdout.strip().decode("utf-8")
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1694
    # normalize paths using realpath to ensure that a virtualenv correctly identifies itself even
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1695
    # when addressed over a symlink
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1696
    proc_stdout = os.path.normcase(os.path.realpath(proc_stdout))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1697
    norm_home_dir = os.path.normcase(os.path.realpath(home_dir))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1698
    if hasattr(norm_home_dir, "decode"):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1699
        norm_home_dir = norm_home_dir.decode(sys.getfilesystemencoding())
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1700
    if proc_stdout != norm_home_dir:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1701
        logger.fatal("ERROR: The executable %s is not functioning", py_executable)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1702
        logger.fatal("ERROR: It thinks sys.prefix is {!r} (should be {!r})".format(proc_stdout, norm_home_dir))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1703
        logger.fatal("ERROR: virtualenv is not compatible with this system or executable")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1704
        if IS_WIN:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1705
            logger.fatal(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1706
                "Note: some Windows users have reported this error when they "
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1707
                'installed Python for "Only this user" or have multiple '
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1708
                "versions of Python installed. Copying the appropriate "
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1709
                "PythonXX.dll to the virtualenv Scripts/ directory may fix "
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1710
                "this problem."
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1711
            )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1712
        sys.exit(100)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1713
    else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1714
        logger.info("Got sys.prefix result: %r", proc_stdout)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1715
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1716
    pydistutils = os.path.expanduser("~/.pydistutils.cfg")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1717
    if os.path.exists(pydistutils):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1718
        logger.notify("Please make sure you remove any previous custom paths from " "your %s file.", pydistutils)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1719
    # FIXME: really this should be calculated earlier
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1720
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1721
    fix_local_scheme(home_dir, symlink)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1722
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1723
    if site_packages:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1724
        if os.path.exists(site_packages_filename):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1725
            logger.info("Deleting %s", site_packages_filename)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1726
            os.unlink(site_packages_filename)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1727
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1728
    return py_executable
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1729
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1730
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1731
def install_activate(home_dir, bin_dir, prompt=None):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1732
    if IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1733
        files = {"activate.bat": ACTIVATE_BAT, "deactivate.bat": DEACTIVATE_BAT, "activate.ps1": ACTIVATE_PS}
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1734
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1735
        # MSYS needs paths of the form /c/path/to/file
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1736
        drive, tail = os.path.splitdrive(home_dir.replace(os.sep, "/"))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1737
        home_dir_msys = (drive and "/{}{}" or "{}{}").format(drive[:1], tail)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1738
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1739
        # Run-time conditional enables (basic) Cygwin compatibility
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1740
        home_dir_sh = """$(if [ "$OSTYPE" "==" "cygwin" ]; then cygpath -u '{}'; else echo '{}'; fi;)""".format(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1741
            home_dir, home_dir_msys
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1742
        )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1743
        files["activate"] = ACTIVATE_SH.replace("__VIRTUAL_ENV__", home_dir_sh)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1744
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1745
    else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1746
        files = {
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1747
            "activate": ACTIVATE_SH,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1748
            "activate.fish": ACTIVATE_FISH,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1749
            "activate.csh": ACTIVATE_CSH,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1750
            "activate.ps1": ACTIVATE_PS,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1751
        }
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1752
    files["activate_this.py"] = ACTIVATE_THIS
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1753
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1754
    if sys.version_info >= (3, 4):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1755
        # Add xonsh support
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1756
        files["activate.xsh"] = ACTIVATE_XSH
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1757
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1758
    install_files(home_dir, bin_dir, prompt, files)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1759
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1760
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1761
def install_files(home_dir, bin_dir, prompt, files):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1762
    if hasattr(home_dir, "decode"):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1763
        home_dir = home_dir.decode(sys.getfilesystemencoding())
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1764
    virtualenv_name = os.path.basename(home_dir)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1765
    for name, content in files.items():
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1766
        content = content.replace("__VIRTUAL_PROMPT__", prompt or "")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1767
        content = content.replace("__VIRTUAL_WINPROMPT__", prompt or "({}) ".format(virtualenv_name))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1768
        content = content.replace("__VIRTUAL_ENV__", home_dir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1769
        content = content.replace("__VIRTUAL_NAME__", virtualenv_name)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1770
        content = content.replace("__BIN_NAME__", os.path.basename(bin_dir))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1771
        content = content.replace("__PATH_SEP__", os.pathsep)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1772
        writefile(os.path.join(bin_dir, name), content)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1773
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1774
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1775
def install_python_config(home_dir, bin_dir, prompt=None):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1776
    if IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1777
        files = {}
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1778
    else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1779
        files = {"python-config": PYTHON_CONFIG}
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1780
    install_files(home_dir, bin_dir, prompt, files)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1781
    for name, _ in files.items():
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1782
        make_exe(os.path.join(bin_dir, name))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1783
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1784
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1785
def install_distutils(home_dir):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1786
    distutils_path = change_prefix(distutils.__path__[0], home_dir)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1787
    mkdir(distutils_path)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1788
    # FIXME: maybe this prefix setting should only be put in place if
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1789
    # there's a local distutils.cfg with a prefix setting?
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1790
    # FIXME: this is breaking things, removing for now:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1791
    # distutils_cfg = DISTUTILS_CFG + "\n[install]\nprefix=%s\n" home_dir
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1792
    writefile(os.path.join(distutils_path, "__init__.py"), DISTUTILS_INIT)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1793
    writefile(os.path.join(distutils_path, "distutils.cfg"), DISTUTILS_CFG, overwrite=False)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1794
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1795
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1796
def fix_local_scheme(home_dir, symlink=True):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1797
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1798
    Platforms that use the "posix_local" install scheme (like Ubuntu with
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1799
    Python 2.7) need to be given an additional "local" location, sigh.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1800
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1801
    try:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1802
        import sysconfig
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1803
    except ImportError:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1804
        pass
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1805
    else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1806
        # noinspection PyProtectedMember
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1807
        if sysconfig._get_default_scheme() == "posix_local":
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1808
            local_path = os.path.join(home_dir, "local")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1809
            if not os.path.exists(local_path):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1810
                os.mkdir(local_path)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1811
                for subdir_name in os.listdir(home_dir):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1812
                    if subdir_name == "local":
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1813
                        continue
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1814
                    copyfile(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1815
                        os.path.abspath(os.path.join(home_dir, subdir_name)),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1816
                        os.path.join(local_path, subdir_name),
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1817
                        symlink,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1818
                    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1819
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1820
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1821
def fix_lib64(lib_dir, symlink=True):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1822
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1823
    Some platforms (particularly Gentoo on x64) put things in lib64/pythonX.Y
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1824
    instead of lib/pythonX.Y.  If this is such a platform we'll just create a
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1825
    symlink so lib64 points to lib
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1826
    """
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1827
    # PyPy's library path scheme is not affected by this.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1828
    # Return early or we will die on the following assert.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1829
    if IS_PYPY:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1830
        logger.debug("PyPy detected, skipping lib64 symlinking")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1831
        return
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1832
    # Check we have a lib64 library path
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1833
    if not [p for p in distutils.sysconfig.get_config_vars().values() if isinstance(p, basestring) and "lib64" in p]:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1834
        return
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1835
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1836
    logger.debug("This system uses lib64; symlinking lib64 to lib")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1837
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1838
    assert os.path.basename(lib_dir) == PY_VERSION, "Unexpected python lib dir: {!r}".format(lib_dir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1839
    lib_parent = os.path.dirname(lib_dir)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1840
    top_level = os.path.dirname(lib_parent)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1841
    lib_dir = os.path.join(top_level, "lib")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1842
    lib64_link = os.path.join(top_level, "lib64")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1843
    assert os.path.basename(lib_parent) == "lib", "Unexpected parent dir: {!r}".format(lib_parent)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1844
    if os.path.lexists(lib64_link):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1845
        return
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1846
    if symlink:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1847
        os.symlink("lib", lib64_link)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1848
    else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1849
        copyfile(lib_dir, lib64_link, symlink=False)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1850
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1851
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1852
def resolve_interpreter(exe):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1853
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1854
    If the executable given isn't an absolute path, search $PATH for the interpreter
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1855
    """
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1856
    # If the "executable" is a version number, get the installed executable for
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1857
    # that version
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1858
    orig_exe = exe
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1859
    python_versions = get_installed_pythons()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1860
    if exe in python_versions:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1861
        exe = python_versions[exe]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1862
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1863
    if os.path.abspath(exe) != exe:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1864
        exe = distutils.spawn.find_executable(exe) or exe
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1865
    if not os.path.exists(exe):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1866
        logger.fatal("The path {} (from --python={}) does not exist".format(exe, orig_exe))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1867
        raise SystemExit(3)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1868
    if not is_executable(exe):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1869
        logger.fatal("The path {} (from --python={}) is not an executable file".format(exe, orig_exe))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1870
        raise SystemExit(3)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1871
    return exe
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1872
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1873
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1874
def is_executable(exe):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1875
    """Checks a file is executable"""
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1876
    return os.path.isfile(exe) and os.access(exe, os.X_OK)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1877
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1878
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1879
# Relocating the environment:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1880
def make_environment_relocatable(home_dir):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1881
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1882
    Makes the already-existing environment use relative paths, and takes out
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1883
    the #!-based environment selection in scripts.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1884
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1885
    home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1886
    activate_this = os.path.join(bin_dir, "activate_this.py")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1887
    if not os.path.exists(activate_this):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1888
        logger.fatal(
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1889
            "The environment doesn't have a file %s -- please re-run virtualenv " "on this environment to update it",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1890
            activate_this,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1891
        )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1892
    fixup_scripts(home_dir, bin_dir)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1893
    fixup_pth_and_egg_link(home_dir)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1894
    # FIXME: need to fix up distutils.cfg
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1895
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1896
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1897
OK_ABS_SCRIPTS = [
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1898
    "python",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1899
    PY_VERSION,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1900
    "activate",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1901
    "activate.bat",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1902
    "activate_this.py",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1903
    "activate.fish",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1904
    "activate.csh",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1905
    "activate.xsh",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1906
]
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1907
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1908
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1909
def fixup_scripts(_, bin_dir):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1910
    if IS_WIN:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1911
        new_shebang_args = ("{} /c".format(os.path.normcase(os.environ.get("COMSPEC", "cmd.exe"))), "", ".exe")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1912
    else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1913
        new_shebang_args = ("/usr/bin/env", VERSION, "")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1914
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1915
    # This is what we expect at the top of scripts:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1916
    shebang = "#!{}".format(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1917
        os.path.normcase(os.path.join(os.path.abspath(bin_dir), "python{}".format(new_shebang_args[2])))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1918
    )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1919
    # This is what we'll put:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1920
    new_shebang = "#!{} python{}{}".format(*new_shebang_args)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1921
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1922
    for filename in os.listdir(bin_dir):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1923
        filename = os.path.join(bin_dir, filename)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1924
        if not os.path.isfile(filename):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1925
            # ignore child directories, e.g. .svn ones.
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1926
            continue
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1927
        with open(filename, "rb") as f:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1928
            try:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1929
                lines = f.read().decode("utf-8").splitlines()
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1930
            except UnicodeDecodeError:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1931
                # This is probably a binary program instead
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1932
                # of a script, so just ignore it.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1933
                continue
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1934
        if not lines:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1935
            logger.warn("Script %s is an empty file", filename)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1936
            continue
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1937
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1938
        old_shebang = lines[0].strip()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1939
        old_shebang = old_shebang[0:2] + os.path.normcase(old_shebang[2:])
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1940
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1941
        if not old_shebang.startswith(shebang):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1942
            if os.path.basename(filename) in OK_ABS_SCRIPTS:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1943
                logger.debug("Cannot make script %s relative", filename)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1944
            elif lines[0].strip() == new_shebang:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1945
                logger.info("Script %s has already been made relative", filename)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1946
            else:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1947
                logger.warn(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1948
                    "Script %s cannot be made relative (it's not a normal script that starts with %s)",
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1949
                    filename,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1950
                    shebang,
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1951
                )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1952
            continue
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1953
        logger.notify("Making script %s relative", filename)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1954
        script = relative_script([new_shebang] + lines[1:])
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1955
        with open(filename, "wb") as f:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1956
            f.write("\n".join(script).encode("utf-8"))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1957
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1958
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1959
def relative_script(lines):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1960
    """Return a script that'll work in a relocatable environment."""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1961
    activate = (
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1962
        "import os; "
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1963
        "activate_this=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'activate_this.py'); "
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1964
        "exec(compile(open(activate_this).read(), activate_this, 'exec'), { '__file__': activate_this}); "
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1965
        "del os, activate_this"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1966
    )
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1967
    # Find the last future statement in the script. If we insert the activation
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1968
    # line before a future statement, Python will raise a SyntaxError.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1969
    activate_at = None
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1970
    for idx, line in reversed(list(enumerate(lines))):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1971
        if line.split()[:3] == ["from", "__future__", "import"]:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1972
            activate_at = idx + 1
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1973
            break
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1974
    if activate_at is None:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1975
        # Activate after the shebang.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1976
        activate_at = 1
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1977
    return lines[:activate_at] + ["", activate, ""] + lines[activate_at:]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1978
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1979
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1980
def fixup_pth_and_egg_link(home_dir, sys_path=None):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1981
    """Makes .pth and .egg-link files use relative paths"""
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1982
    home_dir = os.path.normcase(os.path.abspath(home_dir))
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1983
    if sys_path is None:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1984
        sys_path = sys.path
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1985
    for a_path in sys_path:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1986
        if not a_path:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1987
            a_path = "."
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1988
        if not os.path.isdir(a_path):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1989
            continue
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1990
        a_path = os.path.normcase(os.path.abspath(a_path))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1991
        if not a_path.startswith(home_dir):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1992
            logger.debug("Skipping system (non-environment) directory %s", a_path)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1993
            continue
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1994
        for filename in os.listdir(a_path):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1995
            filename = os.path.join(a_path, filename)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1996
            if filename.endswith(".pth"):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1997
                if not os.access(filename, os.W_OK):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  1998
                    logger.warn("Cannot write .pth file %s, skipping", filename)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1999
                else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2000
                    fixup_pth_file(filename)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2001
            if filename.endswith(".egg-link"):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2002
                if not os.access(filename, os.W_OK):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2003
                    logger.warn("Cannot write .egg-link file %s, skipping", filename)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2004
                else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2005
                    fixup_egg_link(filename)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2006
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2007
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2008
def fixup_pth_file(filename):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2009
    lines = []
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2010
    with open(filename) as f:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2011
        prev_lines = f.readlines()
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2012
    for line in prev_lines:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2013
        line = line.strip()
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2014
        if not line or line.startswith("#") or line.startswith("import ") or os.path.abspath(line) != line:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2015
            lines.append(line)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2016
        else:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2017
            new_value = make_relative_path(filename, line)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2018
            if line != new_value:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2019
                logger.debug("Rewriting path {} as {} (in {})".format(line, new_value, filename))
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2020
            lines.append(new_value)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2021
    if lines == prev_lines:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2022
        logger.info("No changes to .pth file %s", filename)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2023
        return
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2024
    logger.notify("Making paths in .pth file %s relative", filename)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2025
    with open(filename, "w") as f:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2026
        f.write("\n".join(lines) + "\n")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2027
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2028
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2029
def fixup_egg_link(filename):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2030
    with open(filename) as f:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2031
        link = f.readline().strip()
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2032
    if os.path.abspath(link) != link:
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2033
        logger.debug("Link in %s already relative", filename)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2034
        return
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2035
    new_link = make_relative_path(filename, link)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2036
    logger.notify("Rewriting link {} in {} as {}".format(link, filename, new_link))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2037
    with open(filename, "w") as f:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2038
        f.write(new_link)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2039
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2040
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2041
def make_relative_path(source, dest, dest_is_directory=True):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2042
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2043
    Make a filename relative, where the filename is dest, and it is
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2044
    being referred to from the filename source.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2045
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2046
        >>> make_relative_path('/usr/share/something/a-file.pth',
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2047
        ...                    '/usr/share/another-place/src/Directory')
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2048
        '../another-place/src/Directory'
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2049
        >>> make_relative_path('/usr/share/something/a-file.pth',
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2050
        ...                    '/home/user/src/Directory')
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2051
        '../../../home/user/src/Directory'
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2052
        >>> make_relative_path('/usr/share/a-file.pth', '/usr/share/')
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2053
        './'
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2054
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2055
    source = os.path.dirname(source)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2056
    if not dest_is_directory:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2057
        dest_filename = os.path.basename(dest)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2058
        dest = os.path.dirname(dest)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2059
    else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2060
        dest_filename = None
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2061
    dest = os.path.normpath(os.path.abspath(dest))
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2062
    source = os.path.normpath(os.path.abspath(source))
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2063
    dest_parts = dest.strip(os.path.sep).split(os.path.sep)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2064
    source_parts = source.strip(os.path.sep).split(os.path.sep)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2065
    while dest_parts and source_parts and dest_parts[0] == source_parts[0]:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2066
        dest_parts.pop(0)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2067
        source_parts.pop(0)
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2068
    full_parts = [".."] * len(source_parts) + dest_parts
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2069
    if not dest_is_directory and dest_filename is not None:
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2070
        full_parts.append(dest_filename)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2071
    if not full_parts:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2072
        # Special case for the current directory (otherwise it'd be '')
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2073
        return "./"
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2074
    return os.path.sep.join(full_parts)
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2075
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2076
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2077
FILE_PATH = __file__ if os.path.isabs(__file__) else os.path.join(os.getcwd(), __file__)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2078
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2079
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2080
# Bootstrap script creation:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2081
def create_bootstrap_script(extra_text, python_version=""):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2082
    """
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2083
    Creates a bootstrap script, which is like this script but with
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2084
    extend_parser, adjust_options, and after_install hooks.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2085
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2086
    This returns a string that (written to disk of course) can be used
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2087
    as a bootstrap script with your own customizations.  The script
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2088
    will be the standard virtualenv.py script, with your extra text
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2089
    added (your extra text should be Python code).
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2090
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2091
    If you include these functions, they will be called:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2092
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2093
    ``extend_parser(optparse_parser)``:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2094
        You can add or remove options from the parser here.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2095
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2096
    ``adjust_options(options, args)``:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2097
        You can change options here, or change the args (if you accept
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2098
        different kinds of arguments, be sure you modify ``args`` so it is
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2099
        only ``[DEST_DIR]``).
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2100
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2101
    ``after_install(options, home_dir)``:
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2102
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2103
        After everything is installed, this function is called.  This
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2104
        is probably the function you are most likely to use.  An
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2105
        example would be::
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2106
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2107
            def after_install(options, home_dir):
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2108
                subprocess.call([join(home_dir, 'bin', 'easy_install'),
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2109
                                 'MyPackage'])
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2110
                subprocess.call([join(home_dir, 'bin', 'my-package-script'),
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2111
                                 'setup', home_dir])
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2112
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2113
        This example immediately installs a package, and runs a setup
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2114
        script from that package.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2115
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2116
    If you provide something like ``python_version='2.5'`` then the
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2117
    script will start with ``#!/usr/bin/env python2.5`` instead of
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2118
    ``#!/usr/bin/env python``.  You can use this when the script must
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2119
    be run with a particular Python version.
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2120
    """
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2121
    filename = FILE_PATH
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2122
    if filename.endswith(".pyc"):
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2123
        filename = filename[:-1]
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2124
    with codecs.open(filename, "r", encoding="utf-8") as f:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2125
        content = f.read()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2126
    py_exe = "python{}".format(python_version)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2127
    content = "#!/usr/bin/env {}\n# WARNING: This file is generated\n{}".format(py_exe, content)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2128
    # we build the string as two, to avoid replacing here, but yes further done
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2129
    return content.replace("# EXTEND - " "bootstrap here", extra_text)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2130
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2131
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2132
# EXTEND - bootstrap here
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2133
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2134
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2135
def convert(s):
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2136
    b = base64.b64decode(s.encode("ascii"))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2137
    return zlib.decompress(b).decode("utf-8")
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2138
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2139
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2140
# file site.py
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2141
SITE_PY = convert(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2142
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2143
eJy1Pf1z2zaWv/OvwNKTseTKdOK0va5T98ZJnNZzbpKN09ncpj4tJUES1xTJEqRlbSb7t9/7AECA
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2144
pGRn29V0XIkEHh4e3jcekDAMz4pCZjOxymd1KoWScTldiiKulkrM81JUy6ScHRZxWW3g6fQmXkgl
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2145
qlyojYqwVRQEB7/zExyI98tEGRTgW1xX+SqukmmcphuRrIq8rORMzOoyyRYiyZIqidPkn9AizyJx
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2146
8PsxCC4yATNPE1mKW1kqgKtEPhdvN9Uyz8SgLnDOT6Jv4qfDkVDTMikqaFBqnIEiy7gKMilngCa0
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2147
rBWQMqnkoSrkNJknU9twndfpTBRpPJXi73/nqVHT/f1A5Su5XspSigyQAZgSYBWIB3xNSjHNZzIS
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2148
4rmcxjgAP2+IFTC0Ea6ZQjJmuUjzbAFzyuRUKhWXGzGY1BUBIpTFLAecEsCgStI0WOfljRrCktJ6
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2149
rOGRiJk9/Mkwe8A8cfwu5wCOb7Lglyy5GzFs4B4EVy2ZbUo5T+5EjGDhp7yT07F+NkjmYpbM50CD
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2150
rBpik4ARUCJNJkcFLcf3eoV+OCKsLFfGMIZElLkxv6QeUXBRiThVwLZ1gTRShPlLOUniDKiR3cJw
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2151
ABFIGvSNM0tUZceh2YkcAJS4jhVIyUqJwSpOMmDWn+Mpof3XJJvlazUkCsBqKfGPWlXu/Ac9BIDW
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2152
DgFGAS6WWc06S5MbmW6GgMB7wL6Uqk4rFIhZUspplZeJVAQAUNsIeQdIj0RcSk1C5kwjtyOiP9Ek
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2153
yXBhUcBQ4PElkmSeLOqSJEzME+Bc4IpXb96Jl+fPL85eax4zwFhmFyvAGaDQQjs4wQDiqFblUZqD
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2154
QEfBJf5PxLMZCtkCxwe8mgZH9650MIC5F1G7j7PgQHa9uHoYmGMFyoTGCqjfJ+gyUkugz+d71jsI
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2155
zrZRhSbO39bLHGQyi1dSLGPmL+SM4HsN54eoqJbPgBsUwqmAVAoXBxFMEB6QxKXZIM+kKIDF0iST
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2156
wwAoNKG2/ioCK7zOs0Na6xYnAIQyyOCl82xII2YSJtqF9Qz1hWm8oZnpJoFd51VekuIA/s+mpIvS
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2157
OLshHBUxFH+byEWSZYgQ8kKwv7dPA6ubBDhxFolLakV6wTQS+6y9uCWKRA28hEwHPCnv4lWRyhGL
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2158
L+rW3WqEBpOVMGudMsdBy4rUK61aM9Ve3juOPrS4jtCslqUE4PXEE7p5no/EBHQ2YVPEKxavap0T
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2159
5wQ98kSdkCeoJfTF70DRM6XqlbQvkVdAsxBDBfM8TfM1kOwkCITYw0bGKPvMCW/hHfwFuPg3ldV0
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2160
GQTOSBawBoXIbwOFQMAkyExztUbC4zbNym0lk2SsKfJyJksa6mHEPmLEH9gY5xq8zitt1Hi6uMr5
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2161
KqlQJU20yUzY4mX7FevHZzxvmAZYbkU0M00bOq1wemmxjCfSuCQTOUdJ0Iv0zC47jBn0jEm2uBIr
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2162
tjLwDsgiE7Yg/YoFlc68kuQEAAwWvjhLijqlRgoZTMQw0Kog+KsYTXqunSVgbzbLASokNt9TsD+A
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2163
2z9BjNbLBOgzBQigYVBLwfJNkqpEB6HRR4Fv9E1/Hh849WKubRMPOY+TVFv5OAsu6OF5WZL4TmWB
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2164
vUaaGApmmFXo2i0yoCOKeRiGgXZgRK7MN2CkIKjKzQnwgjADjceTOkHLNx6jrdc/VMDDCGdkr5tt
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2165
Z+GBijCdXgOZnC7zMl/hazu5K9AmMBb2CPbEW1Izkj1kjxWfIf1cnV6Ypmi8HX4WqIiCt+/OX118
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2166
OL8Sp+Jjo9NGbYV2DWOeZzHwNZkE4KrWsI0yg5ao+RJUfuIV2HfiCjBo1JvkV8ZVDcwLqL8va3oN
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2167
05h6L4Pz12fPL8/Hv1ydvxtfXbw/BwTB0Mhgj6aM9rEGj1FFIB3AljMVaQMbdHrQg+dnV/ZBME7U
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2168
+Nuvgd/gyWAhK+DicgAzHolwFd8p4NBwRE2HiGOnAZjwcDgUP4hjcXAgnh4TvGJTbAAcWF6nMT4c
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2169
a6M+TrJ5Hg6DIJjJOUjLjUSZGhyQKzvkVQciAoxcm9Z/5Elm3ve8jieKIMBTfl1KoFyGrUa2EXD3
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2170
ahorya14bOg4HqOMj8cDPTAwPzEYOCgstvvCNEEZLxPwA2mhUOYnKk/xJw6AUkP8iqEIahVkHB1q
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2171
RLdxWktlxqBmgL+hJ5io0Axi6G0bghM5R0HFp013/KDZSLJa2oeryKLaJc7cTLqUq/xWzsB8Iz2d
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2172
eYt39AZiuyIF5QrzAs1AFoVl0HgeMUYyrF1g8dD6ALuuCIqhiCHGHoeTMlPAyRyaEW/ruJGVaVHm
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2173
twmaq8lGvwRtC9KGOteYRg0tR7/eIzsqVWAw8KMyJNVa7oM8lTW7PIQ3gkSFM2skMyJwlyjq1/T1
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2174
JsvX2ZhjqVOU2sHQLibyml5ObNCswZ54BWoMkMwhNGiIxlDAaRTIboeAPEwfpguUJe8UAIGpUOTw
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2175
O7BMsEBT5LgDh0UYw2eC+LmUaHFuzRDkrBtiOJDobWQfkBTAH4QEk7PyZqVFcxmaRdMMBnZI4rPd
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2176
ZcRBjA+gRcUI9O5AQ+NGhn4fT64Bi0tXTp1+Aer0Dx8+MN+oJYXoiNkEZ40GaU7qNio2oJoT8HyN
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2177
UeeAn/gAAvcMwNRK86Y4vBJ5wQYdFpQzCWA1r8B9XFZVcXJ0tF6vIx2g5uXiSM2Pvvnu22+/e8xq
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2178
YjYjBoL5OOKiszXREb1Dpyj63gShP5ilazFkkvnsSLAGkgw7eTOI3491MsvFyeHQqhRk40bR419j
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2179
DEGFjM2gAdMZqBs2KH36fPjpM/wNI2wSVwO3xwCCswNcGFcz83IBQ/gaHPpVOdgVsILTvEbF37CF
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2180
El/BoBDwzeSkXoQWD09/mx8wbRTagWWIwyfXmMnx2cQwmTJqa4w6g5gEkXTW4R0zUUzGVusLpDWq
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2181
8E40tunXaYbSs4dLv3VdHBEyU0wUsgrKh9/kweJoG3flCD/aU3q/KVxPyXw8u2BMobF4s5l2VAYo
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2182
RoQMrsbIFUKHx9GDAtlas6YGfeNqStDX4HRMmNwaHPnf+whyX5C/SdEjL61uAYRqpaJMwGmWAVq4
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2183
43SsX5sX7AswMhJ9mSf0RILLddJ595jXtk5TyhC0uNSjCgP2Vhrtdg6cOTAAQDTKkBsar/dNa1F4
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2184
DXpg5ZxTQAabd5gJ30RMJSTSINwLe9ip4wRs680k7gOBazTg3MaDoBPKpzxCqUCaioHfcxuLW9p2
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2185
B9tpf4inzCqRSKstwtXWHr1CtdNMzZMMFbGzSNE0zcFttGqR+Kh577sO5Fbj417TpiVQ06Ghh9Pq
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2186
lLw/TwD3dTvMxyxqjFzdwB5RWiWKbB3SaQl/wMuggJmyG0BMgmbBPFTK/Jn9ATJn56u/bOEPS2nk
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2187
CLfpNq+kYzM0HHSGkIA6sAcByIB4XTkkH5IVQQrM5SyNJ9fwWm4VbIIRKRAxx3iQggGs6WXTDacG
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2188
TyJMppNwIuS7SslCfAWhEpijFms/TGv/sQxq4tmB04KiYR0In7pBshMgn7YCZp+X/VCZ8u5FDsw7
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2189
Ad/HTRq7HG741cbv4Lb7OtsiBcqYQvpw6KJ6bSjjJib/dOq0aKhlBjG85A3kbQ+YkYaBXW8NGlbc
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2190
gPEWvT2Wfkzz1B4Z9h2EuTqWq7sQTUuiprnq09qaEbrUsPhdJhME4ZE8HF57kGSaoGvFUfu/M8j9
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2191
0L3pnYKfOIvLdZKFpK00xU79xejgYYnnmbSjKwqljmCimC87elWCTNDG2RFQjKS/KCCCV9rl78Jt
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2192
z7G3AX68yYd2RIaLVPad7K5T3SXV6GGDWUqf31VlrHCslBeWRWUboOvubEk3I1nibKN3zfSuKgYX
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2193
Za4g+BRvrj4IpCEnFNfx5l6i9aPrIfnl1GmhT5wEA6GORB46Cnczay/S/xFE+6m/cyhH0X1Z/wfj
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2194
CAMdzjZZmsezvhGuO0+gw7dfj3uybi7u3379ewjVJ9Qtp85iMfRcvlLGKTkIznv0DUBX7l5o27EY
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2195
sn6mUE6zSZcqXZbSaNo0aX8L/BiomH2V4AQ8HjU07U4dP76ntBWetkM7gHUiUfPZI90LgXs++QdE
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2196
v0qnz27jJKUUNBDj8BBVqYncOTHRL/AepJ06wSFBX2ilPj6+Bu7gVMGwOx3tbZ2ZZGtPhGs+Ray6
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2197
qOzp/eZmu8TbQ3a3yrbrEEP2LxFuszf2RULi4dYjJL1i0wYEFEWteNxPpQfNace8/uAZ9c9quzT8
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2198
sehb3Hto+O9j38ZxJyo8hFb/Pqx+KriGzQB7gIHZ4pTtcMm6Q/Mm09w4VqwglDhATXIg1rTRTClN
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2199
8MsygDJjl6sHDoqH3q58UZclbzqSQipkeYj7aCOBNTbGt6LSnS6Yo9eyQkxssymliJ2KjLxPYkKd
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2200
9LUzCRsvHfNU+v3T3gb9fLnMTfZIZrdJCcBBPw7Cn978fL6FbzCnCp0ervS3NsSPxwEIl11+JAry
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2201
wO9xTbeO678xW64mR6qx786vkxo14XU/Ke5JkXh7fLyPSYHrdCmnN2NJm7PIT9jXyRO/wNeIit2z
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2202
9UtsVDynOiGYyjStkTzsgmKB17zOprR/UEnwU3Q1JlZn0JYrZ8TmabwQA+o8w2SM5grK19zGpXbD
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2203
ijLH+j9RJ7OjRTIT8rc6TjHalfM54IK7O/pVxMNTTka85F1jrgtTclqXSbUBGsQq15tjtMHsNJxs
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2204
eKIDD0neBmEK4pbzibjCaeN7JtzMkMvEzP4uAE4SGIQ6ONvBET2H91k+xlHHSF7gPUJq2E6Y8OOg
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2205
PUKutxlg/nqE9htJr9wdOFpzl6iozjxSugF4Tj4MQhkMMQHAv+mnz4kuc23BcrEdy8VuLBdtLBe9
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2206
WC58LBe7sXRlAhe2SeYYUehL6LQz/b0lDW4uhsc5j6dLbof1dVhHBxBFYWJJI1RcZuplfHgDjICQ
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2207
/nS2ZOlhU6KQcOFemXNaWINE9seNHR23mgJhpzMVPOjOPBXjBm4r0/D7HkURleNMqDsL3Cyu4sgT
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2208
jEWaT0BuLbqjBsBItCs2OImY3Y4nnPBsm4y3//v+pzevsTmCshUA1A0XETU8TmVwEJcL1RWnJooq
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2209
gB+ppV85Qd00wL3elNM+p5z2R2KfU077epg9/vMyx0It5Byxpk38XBRgrKlyxjZz60v291vPdSGK
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2210
fs5szhsw4H9kleN7bKHS2du3L8/en4VUihL+K3RFxhDXlw8XH9PCNui6Wm5zS3Ls01jTxv65c/KI
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2211
7bCE7vXp879jfn38/qNzBGICEpHOZ37ZFH9n9sQagU6Vk5sAYKfBvnMkwHEVHAHsy4q3B/C34dAn
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2212
H8NctCszMPNqgrqW7rVWbgdxHKB/VADV8aQsHj2+lEMc22y7J9XdCVCyen7+48Xry4vnb8/e/+T4
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2213
UugTvbk6OhbnP38QVIiAhoCdixi33SuseQEF7R7KELMc/qsx8zCrK84rQq+Xl5d6J2CFZflYp4m6
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2214
O4LnXDBjoXEShxOX9qGudEGMUh0SOOcfqC6EzkdghLDi2nuV61pOOlYxQa+v1sGGPtdizr/QnmkE
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2215
ogCNXVIwCC5mgldUcVuZOKjkLSZ9JqQHKW3rbNFBSkmqzk60s79icvleXo86w5Oms9aXH0MX1/A6
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2216
UkWagAZ9Flpp0N2w9qLhG/3Qbp4yXn3qyOkOI+uGPOutWGBdyrOQ56b7DxtG+60GDBsGewnzziRV
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2217
HlCxKJZRiX1stM8VBvIOvtql12ugYMFwI6nCRTRMl8DsYwgnxTIBTxx4cglGDB1ugNBaCT/HfOLY
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2218
JJnjxn/4YjU7/EuoCeK3/vXXnuZVmR7+TRQQTgguUwl7iOk2fgkRRCQjcf7m1TBk5KZpDE7jX2os
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2219
ZQbDTgk4R9ipNoY3Z8cDJdO5Ll3w1QG+0OaWXget/qUsSt2/38kMUQQ+fR6Q9f302RCwSaeYAUY4
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2220
n2EbPtZqW/zwzJO7z20+e+JqKdNUF+hevLw8B08My8dRjniv5xzG5DwB7tTqWi8+k9UChfu48LpE
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2221
Zi7RIaRt/FnkNetNnaLgUW9v59+uFqUnu706ucgyTpSL9gCnrQljCqAj5GhYErO6If7WUmrbIJ3d
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2222
NkR3FB3mjPHbkiomfdYAlqanMYcYEHtgdbpJBPNmZZJVpkIuTaagTkHzgl4dgawgdfEIFjFgnnEq
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2223
Ni+VObkBD4tNmSyWFWbioXNEVePY/OezD5cXr6mQ+vhp48T28OiIHOsRlymcYjEapg/gi1tahnw1
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2224
Hrus23qFMFAJwf/ar7j+4ZQH6PTjjJq3FaBf8dGZUyey4hmAnqqLtpCgO+1065OeRhgYVxtX4set
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2225
Mmsw88FQEg4r9XVBgTu/Livali2LQn6IefkF+wjzwhY96c5O0VP7o6c4L3D3ZTbobwRv+2TLfCbQ
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2226
9abzZlt5lfvpSCEe4gOMuq39MUz9Uaepno7Da9uYhYJEbWl/dUMFp900Q0kGGg7czkOXx/o1sW7O
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2227
DOiV7XaAie81ukYQ+/U5oKj9DA8TS+xO6GA6YtWheKQGXKMh9WGFGjypR4r0RygeicHAEdzRUByI
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2228
Y2+Wjj24f5ZaeYGN/Ak0oa73pDr7vARWhC+/sQPJrwgxVKQnogkScXpZbkuR8LNeonf5xJ9lrxBQ
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2229
VhDlroyzhRwwrJGB+ZVP7i1JTVK3HrE/Jtd9pkVcgJN6t4XHu5LRv2VgUGuxQqfdjdy09ZFPHmzQ
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2230
e/pgJ8F88GW8BuVf1NWAV3LLfmjv8Z/tUO+HiAVu0FRvFQ9C9KB/66ul8QH3UkPDQk/vt559Evzw
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2231
2liP1lrI1tGSfftCu7LTEkK0Su0jks6BKuOUWj+gMbmnjdEP7dOQzyrZ39bX75b3NCB5aB8gP+M9
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2232
hLcbPtGWUFl1c0aD3szkrUzBLoC1MnX0OA5V0PdmMXaN65G0QcJ/HIa/apc/zm4orHvx14uRePH6
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2233
Hfx9Lt+AjcJzUCPxN0BLvMhLiN/4JB8dscaS/IoDs7xWeFiKoFFOnU+joz9kamJ4dpi/12cF/EMC
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2234
VgMJDNzRCcYrEADFBmemAZ1zbUyxqX+H3+a4TsvhM85YH3VC/dIZJTTnGFT3IEOh5ke6x5HT5WN4
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2235
efHi/PXVeVTdIeOYn+G108YNQP3NJklqFx+VuIszEvbJtMYnGorjo/4k06LHRdVhnjkTgWGe2IcY
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2236
oLChHR+4j60jH5cYq4tiM8unEbYUAz7nKKo1+KxDJ6K716h6Fg1hDYZ6A6hxnPEx0EeE8Jya6ClQ
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2237
Qxo/nuD5H34chVuM3EhQEhb+d3Cznrk5XH2QgyYUtFFrpjnw+zdqZsmU1RAtDxFqp5bw9sRbmsRq
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2238
NZm6577eZEJfkQAahJLych7XaSVkBiELRdJ0Vh3UqHtUi8WEV5ptBZ1folxIuo43yqk0iZUIcVTa
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2239
VJW4e0CJNQh0f45vWNniGTJR89lIgE6IUnSSO11VPV2yGHPAoTVcZz97nWRPj8MOkXlQDkCnqqE2
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2240
TBTdMkZpIStNAH4wGH580uygUyJ26pUhTgtdbQjfDg4OQvHf93sUjEGU5vkNuDoAsdcTuKTXW6yh
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2241
npNdpJ56P/MqAlacLuVHeHBNeWL7vM4o7bejKy2EtP83MHhNGjY0HVrGjlNiJe+HcgveVtF25Jcs
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2242
oRtQMHEjUdXqi2QwqWMkiXgRlMB+rKZJss/hP6zDJq/xbBUm8TSjyDvg9QTBjPAt7uNwBLtEv40q
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2243
Gi3bWHRgLgQ45NIhHo4ObNKJIkB0/Haj8RxfZEnVHAV47G7y6VPBlb3ZRDOUiNcoE2YiLWo4B/U8
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2244
Jm1WE37vYk4vFsinH5+0yticefLr+5AHpgYhy+dzgyo8NMs0zWU5NeYU1yyZJpUDxrRDONyZbnSh
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2245
/HYU9KAUgjInGzCzwmzf/smujIvpG9rwPDQj6YKUyt6Sw2mXOGsVkEVRMz4leCwhLeeaL3Ru4DXl
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2246
jbUr4A0m/qS5HqvBvdP87qG0OtOn9LnSoDm6D3DoZhirHC1HeorCuY7Iwme+3XK0Hj8U/TJyt0lZ
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2247
1XE61ofBx+jCje0WsEbUHmbaeVDPeikjtILJ4lCXYqPrMGxO7WGxpSmuh/hfh/+Re0DIP0tT5OgA
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2248
HrOPBJ4EkmY2NodcTX7mo2VYe2CQq91Chy0Q1FfmCEqvy9tTNSd+EIOnIwhMW8fnig1eygIDPJph
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2249
KNtTKOZEyQav9vl28cOpGDwZiW92QI+2DHBy7I7QDu9aELYCeXrt8AUf/ugcm3AXjbcXiGx4fOL+
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2250
pqaGbaRRGl63qd2lyvdElD+3iMJnsXTZ6JMvGztcgdDOEzk7fKSQEBqXRi9uZy0aFs8j6zI3MlZ8
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2251
FFfsc0ncPp/inUAksG6UkKOOjIdqRzFnfLXq4AOQKOdst+wZblNU0aows/c+YfWZxq9FLAAw7tsw
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2252
4mteQnyvaeH6RVv3EXXttQXbEx/rs3K8LdQ0DHwR2OWAPZQDcZ/rfubDLUNT1ugLyBdw+sO3rR3G
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2253
/uOZiQu7t20AdrD+khp8zzfoLbXvWe/d5e6epNoa94YbzKc/K+XxUV/X3yVPDpRGssCVNHfLkRN4
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2254
gkWruClMd3jo4tUV3t5G27NorFLpujQc2vI1PehjUDRPlUmwNODl1HPcTb2ly+jOFFVQvT1/K74+
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2255
fjIyJy8ZkJ7A0+jpV/rONupmTpf7HvBIh1TwUvc7jv7LAZZUfm/7qhNt0LROW3e3+INx5mgYjS0d
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2256
GvNzfzF+s2axwEvOGmKy42uvW3gFfsgEPBBzW2EOvhTEiVEfuq5CaYR7m+b7nfLtK03EYJfkbFOU
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2257
u5TkF/O17tVvLTBMRzZexvwGPa66OLG5LGM/cBNv4Nb5EYPc9B7zYduBlrW6CXdNn/vvmrtuEdiZ
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2258
m+35ztz943kuDXTf7RazjwacQtCEeFCZe6POreHw5uXRyNX4I10i0i2IdlvhPLdYjE4/U3KCiWri
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2259
Ro2sYc5VPHW/Y03SId9+2lMq5JyecxmiNd2O4m9z+kO8AS7jwOf2GDbV5sw05+l4hO61GnPZ5Fgu
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2260
Fmoc46VqYwpjqTKpE52YuOgVXYklY7Ux0Qxe9AIgDBvpYky34Bo4AjQeX+7KlT3OJR6ChqY6Uqcw
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2261
VSUzVuw6dAJwEWcgqb/JgXNlaZhKTCWruixKiDdDfQUol5z0Vbs2QE12bBWrG4O66THSN0KSeqQ6
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2262
J3MAk/OerXoVIAKb4o6CH4/tO+Cax82R9GRkuUFm9UqWcdVcxeLvaicQIDUj0GldXF0n9dWIY4tN
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2263
XMQSyxwOUpiFst+/gsDNj1p3nEEfWj33cH6iHjql+iXH2x2bMnSCfiymuyfo9yuPvzDo9+B/SdDP
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2264
JfxlincdpHh/loOczvCYNBRG53QiwL/wEP7rlo0AYSYbTcMFlt1QZifWa+q0X+b5zXjMBv1ibrwk
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2265
HkfrN11abS6SHlEj7MfZG6Vzhu/jCe63MesroSeEGOIuHPKiQUX860hveIxBVKlIHDqYr3yBI0Ih
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2266
A6xHz0HGymQ2wzvDWIV4eRbcUfbWQCPPVok2CGD2XLV99f7s3ftf3joDeVsPBsuxocOgm/oHCbxL
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2267
qkZjd28W4nYGRO+7Zs3bvlsv0zQC0Yy7J97BCKYiyL/aG4+RIJ8MuSRzFW/MrVwyy+vFkmsBYC4O
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2268
NH/RjMHGVnih7hyMYGXKiTKaHFcSWEIyjjzn8YyyoEbJmcek6eAV3ZsX+n6L11Vf+4lbuzQmejq4
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2269
w0i7Cm7LNon4De50KTmGnuNJAqYtxL/i/y6A7mND+HB38cQWQODunAgHxHYusCDwCxdTIa2cDLBe
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2270
8DdXvV76WWbe8I4kH5wj/2mFFwLQFamKoyq+TFxVgu+5Fu0d8T0+YcE1ryW6cFkuItqRL6fMIgMY
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2271
J0ISmwda0igE1pVlDTi8q/vNlfgAtkCvzNB0wKQ+XYltThDifacZjz6l6vx1G7l1zC4A32mqoeiL
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2272
T/1wg5VnD9dgpn085YOKRrGMwXwvwOwN0Zl83KbvBZYQWcWzxqvP83iGKs7oXMCopaqiFgysYl7U
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2273
eIySrrQzN8VjqHqbJzMun0YJNcPgFZ2gQFpgaIfNvUaRSgjXRs5IHyOCeJtbPNtYGyBnLUDVsiTp
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2274
bms7VNgjLP5pE0GXAUzqhXK3oROlavnNd19/s7dSiyd//u7bp996Hc10tlwZ5xxsCf+F+aGwRcdW
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2275
LVrvlpsvP2ZJSYT0j949uF5p6rIOflDhr0t0PTTA9oGtrbh5+HkgdiDoIDl4Ba1e59UrdBIJ35F4
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2276
K0u6FyrP6MGWspe91jks/mcIUFdSEEDWjn8jWuhCbAOjCxB6lx6W/M9Pejt2qcjmMDKWc+CRwwk1
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2277
ejwPrDVqG1xwjbwNAWua2XLaehvK5LgLBnacqlyMF3fCm+O2TsEcbdCXVOIFlaU8tP9Chr5z2oKj
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2278
zuBPLcp4pbRS44iVDyf4N8aiI0aOdl1ENnfAkJvIDm8wRBT3lbkTM3Kxb/sZPTvFeDLaaka9xQ5I
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2279
GJowMuPW9VUuSNvXh/nPpND3zX0xSNvV3g8MikAvi46Wes/X3bPhZXICPTtDvXzAnqd7P3DA7Apx
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2280
whibbRRxm3+XrhnFPdtW5Cq5C+3l+ByAOoeb8MRW90JM6vozM4OTsPCuIqWnP16+eX52SXQYvz17
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2281
8T9nP1LpNUpsK5x/8CZflh8ypQ+901ruhp+ul+0bvEG25+ZqPvmrIXTedwoNeyD0n/LuW5x2pOe+
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2282
3tahc1i22wkQ3z3tFtRtMW0v5E7KSl8F5tbItg5lBfopn6Axv5zqQ/PIVAq5Y/XcIvLUOZnSjSdZ
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2283
LpoqIgO8qf/QAWtnb3zbqjvDdWNrnQfUN1Nv2bgf2uNYtHwY5SFz2qoPc0TVVhZw/qf9jxeR94UH
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2284
/M1dbiCXU+lcLkz3CjOoyv9XkkqI/NGf0v8e0cj+iwPUjitclP2nNLBUbaqDnM4J++783IrVmUy3
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2285
UAHUJatKc18uo2JUp64HsxWUj5T4eEjXbhyiArq2v3DVdPrwrwnWSVb22knFRcxsyqDxvE7d2kfb
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2286
p9OBsmpUUZPPnSOooAWPgNKNdCuQDkxIsY2bbMT+I7Wvc154hIYoqe+MdZBHJ8XB3lDrsTjcdteD
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2287
e9eBEE+2N5y1rlPQPY65h7qnh6rNgXrH0uFRjm2XOIgfCDIXZQm6bdJL+GENoN4dga+3H5+c2OoI
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2288
5Hh87eghqjgPrdE5FR8dP3nn5cZOd/z66U/l55HdQMHk/rA9ynXYOvO1PYfcOcO6Jc9syjMZUui9
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2289
799fND28f1gkDNq4Wg48oZmJwafPQzs75/yunoJ9MuxOu9Fi20DxiWQXFB1h7oLq6EXxqMT9qPZz
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2290
52DJhg+HDR7bY2V0bbxbNBM6ckLOmM8j3MMk85uZtrvTfR4P6s4omv7coM2TevlB3NkZ4Vb+fvV2
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2291
M9GeesMTW3wKvhqlv/+TB/TvHn6w3Y93JX1sq6e9R/rZ38UTM1jc3OZS8zwCywOqdEAK/JEYWNnH
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2292
W9QaQroM1UwOGYPCH3K4MUA6xYwZ+cZj7VRYQxH8Pz99ANE=
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2293
"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2294
)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2295
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2296
# file activate.sh
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2297
ACTIVATE_SH = convert(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2298
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2299
eJytVW1P2zAQ/u5fcaQVG9s6VvjGVLQyKoEELWo6JjZQMMmVWEudynYK5eW/75w3kgbYh9EPbe27
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2300
s5977p5zCyah0DAVEcIs0QauEBKNAdwIE4Kj40T5CFdCbnLfiAU36MCHqYpncMV1+IG1YBkn4HMp
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2301
YwMqkSAMBEKhb6IlY0xM4Tc47fu9vnvguaMf4++DzqMDPdr74sDFVzAhSgb0QT+MwTmjw1IY+cXG
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2302
gtO+EnOzA+ftYtsG765vZYG3dOX2NpsKxgIsUML7DbhP7YnUaKAzhfkyiH3Y3QxwsSmTKIKt3fUu
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2303
S31aoNB6xVEAKBdCxXKG0sCCK8GvItS51xpl07mD9v1pf/zRe4QLijOJkhqMShAoWzIAQQ7Qj7gi
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2304
GrkBHkVpOFnzeCLEGx3te6eH48mP/pF30p8c7NB5xAhUKLEfa+o57Ya7U3rg7TxWJnUs97KcG0Gp
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2305
nXj6B5qzycFoeDA6HrwAqbQ3gJWWJrzS9CrIupctaUZ82qQ6jBMqUICG2ivtP+AygDsdfoKbUPgh
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2306
hHyBwOmHTH48m1mzCakGtqfyo6jBfSoJ1cbEcE0IqH3o3zRWdjHn1Hx5qP4M8JNkECcmNxshr/Nj
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2307
ao6WIGhbisEPubxGDTekJx7YryVYbdC11GNzQo5BUQCiXxbq6KRUPzyUm79IMaeDsXs4GnaeK0Oa
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2308
ZEdRF5cdXSPtlQK73Rcq63YbJXW7zVq63VeLmJsLIJlLYR0MT5/SX7PYuvlEkLEMUJOQrIRxBV4L
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2309
XIymUDisrQDoWFOh/eL2R0bjKbMLpTDCBa9pujIt6nczVkHbczyvsvQ8h+U8VFNiDbERk5lQ80XF
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2310
e9Pz9g6H3rB/PPC8ndytquMS95MgLGG0w2plfU2qLwjLwlqR6epV6SjN2jO9pZr9/qHb3zsaeCfj
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2311
0fHJpNGYq43QsyBdW+Gnoju3T4RmxxCnsNaD2xc6suleOxQjjfWA95c0HFDyGcJ5jfhz53IDasH5
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2312
NKx0tk2+Bcf8D4JOFNrZkEgeCa7zF4SSEOadprmukAdLC1ghq3pUJFl9b9bXV04itdt3g7FsWT5Z
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2313
8yUNHQmdWe7ntL85WTe/yRx8gxn4n/Pvf2bfc3OPavYXWw6XFQ==
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2314
"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2315
)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2316
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2317
# file activate.fish
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2318
ACTIVATE_FISH = convert(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2319
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2320
eJytVm1v2zYQ/q5fcZUdyClqGVuHfQgwDGnjIQYSO3DcAMM6yLREWxxo0iMpty7243ekLImy5RQY
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2321
lg+xTd7rc3cPrweLnGlYM05hW2gDKwqFphn+Y2IDSy0LlVJYMTEiqWF7Ymi8ZjpfwtsvzORMAAFV
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2322
CGGF7TkMIDdmdzMa2V86p5zHqdzCNWiqNZPibRz04E6CkMYqAjOQMUVTww9xEKwLgV6kgGRFdM7W
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2323
h2RHTA7DDMKPUuypMhodOkfuwkjQckttIBuwKpASAWhObgT7RsMA8E9T41SOxvpEbfb1hVWqLhqh
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2324
P37400mspXKO8FAZwGx9mR/jeHiU67AW9psfN/3aSBkSFVn5meYSPMHAXngoWG+XUHDpnqPgwOlA
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2325
oXRlc4d/wCiIbiKIPovoxGVGqzpbf9H4KxZoz5QpCKdiD1uZUSAiQ+umUMK6NjnFaqot4ZgWikqx
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2326
pcLEkfPaQ0ELjOSZfwt7ohhZcaqdFFuDodh8Q4GwJbOHu+RlMl98un1Inm4X92ENcc81l8bu2mDz
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2327
FSvbWq7Rhq7T/K9M64Lq0U/vfwbCDVXY0tYW5Bg8R5xqm5XvQQnQb5Pn++RlPH+ezKYlUGEcQvhZ
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2328
hNfYFDDkBt7XulXZh5uvpfVBu2LnuVzXupRretnQuWajeOydWodCt7Ar7Hfg/X1xP5vezx7HYXAW
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2329
R313Gk198XocbbFXonGYP81nj0+LZIbYzyd3TTy22aru1DD8GxLsJQdzslNyuzNedzxjGNj5FE8P
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2330
wGWKLbl0E5tUFlxdlrZtCefyi2teRbdyj6JyDUvP7rLiQM87XcbtnDmcmw+8iMaKaOoNUKRPfJSz
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2331
pI1U1AUjFdswQXjjx3cPXXl7AukZOt/ToJfx9IvaVaJ2WY/SVfXH05d2uUPHPThDIbz5BSIhRYbH
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2332
qrBsQ6NWEfl6WN296Y55d8hk2n3VENiFdP2X5YKIP8R1li7THnwSNlOmFOV0T3wqiwOPPNv5BUE1
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2333
VR4+ECaJ9zNJQmv//2O4/8hsVaRnpILs1nqV+yWh1UR2WdFJOgBbJBf2vfRHSfJhMk2mt49jROKo
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2334
UuO97Dd0srQ9hYdxUH5aUjghm+5QPELrkqe+lfar2PTb7mByPBhuy7PjNuGka2L71s4suZs83354
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2335
GB/nJzw+jB/l7uBGPi2wmbCR2sRQ+yZIGaczeqSh1uT7Q3820y3xTk7AwSN72gqorw0xhX7n1iBP
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2336
R6MUsXub3nFywBXujBSt+1K5MuKT4lMZpMRNRjHcJ9DqHj+zXz2ZydquiO/gL7uU7hTdIcQuOH+L
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2337
EGRLG9/+w9JM1pG0kuaBc2VUTJg1RFf6Sked4jDAXJJUcsy9XG9eebsbc4MrfQ1RhzIMcHiojbjd
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2338
HaFntuLSEoJ5x7NQw1nr2NkOqV3T+g3qIQ54ubrXgp0032bvamC6yP4kaNfx/wIsXsYv
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2339
"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2340
)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2341
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2342
# file activate.csh
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2343
ACTIVATE_CSH = convert(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2344
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2345
eJx9VNtO4zAQffdXDKEiUEFhX8t22bJFWqRyEVuQVkKy3Hi6sZQ44Dit+sK379hJittG5KGqPZdz
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2346
fOZyCLNUlbBQGUJelRbmCFWJElbKphCVRWUShLnS5yKxaiksDpIyjaC/MEUO9Lc/YIfwt6ggEVoX
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2347
FkylQVmQymBis7Wz/jJIcRLma5iIpZIIEwXXmSgVfJf+Qs5//suFygZJkf8YMFaiBY2rTGkcxa8s
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2348
ZkxkSpQgsWUBsUVi27viD9MJf7l9mj2Pp/xxPPsNByO4gKMjoCSol+Dvot6e3/A9cl6VdmB71ksw
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2349
mIoyvYROnKeHu8dZiARvpMebHe0CeccvoLz9sjY5tq3h5v6lgY5eD4b9yGFFutCSrkzlRMAm554y
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2350
we3bWhYJqXcIzx5bGYMZLoW2sBRGiXmG5YAFsdsIvhA7rCDiPDhyHtXl2lOQpGhkZtuVCKKH7+ec
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2351
X9/e8/vx3Q3nw00EfWoBxwFWrRTBeSWiE7Apagb0OXRKz7XIEUbQFcMwK7HLOT6OtwlZQo9PIGao
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2352
pVrULKj64Ysnt3/G19ObtgkCJrXzF74jRz2MaCnJgtcN5B7wLfK2DedOp4vGydPcet5urq2XBEZv
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2353
DcnQpBZVJt0KUBqEa4YzpS0a3x7odFOm0Dlqe9oEkN8qVUlK01/iKfSa3LRRKmqkBc2vBKFpmyCs
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2354
XG4d2yYyEQZBzIvKOgLN+JDveiVoaXyqedVYOkTrmCRqutrfNVHr6xMFBhh9QD/qNQuGLvq72d03
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2355
3Jy2CtGCf0rca/tp+N4BXqsflKquRr0L2sjmuClOu+/8/NKvTQsNZ3l9ZqxeTew//1a6EA==
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2356
"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2357
)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2358
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2359
# file activate.xsh
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2360
ACTIVATE_XSH = convert(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2361
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2362
eJyNU11PwjAUfe+vuNY9sIj7ASQ+YCSBRD6i02gIaSq7gyWjXdqyaIz/3XYwVmB+9GFZ78c57T2n
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2363
lNIXKfQa+NJkJTcIeqmywkAqFZSZMlueoygppSRVcgPvrjgyUuYask0hlYEVGqaxAK6B7f8JSTAF
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2364
lmCN2uFqpcMeAbuyFGjxkcglhUwAzzOuUe9SbiWY18H5vm5B6sbgM4qir8jSdCib3t+x59FD/NS/
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2365
Z7N+PKRdoDRskAIXhBsIziqPyFrSf9O9xsPpZDgdD85JD6lz6kPqtwM0RYdx1bnB5Lka2u5cxzML
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2366
vKLWTjZ7mI5n8b8A9rUNjpAiQW3U1gmKFIQ0lXpW1gblEh4xT6EuvGjXtHGFE5ZcwlZotGhKYY4l
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2367
FwZKrjL+lqMmvoXmp4dYhKQV1M7d6yPEv5jNKcqYf1VGbcmZB5x4lRcCfzfvLXaBiCdJ5wj46uD+
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2368
Tmg3luR2NGGT/nhgGbpgX48wN7HaYhcUFjlfYrULCTkxWru36jF59rJ9NlJlf7JQde5j11VS+yZr
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2369
0d22eUPaxdycLKMTvqWjR3610emDtgTu36ylcJe83rhv/di/AYN1UZY=
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2370
"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2371
)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2372
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2373
# file activate.bat
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2374
ACTIVATE_BAT = convert(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2375
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2376
eJyVk1FLhEAUhd8X/A8XWSkf28dCyMUpBR3FzAiCS+WYwq4TOdXfb0Z3dTJdyCfveO85n8frNXut
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2377
OPCyNFbGqmUCzDxIs3s3REJzB1GrEE3VVJdQsLJuWAEYh97QkaRxlGRwbqxAXp1Uf+RYM32W1LKB
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2378
7Vp2nJC6DReD9m+5qeQ6Wd+a/SN7dlzn9oI7dxsSXJCcoXOskfLgYXdv/j8LnXiM8iGg/RmiZmOr
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2379
bFMSgcebMwGfKhgbBIfnL14X8P7BX3Zs38J3LSoQFdtD3YCVuJlvnfgmj5kfUz+OCLxxqUWoF9zk
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2380
qtYAFyZkBsO9ArzUh/td0ZqP9IskElTFMsnwb4/GqeoLPUlZT5dJvf8Id5hQIONynUSa2G0Wc+m8
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2381
Z+w2w4/Tt2hbYT0hbgOK1I0I4tUw/QOTZfLE
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2382
"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2383
)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2384
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2385
# file deactivate.bat
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2386
DEACTIVATE_BAT = convert(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2387
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2388
eJyFkN0KgkAUhO8F32EQpHqFQEjQUPAPMaErqVxzId3IrV6/3ST/UDp3c86c4WN25FIysKJQFVVp
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2389
CEfqxsnB9DI7SA25i20fFqtXHM+GYL0BZzi9GM1xf7DzjVQN3pSX4CWpQGvokZk4uqrQAjXjyElB
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2390
a5IjCz0r+2VHcehHCa5MZNmB5e7TdqMqECMptHZh6DN/utb7Zs6CejsO/QNzTJwwcELfHgJJPcTp
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2391
TFOk7rCM1f92aG38HzBR5KgjoYdIQk5hZPWLGNLfd/MN+wANyJE5
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2392
"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2393
)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2394
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2395
# file activate.ps1
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2396
ACTIVATE_PS = convert(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2397
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2398
eJytVU1v4jAQvftXTNNoF9QNvSP1kG6RikQpIiyX3ZXlJkOx5NiR46RFK/77Oh+QkEBVrXYOSPZ8
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2399
+L2ZN8FNQ80TM149TgO68FePcAduvOMyVyEzXMlRvAtVHDMZjRJmtsStE+79YEIfpksbHySCG29h
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2400
vTBYYqpEjtXJcY9lb0cjZwj2WqM0hGwyGRbV4VWoFybGETJ7zpnBwc/0jZtw+xvcuZIPmBqdFS4c
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2401
wh8C1vgGBit7XT2RM83Zi8AxfZ490PV0ufrhz8oXD/GFuSjz8YHd5ZRj/BJjZUms60hweqEOeEGo
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2402
EqwJlJl7cgbggemYKhHRnGuTMUETreLEnEA8Bla+AulHuV2sU4Nx89ivSxktjGVTDpwm83UbTbto
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2403
Jwy8idZK+9X8Ai7sQMXuu5KGywy7j1xdmGJh1xCg2EBUe68+ptRI5OO4ZBepsIax7yutdNcgkp3Z
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2404
Wo8XQ3XrMv2aFknXkMkUDXCtUWDOpDkKLSUNEPCkklFDjhC33Sg7wcOWkG6zC2frSMgc3xq9nWgL
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2405
vDmLEXoSBBsvMmzETUhb5073yVtK76dzOvefJtRaEUaDyYJSB25aRaqpdXIth8C/n03oYvn8tFgd
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2406
ptht7hnVtebtOPVYTvV+Lumutw+NpBzatKFEUzDwpN1Sp62u3uC7cCoJ+lEEZosQZqlRVggaN/wd
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2407
jCov8Z2nVtav0Nm5koANzbnK0hozzctp3MGXTy5uYefJ3FwoPjzm7ludRJHiv/FmHbphpovPc832
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2408
G7xkBiIlv9pfnoZMR8DN6P83wZX41s13Bu6g/cfS2x9vhmwDwyE4pw3tF/t8N/fkLzQ3ME8=
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2409
"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2410
)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2411
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2412
# file distutils-init.py
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2413
DISTUTILS_INIT = convert(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2414
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2415
eJytV21v5DQQ/p5fMaRCJLANcAcSqlghuBdUcRzo6BdUnSI3cXZNs3bO9m679+uZsbOJnWR7fKBS
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2416
u65nPC/PvK7YdUpbUCYR/mSOw/GBaSnkxiTJBaiuUjUHYUAqCwwOQts9a7k8wE7V+5avwCh44FAx
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2417
CXuDnBasgkbIGuyWg7F1K+5Q0LWTzaT9DG7wgdL3oCR0x+64QkaUv9sbC3ccdXjBeMssaG5EzQ0I
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2418
SeJQDkq77I52q+TXyCcawevLx+JYfIRaaF5ZpY8nP7ztSYIEyXYc1uhu0TG7LfobIhm7t6I1Jd0H
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2419
HP8oIbMJe+YFFmXZiJaXZb6CdBCQ5olohudS6R0dslhBDuuZEdnszSA/v0oAf07xKOiQpTcIaxCG
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2420
QQN0rLpnG0TQwucGWNdxpg1FA1H1+IEhHFpVMSsQfWb85dFYvhsF/YS+8NZwr710lpdlIaTh2mbf
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2421
rGDqFFxgdnxgV/D6h2ffukcIBUotDlwbVFQK2Sj4EbLnK/iud8px+TjhRzLcac7acvRpTdSiVawu
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2422
fVpkaTk6PzKmK3irJJ/atoIsRRL9kpw/f/u1fHn97tWLmz/e/Z3nTunoaWwSfmCuFTtWbYXkmFUD
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2423
z9NJMzUgLdF9YRHA7pjmgxByiWvv31RV8Zfa64q/xix449jOOz0JxejH2QB8HwQg8NgeO26SiDIL
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2424
heMpfndxuMFz5p0oKI1H1TGgi6CSwFiX6XgVgUEsBd2WjVa70msKFa56CPOnbZ5I9EnkZZL0jP5M
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2425
o1LwR9Tb51ssMfdmX8AL1R1d9Wje8gP2NSw7q8Xd3iKMxGL1cUShLDU/CBeKEo2KZRYh1efkY8U7
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2426
Cz+fJL7SWulRWseM6WvzFOBFqQMxScjhoFX0EaGLFSVKpWQjNuSXMEi4MvcCa3Jw4Y4ZbtAWuUl6
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2427
095iBAKrRga0Aw80OjAhqy3c7UVbl/zRwlgZUCtu5BcW7qV6gC3+YpPacOvwxFCZoJc7OVuaFQ84
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2428
U9SDgUuaMVuma2rGvoMRC3Y8rfb92HG6ee1qoNO8EY8YuL4mupbZBnst9eIUhT5/lnonYoyKSu12
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2429
TNbF6EGP2niBDVThcbjwyVG1GJ+RK4tYguqreUODkrXiIy9VRy3ZZIa3zbRC0W68LRAZzfQRQ4xt
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2430
HScmNbyY01XSjHUNt+8jNt6iSMw3aXAgVzybPVkFAc3/m4rZHRZvK+xpuhne5ZOKnz0YB0zUUClm
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2431
LrV9ILGjvsEUSfO48COQi2VYkyfCvBjc4Z++GXgB09sgQ9YQ5MJFoIVOfVaaqyQha2lHKn3huYFP
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2432
KBJb8VIYX/doeTHjSnBr8YkT34eZ07hCWMOimh6LPrMQar8cYTF0yojHdIw37nPavenXpxRHWABc
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2433
s0kXJujs0eKbKdcs4qdgR4yh1Y5dGCJlMdNoC5Y5NgvcbXD9adGIzAEzLy/iKbiszYPA/Wtm8UIJ
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2434
OEGYljt14Bk9z5OYROuXrLMF8zW3ey09W+JX0E+EHPFZSIMwvcYWHucYNtXSb8u4AtCAHRiLmNRn
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2435
1UCevMyoabqBiRt3tcYS9fFZUw/q4UEc/eW8N/X3Tn1YyyEec3NjpSeVWMXJOTNx5tWqcsNwLu5E
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2436
TM5hEMJTTuGZyMPGdQ5N+r7zBJpInqNJjbjGkUbUs+iGTEAt63+Ee2ZVbNMnwacF6yz4AXEZ/Ama
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2437
5RTNk7yefGB+5ESiAtoi/AE9+5LpjemBdfj0Ehf09Lzht5qzCwT9oL00zZZaWjzEWjfEwoU9mMiD
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2438
UbThVzZ34U7fXP+C315S91UcO9rAFLen4fr29OA9WnOyC1c8Zu5xNaLeyNo2WNvPmkCtc2ICqidc
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2439
zmg+LaPu/BXc9srfx9pJbJiSw5NZkgXxWMiyBWpyNjdmeRbmzb+31cHS
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2440
"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2441
)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2442
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2443
# file distutils.cfg
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2444
DISTUTILS_CFG = convert(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2445
    """
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2446
eJxNj00KwkAMhfc9xYNuxe4Ft57AjYiUtDO1wXSmNJnK3N5pdSEEAu8nH6lxHVlRhtDHMPATA4uH
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2447
xJ4EFmGbvfJiicSHFRzUSISMY6hq3GLCRLnIvSTnEefN0FIjw5tF0Hkk9Q5dRunBsVoyFi24aaLg
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2448
9FDOlL0FPGluf4QjcInLlxd6f6rqkgPu/5nHLg0cXCscXoozRrP51DRT3j9QNl99AP53T2Q=
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2449
"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2450
)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2451
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2452
# file activate_this.py
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2453
ACTIVATE_THIS = convert(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2454
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2455
eJylVE1v2zAMvetXENqh9pZ5wHYL0EMOBdqh64It7RAEhaE4TKzOlgxJ+ULR/15Sdhr341BsOcSW
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2456
9fj4SD5JSjkqgt6ogLDRLqxVhWYDS+ugWDuHJoA2AV3jkP6HQlx7BNxhkdgGTRJK7fOlrjDNHKpF
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2457
kg7g/iSPX/L8ZAhP+w9pJsSEVlAoA3OEtccFbEs0sLdrqNc+8CegTdxpH7RZwXgfSmv6+QdgbCDS
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2458
Z1rn2nxpIjQTUkqh68a6ANYf3rwO+PS+90IEtx8KoN9BqcBdgU2AK1XjmXPWtdtOaZI08h5d0NbE
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2459
nURO+3r/qRWpTIX4AFQTBS64AAgWxqPJOUQaYBjQUxuvFxgLZtBCOyyCdftU0DKnJZxSnVmjQpnR
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2460
ypD85LBWc8/P5CAhTQVtUcO0s2YmOZu8PcZ7bLI7q00y66hv4RMcA7IVhqQNGoCUaeabSofkGEz0
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2461
Yq6oI68VdYSx5m5uwIOjAp1elQHU3G5eVPhM683Fr8n16DI/u7qJkjkPk6nFom8G6AJqcq2PU//c
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2462
qOKvWiG3l4GlpbE1na1aQ9RYlMpoX4uL3/l4Op4Sf6m8CsElZBYqttk3+3yDzpMFcm2WlqZH2O/T
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2463
yfnPK0ITKmsqFejM1JkPygW/1dR4eac2irB6CU/w1lcsLe+k+V7DYv+5OMp6qefc6X4VnsiwaulY
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2464
6fvJXrN4bKOJ6s/Fyyrg9BTkVptvX2UEtSkJ18b8ZwkcfhTwXrKqJWuHd/+Q3T/IjLWqkHxk7f0B
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2465
pW9kFXTaNlwn+TjWSglSwaiMbMRP8l7yTAltE5AOc5VT8FLvDm2KC3F87VnyBzuZrUakdMERXe0P
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2466
7luSN+leWsYF5x/QAQdqeoHC4JZYKrr5+uq6t9mQXT/T8VrWHMRwmoqO9yGTUHF8YN/EHPbFI/bz
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2467
/no=
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2468
"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2469
)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2470
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2471
# file python-config
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2472
PYTHON_CONFIG = convert(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2473
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2474
eJyNVV1P2zAUfc+v8ODBiSABxlulTipbO6p1LWqBgVhlhcZpPYUkctzSivHfd6+dpGloGH2Ja/ue
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2475
e+65Hz78xNhtf3x90xmw7vCWsRPGLvpDNuz87MKfdKMWSWxZ4ilNpCLZJiuWc66SVFUOZkkcirll
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2476
rfxIBAzOMtImDzSVPBRrekwoX/OZu/0r4lm0DHiG60g86u8sjPw5rCyy86NRkB8QuuBRSqfAKESn
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2477
3orLTCQxE3GYkC9tYp8fk89OSwNsmXgizrhUtnumeSgeo5GbLUMk49Rv+2nK48Cm/qMwfp333J2/
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2478
dVcAGE0CIQHBsgIeEr4Wij0LtWDLzJ9ze5YEvH2WI6CHTAVcSu9ZCsXtgxu81CIvp6/k4eXsdfo7
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2479
PvDCRD75yi41QitfzlcPp1OI7i/1/iQitqnr0iMgQ+A6wa+IKwwdxyk9IiXNAzgquTFU8NIxAVjM
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2480
osm1Zz526e+shQ4hKRVci69nPC3Kw4NQEmkQ65E7OodxorSvxjvpBjQHDmWFIQ1mlmzlS5vedseT
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2481
/mgIEsMJ7Lxz2bLAF9M5xeLEhdbHxpWOw0GdkJApMVBRF1y+a0z3c9WZPAXGFcFrJgCIB+024uad
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2482
0CrzmEoRa3Ub4swNIHPGf7QDV+2uj2OiFWsChgCwjKqN6rp5izpbH6Wc1O1TclQTP/XVwi6anTr1
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2483
1sbubjZLI1+VptPSdCfwnFBrB1jvebrTA9uUhU2/9gad7xPqeFkaQcnnLbCViZK8d7R1kxzFrIJV
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2484
8EaLYmKYpvGVkig+3C5HCXbM1jGCGekiM2pRCVPyRyXYdPf6kcbWEQ36F5V4Gq9N7icNNw+JHwRE
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2485
LTgxRXACpvnQv/PuT0xCCAywY/K4hE6Now2qDwaSE5FB+1agsoUveYDepS83qFcF1NufvULD3fTl
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2486
g6Hgf7WBt6lzMeiyyWVn3P1WVbwaczHmTzE9A5SyItTVgFYyvs/L/fXlaNgbw8v3azT+0eikVlWD
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2487
/vBHbzQumP23uBCjsYdrL9OWARwxs/nuLOzeXbPJTa/Xv6sUmQir5pC1YRLz3eA+CD8Z0XpcW8v9
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2488
MZWF36ryyXXf3yBIz6nzqz8Muyz0m5Qj7OexfYo/Ph3LqvkHUg7AuA==
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2489
"""
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2490
)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2491
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2492
MH_MAGIC = 0xFEEDFACE
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2493
MH_CIGAM = 0xCEFAEDFE
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2494
MH_MAGIC_64 = 0xFEEDFACF
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2495
MH_CIGAM_64 = 0xCFFAEDFE
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2496
FAT_MAGIC = 0xCAFEBABE
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2497
BIG_ENDIAN = ">"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2498
LITTLE_ENDIAN = "<"
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2499
LC_LOAD_DYLIB = 0xC
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2500
maxint = getattr(sys, "maxsize", getattr(sys, "maxint", None))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2501
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2502
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2503
class FileView(object):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2504
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2505
    A proxy for file-like objects that exposes a given view of a file.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2506
    Modified from macholib.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2507
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2508
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2509
    def __init__(self, file_obj, start=0, size=maxint):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2510
        if isinstance(file_obj, FileView):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2511
            self._file_obj = file_obj._file_obj
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2512
        else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2513
            self._file_obj = file_obj
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2514
        self._start = start
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2515
        self._end = start + size
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2516
        self._pos = 0
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2517
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2518
    def __repr__(self):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2519
        return "<fileview [{:d}, {:d}] {!r}>".format(self._start, self._end, self._file_obj)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2520
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2521
    def tell(self):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2522
        return self._pos
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2523
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2524
    def _checkwindow(self, seek_to, op):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2525
        if not (self._start <= seek_to <= self._end):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2526
            raise IOError(
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2527
                "{} to offset {:d} is outside window [{:d}, {:d}]".format(op, seek_to, self._start, self._end)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2528
            )
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2529
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2530
    def seek(self, offset, whence=0):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2531
        seek_to = offset
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2532
        if whence == os.SEEK_SET:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2533
            seek_to += self._start
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2534
        elif whence == os.SEEK_CUR:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2535
            seek_to += self._start + self._pos
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2536
        elif whence == os.SEEK_END:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2537
            seek_to += self._end
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2538
        else:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2539
            raise IOError("Invalid whence argument to seek: {!r}".format(whence))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2540
        self._checkwindow(seek_to, "seek")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2541
        self._file_obj.seek(seek_to)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2542
        self._pos = seek_to - self._start
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2543
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2544
    def write(self, content):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2545
        here = self._start + self._pos
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2546
        self._checkwindow(here, "write")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2547
        self._checkwindow(here + len(content), "write")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2548
        self._file_obj.seek(here, os.SEEK_SET)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2549
        self._file_obj.write(content)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2550
        self._pos += len(content)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2551
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2552
    def read(self, size=maxint):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2553
        assert size >= 0
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2554
        here = self._start + self._pos
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2555
        self._checkwindow(here, "read")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2556
        size = min(size, self._end - here)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2557
        self._file_obj.seek(here, os.SEEK_SET)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2558
        read_bytes = self._file_obj.read(size)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2559
        self._pos += len(read_bytes)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2560
        return read_bytes
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2561
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2562
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2563
def read_data(file, endian, num=1):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2564
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2565
    Read a given number of 32-bits unsigned integers from the given file
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2566
    with the given endianness.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2567
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2568
    res = struct.unpack(endian + "L" * num, file.read(num * 4))
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2569
    if len(res) == 1:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2570
        return res[0]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2571
    return res
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2572
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2573
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2574
def mach_o_change(at_path, what, value):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2575
    """
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2576
    Replace a given name (what) in any LC_LOAD_DYLIB command found in
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2577
    the given binary with a new name (value), provided it's shorter.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2578
    """
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2579
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2580
    def do_macho(file, bits, endian):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2581
        # Read Mach-O header (the magic number is assumed read by the caller)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2582
        cpu_type, cpu_sub_type, file_type, n_commands, size_of_commands, flags = read_data(file, endian, 6)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2583
        # 64-bits header has one more field.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2584
        if bits == 64:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2585
            read_data(file, endian)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2586
        # The header is followed by n commands
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2587
        for _ in range(n_commands):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2588
            where = file.tell()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2589
            # Read command header
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2590
            cmd, cmd_size = read_data(file, endian, 2)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2591
            if cmd == LC_LOAD_DYLIB:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2592
                # The first data field in LC_LOAD_DYLIB commands is the
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2593
                # offset of the name, starting from the beginning of the
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2594
                # command.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2595
                name_offset = read_data(file, endian)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2596
                file.seek(where + name_offset, os.SEEK_SET)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2597
                # Read the NUL terminated string
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2598
                load = file.read(cmd_size - name_offset).decode()
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2599
                load = load[: load.index("\0")]
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2600
                # If the string is what is being replaced, overwrite it.
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2601
                if load == what:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2602
                    file.seek(where + name_offset, os.SEEK_SET)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2603
                    file.write(value.encode() + b"\0")
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2604
            # Seek to the next command
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2605
            file.seek(where + cmd_size, os.SEEK_SET)
32
96296eddc5e2 try to improve virtualenv install on ubuntu
ymh <ymh.work@gmail.com>
parents:
diff changeset
  2606
98
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2607
    def do_file(file, offset=0, size=maxint):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2608
        file = FileView(file, offset, size)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2609
        # Read magic number
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2610
        magic = read_data(file, BIG_ENDIAN)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2611
        if magic == FAT_MAGIC:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2612
            # Fat binaries contain nfat_arch Mach-O binaries
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2613
            n_fat_arch = read_data(file, BIG_ENDIAN)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2614
            for _ in range(n_fat_arch):
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2615
                # Read arch header
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2616
                cpu_type, cpu_sub_type, offset, size, align = read_data(file, BIG_ENDIAN, 5)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2617
                do_file(file, offset, size)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2618
        elif magic == MH_MAGIC:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2619
            do_macho(file, 32, BIG_ENDIAN)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2620
        elif magic == MH_CIGAM:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2621
            do_macho(file, 32, LITTLE_ENDIAN)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2622
        elif magic == MH_MAGIC_64:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2623
            do_macho(file, 64, BIG_ENDIAN)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2624
        elif magic == MH_CIGAM_64:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2625
            do_macho(file, 64, LITTLE_ENDIAN)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2626
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2627
    assert len(what) >= len(value)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2628
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2629
    with open(at_path, "r+b") as f:
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2630
        do_file(f)
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2631
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2632
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2633
if __name__ == "__main__":
a14feef87fd7 increment version and upgrade librairies
ymh <ymh.work@gmail.com>
parents: 32
diff changeset
  2634
    main()