@@ -50,6 +50,32 @@ let
5050 { deps = pkgs.makeWrapper;
5151 substitutions.libPrefix = python.libPrefix;
5252 substitutions.executable = "${python}/bin/${python.executable}";
53+ substitutions.magicalSedExpression = let
54+ # Looks weird? Of course, it's between single quoted shell strings.
55+ # NOTE: Order DOES matter here, so single character quotes need to be
56+ # at the last position.
57+ quoteVariants = [ "'\"'''\"'" "\"\"\"" "\"" "'\"'\"'" ]; # hey Vim: ''
58+
59+ mkStringSkipper = labelNum: quote: let
60+ label = "q${toString labelNum}";
61+ isSingle = elem quote [ "\"" "'\"'\"'" ];
62+ endQuote = if isSingle then "[^\\\\]${quote}" else quote;
63+ in ''
64+ /^ *[a-z]?${quote}/ {
65+ /${quote}${quote}|${quote}.*${endQuote}/{n;br}
66+ :${label}; n; /^${quote}/{n;br}; /${endQuote}/{n;br}; b${label}
67+ }
68+ '';
69+
70+ in ''
71+ 1 {
72+ /^#!/!b; :r
73+ /\\$/{N;br}
74+ /__future__|^ *(#.*)?$/{n;br}
75+ ${concatImapStrings mkStringSkipper quoteVariants}
76+ /^ *[^# ]/i import sys; sys.argv[0] = '"'$(basename "$i")'"'
77+ }
78+ '';
5379 }
5480 ../development/python-modules/generic/wrap.sh;
5581