classification
Title: option for not writing .py[co] files
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: brett.cannon, christian.heimes, doko, georg.brandl, gvanrossum, loewis, nnorwitz, thosrtanner
Priority: normal Keywords: patch

Created on 2002-08-30 11:13 by doko, last changed 2008-01-07 17:09 by georg.brandl. This issue is now closed.

Files
File name Uploaded Description Edit
readonly.diff nnorwitz, 2003-01-12 19:02 nn patch 1 - 2.3
readonly-2.2.diff nnorwitz, 2003-01-12 19:02 nn patch - for Python 2.2 only
pyman.diff nnorwitz, 2003-01-20 23:00 man page patch
kew-msg skip.montanaro, 2007-01-25 16:45
no-pyc-flag.diff georg.brandl, 2007-10-19 12:41
no-pyc-flag.diff georg.brandl, 2008-01-06 18:00
Messages (22)
msg53619 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2002-08-30 11:13
[destilled from http://bugs.debian.org/96111]

Currently python tries to write the .py[co] files even
in situations, where it will fail, like on read-only
mounted file systems.

In other situations I don't want python trying to write
the compiled files, i.e. having installed the modules
as root as part of a distribution, compiled them
correctly, there is no need to write them. Or compiling
.py files which are configuration files.

Is it reasonable to add an option to python
(--dont-write-compiled-files) to the interpreter, which
doesn't write them? This would not affect existing code
at all.
msg53620 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-09-01 23:30
Logged In: YES 
user_id=33168

Guido, do you think this is a good idea?  If so, assign back
to me and I'll work up a patch.
msg53621 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-09-03 15:39
Logged In: YES 
user_id=6380

I think it's a good idea, but please use a single upper case
letter for the option. Python doesn't support long options
and I'm not about to start doing so.
msg53622 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2003-01-12 19:47
Logged In: YES 
user_id=21627

The patch looks good, but is surely incomplete: there should
be patches to the documentation, in particular to the man page.

It might be also desirable to parallel this option with an
environment variable, and/or to expose it writable through
the sys module.

With the environment variable, people could run Python
scripts that won't create .pyc files (as #! /usr/bin/env
python does not allow for further command line options).
With the API, certain applications could declare that they
never want to write .pyc files as they expect to run in
parallel with itself, and might cause .pyc conflicts.
msg53623 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2003-01-12 21:39
Logged In: YES 
user_id=33168

You are correct about the patch being incomplete.  I still
have to do all the doc.

I hadn't thought about an env't variable or variable in sys.
 Both are certainly reasonable.  I will update the patch.
msg53624 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-05-21 05:50
Logged In: YES 
user_id=357491

PEP 304 now handles this situation.
msg53625 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2003-05-22 22:03
Logged In: YES 
user_id=33168

I think Skip now owns this because of his PEP. :-)
msg53626 - (view) Author: Skip Montanaro (skip.montanaro) * (Python committer) Date: 2003-05-22 22:20
Logged In: YES 
user_id=44345

I have a c.l.py message buried in my python mailbox which raises some
Windows-related problems.  I have yet to figure that out, but they looked
somewhat difficult on first glance.  I'll try to dredge that up and attach
it to this id.
msg53627 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-01-25 16:33
Turning in a feature request.
msg53628 - (view) Author: Skip Montanaro (skip.montanaro) * (Python committer) Date: 2007-01-25 16:45
Took me awhile (nearly four years!) to find it, but I finally found the c.l.py message I referred to regarding Windows problems.  It's attached.

Skip

File Added: kew-msg
msg56550 - (view) Author: Tom Tanner (thosrtanner) Date: 2007-10-19 10:01
Is there likely to be any action on this. We can get issues with the
creation of .pyc files due to our build setup. We can get situations
where we run builds in parallel on 2 different architectures. Our build
is set up so that anything generated by compilers end up in individual
architecture specific directories, but we cannot do this with python. We
are also using clearmae, which has its own build avoidance features,
which get thoroughly confused by the generation of these files)

End result is one of
1) We get corrupt .pyc files
2) The build breaks
3) We rebuild things we don't need to.

We'd be very grateful for a way of suppressing the generation of .pyc
files completely.
msg56552 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-10-19 12:41
Since the PEP is now withdrawn, I updated Neal's patch to the trunk and
added the env variable as well as the sys module value, including
documentation.
msg59334 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-05 21:13
Should the read only option be considered for 2.6?
msg59335 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-05 22:06
I'm okay with this feature, and the patch looks fine, except I don't
like the names used.  It's not really about "read-only-ness" of
bytecode, it's about whether we write certain files.  I'd suggest naming
the envvar PYTHONDONTWRITEBYTECODE, the C flag variable
Py_DontWriteByteCodeFlag, and the sys variable sys.dont_write_byte_code.
 With those changes I'm find with Georg checkin it in.
msg59341 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-01-05 23:50
For some reason I don't love the use of "dont", with the missing 
apostrophe.  Just looks ugly to me.  But I don't know if "donot" is that 
much better.  And I don't think "PYTHONSKIPWRITINGBYTECODE" is much 
better.

In other words, I wish there was a better option, but I don't think any 
of my suggestions are really better.
msg59342 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-05 23:53
"dont" is a pretty common contraction (see e.g. telnet.py).
msg59395 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-01-06 16:20
Does the flag name -R still make sense with the new env var name?
msg59397 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2008-01-06 16:31
What do you think about PYTHONOMITPYC, --omit-pyc and sys.omit_pyc_creation?
msg59400 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-01-06 18:00
Attaching new diff, with -B flag name, PYTHONDONTWRITEBYTECODE, and
sys.dont_write_bytecode.
msg59420 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-06 23:44
Looks good, please commit!

(Christian: the problem with using PYC in the envar name is that it is
ambiguous about what happens to PYO files...)
msg59421 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-01-06 23:55
PS the patch still has a problem:

Python/pythonrun.c:177: error: ‘Py_ReadOnlyBytecodeFlag’ undeclared
(first use in this function)
msg59466 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-01-07 17:09
Committed r59824.
History
Date User Action Args
2008-01-07 17:09:46georg.brandlsetstatus: open -> closed
messages: + msg59466
2008-01-06 23:55:00gvanrossumsetmessages: + msg59421
2008-01-06 23:44:09gvanrossumsetresolution: accepted
messages: + msg59420
2008-01-06 18:00:46georg.brandlsetfiles: + no-pyc-flag.diff
messages: + msg59400
2008-01-06 16:39:22skip.montanarosetnosy: - skip.montanaro
2008-01-06 16:31:21christian.heimessetmessages: + msg59397
2008-01-06 16:20:25georg.brandlsetmessages: + msg59395
2008-01-05 23:53:29gvanrossumsetmessages: + msg59342
2008-01-05 23:50:24brett.cannonsetmessages: + msg59341
2008-01-05 22:06:52gvanrossumsetkeywords: + patch
assignee: skip.montanaro -> georg.brandl
messages: + msg59335
2008-01-05 21:13:56christian.heimessetnosy: + christian.heimes
messages: + msg59334
versions: + Python 2.6
2007-10-19 12:41:22georg.brandlsetpriority: low -> normal
files: + no-pyc-flag.diff
messages: + msg56552
2007-10-19 10:01:02thosrtannersetnosy: + thosrtanner
messages: + msg56550
2002-08-30 11:13:03dokocreate