2016-08-31 09:22:19 +01:00
|
|
|
{ lib
|
|
|
|
, python
|
|
|
|
, makeSetupHook
|
|
|
|
, makeWrapper }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
makeSetupHook {
|
|
|
|
deps = makeWrapper;
|
2018-12-20 14:03:23 +00:00
|
|
|
substitutions.sitePackages = python.sitePackages;
|
2016-08-31 09:22:19 +01:00
|
|
|
substitutions.executable = python.interpreter;
|
2019-01-02 19:09:44 +00:00
|
|
|
substitutions.python = python.pythonForBuild;
|
|
|
|
substitutions.pythonHost = python;
|
2016-08-31 09:22:19 +01:00
|
|
|
substitutions.magicalSedExpression = let
|
|
|
|
# Looks weird? Of course, it's between single quoted shell strings.
|
|
|
|
# NOTE: Order DOES matter here, so single character quotes need to be
|
|
|
|
# at the last position.
|
|
|
|
quoteVariants = [ "'\"'''\"'" "\"\"\"" "\"" "'\"'\"'" ]; # hey Vim: ''
|
|
|
|
|
|
|
|
mkStringSkipper = labelNum: quote: let
|
|
|
|
label = "q${toString labelNum}";
|
|
|
|
isSingle = elem quote [ "\"" "'\"'\"'" ];
|
|
|
|
endQuote = if isSingle then "[^\\\\]${quote}" else quote;
|
|
|
|
in ''
|
|
|
|
/^[a-z]?${quote}/ {
|
|
|
|
/${quote}${quote}|${quote}.*${endQuote}/{n;br}
|
|
|
|
:${label}; n; /^${quote}/{n;br}; /${endQuote}/{n;br}; b${label}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
# This preamble does two things:
|
|
|
|
# * Sets argv[0] to the original application's name; otherwise it would be .foo-wrapped.
|
|
|
|
# Python doesn't support `exec -a`.
|
|
|
|
# * Adds all required libraries to sys.path via `site.addsitedir`. It also handles *.pth files.
|
|
|
|
preamble = ''
|
|
|
|
import sys
|
|
|
|
import site
|
|
|
|
import functools
|
2017-01-01 16:57:26 +00:00
|
|
|
sys.argv[0] = '"'$(readlink -f "$f")'"'
|
2016-08-31 09:22:19 +01:00
|
|
|
functools.reduce(lambda k, p: site.addsitedir(p, k), ['"$([ -n "$program_PYTHONPATH" ] && (echo "'$program_PYTHONPATH'" | sed "s|:|','|g") || true)"'], site._init_pathinfo())
|
|
|
|
'';
|
|
|
|
|
|
|
|
in ''
|
|
|
|
1 {
|
|
|
|
:r
|
|
|
|
/\\$|,$/{N;br}
|
|
|
|
/__future__|^ |^ *(#.*)?$/{n;br}
|
|
|
|
${concatImapStrings mkStringSkipper quoteVariants}
|
|
|
|
/^[^# ]/i ${replaceStrings ["\n"] [";"] preamble}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
} ./wrap.sh
|