Georg Brandl wrote: > +1. Having a single (visible) __pyr__ directory is much less clutter than > multiple .pyc files anyway. Also, don't forget Windows users, for whom > the dot convention doesn't mean anything.
I must admit I quite like the __pyr__ directory approach as well. Since the interpreter knows the suffix it is looking for, names shouldn't conflict. Using a single directory allows the name to be less cryptic, too (e.g. __pycache__). That still leaves the question of what to do with __file__ (for which even the solution in the PEP isn't particularly clean). Perhaps the thing to do there is to have __file__ always point to the source file and introduce a __file_cached__ that points to the bytecompiled file on disk (set to None if it doesn't exist, as may be the case for __main__ or due to writing of bytecode files being disabled). With that approach, a structure given just a run under 2.7 and one under 2.7 with -O might look like: package/ __init__.py foo.py __pycache__/ __init__.cpython-27.pyc __init__.cpython-27.pyo foo.cpython-27.pyc foo.cpython-27.pyo subpackage/ __init__.py bar.py __pycache__/ __init__.cpython-27.pyc __init__.cpython-27.pyo bar.cpython-27.pyc bar.cpython-27.pyo __file__ would always point to the source files __file_cached__ would always point to the relevant compiled file (either pre-existing or newly created) To use the final step of importing package.foo as an example (ignoring the extra backwards compatibility steps for the existing scheme): 1. Check package dir listing for __pyr__ 2. It it exists, check it for a foo.<cookie>.<ext> (where the interpreter will always know exactly which cookie and extension it wants) 3. As an CPython implementation details, use the cookie inside the file to double-check correctness 4. If all good, run with that cached file 5. Otherwise, check package dir for foo.py 6. If the source file exists, create the cached bytecode file inside the __pyr__ (if this fails, just run from RAM with __file_cached__ = None) 7. Run with the newly compiled source file 8. Otherwise report ImportError. This doesn't seem to have any significant disadvantages relative to the subdirectory-per-source-file approach (and the major advantage of creating just a single subdirectory). Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia --------------------------------------------------------------- _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com