[Python-Dev] Proto-PEP regarding writing bytecode files

Delaney, Timothy tdelaney@avaya.com
Thu, 23 Jan 2003 09:54:16 +1100


> From: Skip Montanaro [mailto:skip@pobox.com]
> 
> Add a new environment variable, PYCROOT, to the mix of environment
> variables which Python understands.  Its interpretation is:
> 
> - If not present or present but with an empty string value, Python
>   bytecode is generated in exactly the same way as is currently done.
> 
> - If present and it refers to an existing directory, bytecode
>   files are written into a directory structure rooted at that
>   location.
> 
> - If present and it does not refer to an existing directory,
>   generation of bytecode files is suppressed altogether.

I think this is wrong behaviour. IMO it should be as follows:

- If not present Python bytecode is generated in exactly the
  same way as is currently done.

- If present and it refers to an existing directory, bytecode
  files are written into a directory structure rooted at that
  location.

- If present but empty, generation of bytecode files is
  suppressed altogether.

- If present and it does not refer to an existing directory,
  a warning is displayed and generation of bytecode files is
  suppressed altogether.

My reasoning is as follows:

1. To suppress bytecode generation, you should not have to choose an invalid
directory. Supressing bytecode should definitely be a positive action
(setting PYCROOT), but should not have false information associated with it
(setting PYCROOT to non-empty).

2. If the specified non-existing directory ever starts existing, bytecode
would begin being written to it. This would at the very least put "garbage"
into that directory, and could potentially cause all kinds of errors.

> - When looking for a bytecode file should the directory holding the
>   source file be considered as well, or just the location implied by
>   PYCROOT?  If so, which should be searched first?  It seems to me
>   that if a module lives in /usr/local/lib/python2.3/mod.py and was
>   installed by root without PYCROOT set, you'd want to use the
>   bytecode file there if it was up-to-date without ever considering
>   os.environ["PYCROOT"] + "/usr/local/lib/python2.3/".  Only if you
>   need to write out a bytecode file would anything turn up there.

I think it should always use PYCROOT.

Tim Delaney