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

Guido van Rossum guido@python.org
Wed, 22 Jan 2003 18:03:48 -0500


Quick comments:

- The envvar needs to have a name starting with "PYTHON".  See
  Misc/setuid-prog.c for the reason.

- PYC may not be the best name to identify the feature, since there's
  also .pyo.  Maybe PYTHONBYTECODEDIR?  I don't mind if it's long,
  the feature is obscure enough to deserve that.

- If the directory it refers to is not writable, attempts to write are
  skipped too (rather than always attempting to write and catching the
  failure).

- There are two problems in this line:

    os.path.join(os.environ["PYCROOT"], os.path.split(sourcefile)[0])

  (1) os.path.split(sourcefile)[0] is a lousy way of writing
      os.path.dirname(sourcefile). :-)

  (2) The way os.path.join() is defined, the first argument is ignored
      when the second argument is an absolute path, which it will
      almost always be (now that sys.path is being absolutized).

  I think the solution for (2) may be to take the path relative to the
  sys.path entry from which it was taken, and tack that onto the end
  of PYCROOT.  This means that submodule M of package X always gets
  its .pyc code written to PYCROOT/X/M.pyc.  There can't be more than
  one of those (at least not unless you have multiple Python
  interpreters with different sys.path values sharing the same
  PYCROOT).

--Guido van Rossum (home page: http://www.python.org/~guido/)