New submission from Arfrever Frehtes Taifersar Arahesis 
<arfrever....@gmail.com>:

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

----------
components: Library (Lib)
messages: 105328
nosy: Arfrever
priority: normal
severity: normal
status: open
title: py_compile.compile() should consistently create parent directory of 
target file
type: behavior
versions: Python 3.2

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8664>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to