This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Arfrever
Recipients Arfrever
Date 2010-05-08.19:36:30
SpamBayes Score 2.2954971e-12
Marked as misclassified No
Message-id <1273347393.41.0.872470014027.issue8664@psf.upfronthosting.co.za>
In-reply-to
Content
Currently when cfile argument of py_compile.compile() is None, then path to target file is automatically calculated and parent directory of target file is created. If the same path of target file is explicitly passed as cfile argument of py_compile.compile(), then parent directory of target file is not created automatically.
This inconsistency in behavior can be easily fixed. Fixing it also allows to simplify compileall.compile_file() function, which calls py_compile.compile() and currently needs to earlier try to create parent directory of target file.

The following example shows inconsistent behavior:

$ mkdir test
$ touch test/test.py
$ tree test
test
└── test.py

0 directories, 1 file
$ python3.2 -c 'import py_compile; py_compile.compile("test/test.py")'
$ tree test
test
├── __pycache__
│   └── test.cpython-32.pyc
└── test.py

1 directory, 2 files
$ rm -fr test/__pycache__
$ python3.2 -c 'import py_compile; py_compile.compile("test/test.py", "test/__pycache__/test.cpython-32.pyc")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.2/py_compile.py", line 131, in compile
    with open(cfile, 'wb') as fc:
IOError: [Errno 2] No such file or directory: 'test/__pycache__/test.cpython-32.pyc'
$ mkdir test/__pycache__
$ python3.2 -c 'import py_compile; py_compile.compile("test/test.py", "test/__pycache__/test.cpython-32.pyc")'
$ tree test
test
├── __pycache__
│   └── test.cpython-32.pyc
└── test.py

1 directory, 2 files
History
Date User Action Args
2010-05-08 19:36:33Arfreversetrecipients: + Arfrever
2010-05-08 19:36:33Arfreversetmessageid: <1273347393.41.0.872470014027.issue8664@psf.upfronthosting.co.za>
2010-05-08 19:36:31Arfreverlinkissue8664 messages
2010-05-08 19:36:30Arfrevercreate