Bug ensure_dir?
Published: July 22, 2018 - 1:22 PM
Good morning,
Wapt version 1.5
I tried using the `setuphelper ensure_dir` in a package, and I encountered a malfunction:
In fact, the command `ensure_dir('C:\Programmes\Ape')` did nothing. I tested it in a Python console with all possible combinations (putting "r" before 'C:\Programmes...', using `Programmes` instead of `Programmes`...), nothing worked.
So, I looked at the function's code and ran some tests directly in Python:
(of course the directory C:\Program Files does not exist)
In test 1, we see that if `d` is declared as `path.dirname`, the `isdir()` function always returns `True`, even if the path doesn't exist. (The response I get when I ask it to display `d` is a bit surprising, but later on, we see that this doesn't seem to be the cause of the problem, even though it's already problematic.)
In test 2, we see that if d is declared as a string and the path does not exist, we do indeed get False.
In test 3, we see that, on the other hand, if the path exists when d is declared as a string, we do get a True.
It seems to me, therefore, that in ensure_dir(), rather than using
You should use
Or, you can directly use the filename variable, since `d`, in this case, doesn't seem to serve much purpose, except perhaps to convert filename to a string:
Sincerely
E. Trezel
Wapt version 1.5
I tried using the `setuphelper ensure_dir` in a package, and I encountered a malfunction:
In fact, the command `ensure_dir('C:\Programmes\Ape')` did nothing. I tested it in a Python console with all possible combinations (putting "r" before 'C:\Programmes...', using `Programmes` instead of `Programmes`...), nothing worked.
So, I looked at the function's code and ran some tests directly in Python:
(of course the directory C:\Program Files does not exist)
Code: Select all
>>> ## Test 1 :
>>> d=path.dirname('C:\program rrr')
>>> d
'C:\\'
>>> path.isdir(d)
True
>>> ## Test 2 :
>>> d="C:\Program rrr"
>>> d
'C:\\Program rrr'
>>> path.isdir(d)
False
>>> ##Test 3 :
>>> d="C:\Program Files"
>>> d
'C:\\Program Files'
>>> path.isdir(d)
True
In test 2, we see that if d is declared as a string and the path does not exist, we do indeed get False.
In test 3, we see that, on the other hand, if the path exists when d is declared as a string, we do get a True.
It seems to me, therefore, that in ensure_dir(), rather than using
Code: Select all
d = os.path.dirname(filename)
Code: Select all
d = filename
Code: Select all
d = str(filename)
E. Trezel