[Python-Dev] disable writing .py[co]

Skip Montanaro skip@pobox.com
Tue, 21 Jan 2003 06:56:56 -0600


Here's a slightly different alternative.  (It woke me up this morning, so I
know it's a good idea. ;-)

Instead of an environment variable which functions simply as an on/off
switch, add an environment variable named PYCROOT which can be used to
control writing of .pyc files as follows:

    * if not present, status quo

    * if present and refers to an existing directory, prepend PYCROOT to any
      attempts to read or write .pyc files.

    * if present and refers to a non-existent or non-directory file, disable
      writing .pyc files altogether.

All that happens is that when you go to read or write a .pyc file is that
you prepend PYCROOT to the full path to the .py source file in addition to
adding a 'c' to the end.

Pros:

    * it allows people to run with .py files on read-only filesystems but
      still gain the benefits of using .pyc files

    * on systems with ram-based file systems (such as /tmp on Solaris), you
      can gain a performance boost.

    * it's easy to suppress writing .pyc files altogether.

Cons:

    * it's not obvious (to me) what the semantics should be on multi-root
      systems like Windows (I can see a couple alternatives).

    * slightly more complexity added to import.

Skip