Commit eaaf3845 authored by Julien Muchembled's avatar Julien Muchembled Committed by Xavier Thompson

[feat] Omit Python library in script paths

This is useful when using OS Python & eggs.

Useless for SlapOS.
parent e402be52
...@@ -20,6 +20,7 @@ installed. ...@@ -20,6 +20,7 @@ installed.
import copy import copy
import distutils.errors import distutils.errors
import distutils.sysconfig
import errno import errno
import glob import glob
import logging import logging
...@@ -101,6 +102,8 @@ pip_path = setuptools_path = [ ...@@ -101,6 +102,8 @@ pip_path = setuptools_path = [
] ]
pip_pythonpath = setuptools_pythonpath = os.pathsep.join(pip_path) pip_pythonpath = setuptools_pythonpath = os.pathsep.join(pip_path)
python_lib = distutils.sysconfig.get_python_lib()
FILE_SCHEME = re.compile('file://', re.I).match FILE_SCHEME = re.compile('file://', re.I).match
DUNDER_FILE_PATTERN = re.compile(r"__file__ = '(?P<filename>.+)'$") DUNDER_FILE_PATTERN = re.compile(r"__file__ = '(?P<filename>.+)'$")
...@@ -1162,6 +1165,10 @@ def scripts(reqs, working_set, executable, dest=None, ...@@ -1162,6 +1165,10 @@ def scripts(reqs, working_set, executable, dest=None,
if p not in unique_path: if p not in unique_path:
unique_path.append(p) unique_path.append(p)
path = [realpath(p) for p in unique_path] path = [realpath(p) for p in unique_path]
try:
path.remove(python_lib)
except ValueError:
pass
generated = [] generated = []
...@@ -1332,6 +1339,12 @@ join = os.path.join ...@@ -1332,6 +1339,12 @@ join = os.path.join
base = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
""" """
def _initialization(path, initialization):
return """sys.path[0:0] = [
%s,
]
""" % path + initialization if path else initialization
def _script(module_name, attrs, path, dest, arguments, initialization, rsetup): def _script(module_name, attrs, path, dest, arguments, initialization, rsetup):
if is_win32: if is_win32:
dest += '-script.py' dest += '-script.py'
...@@ -1340,11 +1353,10 @@ def _script(module_name, attrs, path, dest, arguments, initialization, rsetup): ...@@ -1340,11 +1353,10 @@ def _script(module_name, attrs, path, dest, arguments, initialization, rsetup):
contents = script_template % dict( contents = script_template % dict(
python = python, python = python,
path = path,
module_name = module_name, module_name = module_name,
attrs = attrs, attrs = attrs,
arguments = arguments, arguments = arguments,
initialization = initialization, initialization = _initialization(path, initialization),
relative_paths_setup = rsetup, relative_paths_setup = rsetup,
) )
return _create_script(contents, dest) return _create_script(contents, dest)
...@@ -1377,8 +1389,7 @@ def _distutils_script(path, dest, script_content, initialization, rsetup): ...@@ -1377,8 +1389,7 @@ def _distutils_script(path, dest, script_content, initialization, rsetup):
contents = distutils_script_template % dict( contents = distutils_script_template % dict(
python = python, python = python,
path = path, initialization = _initialization(path, initialization),
initialization = initialization,
relative_paths_setup = rsetup, relative_paths_setup = rsetup,
before = before, before = before,
after = after after = after
...@@ -1446,9 +1457,6 @@ script_template = script_header + '''\ ...@@ -1446,9 +1457,6 @@ script_template = script_header + '''\
%(relative_paths_setup)s %(relative_paths_setup)s
import sys import sys
sys.path[0:0] = [
%(path)s,
]
%(initialization)s %(initialization)s
import %(module_name)s import %(module_name)s
...@@ -1460,9 +1468,6 @@ distutils_script_template = script_header + ''' ...@@ -1460,9 +1468,6 @@ distutils_script_template = script_header + '''
%(before)s %(before)s
%(relative_paths_setup)s %(relative_paths_setup)s
import sys import sys
sys.path[0:0] = [
%(path)s,
]
%(initialization)s %(initialization)s
%(after)s''' %(after)s'''
...@@ -1475,14 +1480,12 @@ def _pyscript(path, dest, rsetup, initialization=''): ...@@ -1475,14 +1480,12 @@ def _pyscript(path, dest, rsetup, initialization=''):
dest += '-script.py' dest += '-script.py'
python = _safe_arg(sys.executable) python = _safe_arg(sys.executable)
if path:
path += ',' # Courtesy comma at the end of the list.
contents = py_script_template % dict( contents = py_script_template % dict(
python = python, python = python,
path = path, path = path,
relative_paths_setup = rsetup, relative_paths_setup = rsetup,
initialization=initialization, initialization = _initialization(path, initialization),
) )
changed = _file_changed(dest, contents) changed = _file_changed(dest, contents)
...@@ -1517,9 +1520,6 @@ py_script_template = script_header + '''\ ...@@ -1517,9 +1520,6 @@ py_script_template = script_header + '''\
%%(relative_paths_setup)s %%(relative_paths_setup)s
import sys import sys
sys.path[0:0] = [
%%(path)s
]
%%(initialization)s %%(initialization)s
_interactive = True _interactive = True
......
...@@ -765,9 +765,9 @@ An interpreter can also be generated without other eggs: ...@@ -765,9 +765,9 @@ An interpreter can also be generated without other eggs:
<BLANKLINE> <BLANKLINE>
import sys import sys
<BLANKLINE> <BLANKLINE>
sys.path[0:0] = [
<BLANKLINE> <BLANKLINE>
] <BLANKLINE>
_interactive = True
... ...
An additional argument can be passed to define which scripts to install An additional argument can be passed to define which scripts to install
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment