PEP 304 - Controlling generation of bytecode files

Ian Bicking ianb at colorstudy.com
Tue Jan 28 11:13:52 EST 2003


On Tue, 2003-01-28 at 08:39, Dennis Reinhardt wrote:
> This PEP does not address explicitly how the user can change the env.
> variable during startup. Suppose I code in my main module:
> 
>     sys.pythonbytecodebase = ""
>     import file01
>     import file02
>     sys.pythonbytecodebase = "outdir/subdir"
>     import file03
>     ....  #etc.
> 
> does this give file by file control?

I would assume this would change the process globally, but since modules
are guaranteed to be imported once it could work.  But it would be
unreliable, because if file01 imported file03 that would change the
behavior.  That is, it would give per-process control.  But that's
probably not what you'd want, as all the standard library would fall
under your new pythoncodebase.

I don't remember if it said what the behavior should be if
pythoncodebase is set, but I also wouldn't want it to miss .pyc files
for the standard library if pythoncodebase was set but the standard
library was precompiled for pythoncodebase==''.

If you really wanted per-file control it should probably be done with

__pythoncodebase__ = '...'

But I'm not sure what the advantage of that would be.

> What I would really want is directory by directory control.  I am importing
> from the following example structure
> 
>     dirA
>       +--dirB
> 
> I would like a clean way to treat pyc files in dirA one way and dirB another
> without chasing down every import.  For example:
> 
>     sys.pyc_dir = {"dirA":"", dirB:"output/dir/path", ".":"some/other/path"}

That would handle the fact that many standard library modules should be
left alone (or dealt with globally, i.e., the module is compiled on
installation), but it's your own modules that you want to control.

-- 
Ian Bicking           Colorstudy Web Development
ianb at colorstudy.com   http://www.colorstudy.com
PGP: gpg --keyserver pgp.mit.edu --recv-keys 0x9B9E28B7
4869 N Talman Ave, Chicago, IL 60625 / (773) 275-7241






More information about the Python-list mailing list