[Python-Dev] PEP 3147, __pycache__ directories and umask

Barry Warsaw barry at python.org
Mon Mar 22 14:56:04 CET 2010


I have a pretty good start on PEP 3147 implementation [1], but I've
encountered a situation that I'd like to get some feedback on.  Here's the
test case illustrating the problem.  From test_import.py:

    def test_writable_directory(self):
        # The umask is not conducive to creating a writable __pycache__
        # directory.
        with umask(0o222):
            __import__(TESTFN)
        self.assertTrue(os.path.exists('__pycache__'))
        self.assertTrue(os.path.exists(os.path.join(
            '__pycache__', '{}.{}.pyc'.format(TESTFN, self.tag))))

The __pycache__ directory does not exist before the import, and the import
machinery creates the directory, but the umask leaves the directory unwritable
by anybody.  So of course when the import machinery goes to write the .pyc
file inside __pycache__, it fails.  This does not cause an ImportError though,
just like if today the package directory were unwritable.

This might be different than today's situation though because once the
unwritable __pycache__ directory is created, nothing is going to change that
without explicit user interaction, and that might be difficult after the
fact.

I'm not sure what the right answer is.  Some possible choices:

* Tough luck
* Force the umask so that the directory is writable, but then the question is,
  by whom?  ugo+w or something less?
* Copy the permissions from the parent directory and ignore umask
* Raise an exception or refuse to create __pycache__ if it's not writable
  (again, by whom?)

Or maybe you have a better idea?  What's the equivalent situation on Windows
and how would things work there?

-Barry

[1] https://edge.launchpad.net/~barry/python/pep3147

P.S. I'm down to only 8 unit test failures.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20100322/80ada87a/attachment.pgp>


More information about the Python-Dev mailing list