[Python-Dev] PEP: per user site-packages directory (original) (raw)

Christian Heimes lists at cheimes.de
Mon Jan 21 13:09:51 CET 2008


Jan Claeys wrote:

There should be a way for distro developers to make sure the users local 'site-packages' is not used when running those tools.

I'd rather have to set/uncomment an environment variable on my system than having 100 "normal" users break their systems accidentally... ;-)

"#!/usr/bin/env python -E -s" doesn't work on most Unices. [1] I came up with two possible solutions. Both depend on a new 'paranoid' flag -P which disables several features like PYTHON* env vars, inspect interactively, user site directory and the '' in sys.path.

A rough Python version of the C code could look like:

def find_paranoid(fname): if not os.path.isfile(fname): return data = open(fname).read(4096) if not data.startswith("#!"): return for i in (1, 2): data = data[data.find('\n'):] if data.startswith("# -- py-paranoid --"): return True return False

Christian

[1] Cygwin discussion thread about #! env http://www.cygwin.com/ml/cygwin/2002-02/msg00657.html/



More information about the Python-Dev mailing list