Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace magic sed for Python argv[0] with a python wrapper. #11168

Open
domenkozar opened this issue Nov 20, 2015 · 9 comments
Open

Replace magic sed for Python argv[0] with a python wrapper. #11168

domenkozar opened this issue Nov 20, 2015 · 9 comments
Labels
0.kind: enhancement Add something new 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: python

Comments

@domenkozar
Copy link
Member

Magic sed line is something that probably just @aszlig can maintain, so I propose a simplification.

Not sure what the best approach would be, but current exec -a bla also doesn't work.

@spwhitt
Copy link
Contributor

spwhitt commented Nov 20, 2015

Is my approach missing something? #7931

@domenkozar
Copy link
Member Author

Yeah I still need to review that, thanks for reminding me

@Profpatsch
Copy link
Member

(triage) was this solved?

@domenkozar
Copy link
Member Author

Nope.

@FRidh
Copy link
Member

FRidh commented May 28, 2017

We have a solution where we use sitecustomize.py to load and set sys.argv[0] from an environment variable #25985 (comment).

@mmahut
Copy link
Member

mmahut commented Aug 25, 2019

Are there any updates on this issue, please

@Profpatsch
Copy link
Member

I don’t see any magic sed line in the linked code anymore, so I’m gonna close for now.

@aszlig
Copy link
Member

aszlig commented Aug 27, 2019

@Profpatsch: This is not solved yet, it's just in a different place:

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
sys.argv[0] = '"'$(readlink -f "$f")'"'
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}
}
'';

@aszlig aszlig reopened this Aug 27, 2019
@stale
Copy link

stale bot commented Jun 2, 2020

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: enhancement Add something new 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: python
Projects
None yet
Development

No branches or pull requests

6 participants