pyc files located elsewhere?

J

Jerry Sievers

Greetings.

On Python 2.3.3, is there any way to have the .pyc files created
elsewhere than in the same dir as the source files?

I have an application that consists of about 30 source files including
a few packages.

I would like it if my .pyc files could be in a subdir of the app root
if possible. I would have to make sure that the subdir structure
underneath matched the structure of the app itself.

I would also consider having each package directory have its own PYC
directory and the compiled files could go in there even.

So, can I feed a prefix to the system that checks for and creates .pyc
files somehow? My review of the Pydocs for related compilation issues
didn't seem to turn up an answer.

Thanks.
 
J

Josiah Carlson

I would like it if my .pyc files could be in a subdir of the app root
if possible. I would have to make sure that the subdir structure
underneath matched the structure of the app itself.

I would also consider having each package directory have its own PYC
directory and the compiled files could go in there even.

So, can I feed a prefix to the system that checks for and creates .pyc
files somehow? My review of the Pydocs for related compilation issues
didn't seem to turn up an answer.

I don't know if it is possible to automatically write to a different
path, but I /think/ one can /turn off/ writing .pyc files, but it would
necessarily make running the script slower (you don't get cached .pyc
files, so every import requires a py->ptc compilation).

- Josiah
 
P

Peter L Hansen

Josiah said:
I don't know if it is possible to automatically write to a different
path, but I /think/ one can /turn off/ writing .pyc files, but it would
necessarily make running the script slower (you don't get cached .pyc
files, so every import requires a py->ptc compilation).

Just to clarify (and I don't know turning that feature off is really
possible, so maybe it's a useless point), but not *every* import will
require the compilation. The first import of any given module will
require the compilation, each time you run the application. If a
module is imported fifty times, all but the first just retrieve
the module from sys.modules, same as normal.

(Is what you describe really possible? I've never heard of it.)

-Peter
 
D

Diez B. Roggisch

(Is what you describe really possible? I've never heard of it.)

It seems that its at least not doable using commandline args. But I have to
admit that I love to see that feature - so far, pyc didn't by me anything
except trouble to clear my src-dirs when using a version control system to
prevent them beeing checked in. I'm very well aware of .cvsignore and the
like - but I'd prefer to turn off the compilation.
 
J

Josiah Carlson

Josiah said:
Just to clarify (and I don't know turning that feature off is really
possible, so maybe it's a useless point), but not *every* import will
require the compilation. The first import of any given module will
require the compilation, each time you run the application. If a
module is imported fifty times, all but the first just retrieve
the module from sys.modules, same as normal.

Right, but if you have 50 modules that are imported (50 unique module
files), then you still have to compile those 50 every time. The speed
hit really depends on the size of the application, and how often
restarts occur.

(Is what you describe really possible? I've never heard of it.)

I know that importing from a non-writable location disables writing of
pyc files (zip imports, etc.), and I am fairly certain it can be done
with an import hook, though never having need for it, I've never tried.

- Josiah
 
S

Skip Montanaro

Josiah> I know that importing from a non-writable location disables
Josiah> writing of pyc files (zip imports, etc.), and I am fairly
Josiah> certain it can be done with an import hook, though never having
Josiah> need for it, I've never tried.

Please have a look at PEP 304. Feedback welcome.

Skip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top