Re: Difference between os.path.isdir and Path.is_dir

2019-12-14 Thread Kirill Balunov
Yeah it is True, for the last two weeks or so I can access bugs.python.org
in normal way. But I totally agree with the site that the best description
of this situation is "Yet".

with kind regards,
-gdg

сб, 14 дек. 2019 г. в 19:46, Terry Reedy :

> On 7/26/2019 3:12 AM, Kirill Balunov wrote:
> > чт, 25 июл. 2019 г. в 20:28, eryk sun :
> >
> >> On 7/25/19, Kirill Balunov  wrote:
> >>>
> >> import os
> >> from pathlib import Path
> >> dummy = " "   # or "" or " "
> >> os.path.isdir(dummy)
> >>> False
> >> Path(dummy).is_dir()
> >>> True
> >>
> >> I can't reproduce the above result in either Linux or Windows. The
> >> results should only be different for an empty path string, since
> >> Path('') is the same as Path('.'). The results should be the same for
> >> Path(" "), depending on whether a directory named " " exists (normally
> >> not allowed in Windows, but Linux allows it).
> >>
> >>
> > I need to confirm that it was my fault and for non-empty strings (`" "`
> or `"
> > "`), both `os.path.isdir(...)` and `Path(...).is_dir()` produce the same
> > results.So sorry for the noise.
> >
> > Concerning the case with empty path string, I will open a ticket at the
> bug
> > tracker (but for some reason it is blocked in my country :(
> > https://isitblockedinrussia.com/?host=https%3A%2F%2Fbugs.python.org%2F).
>
> For me, this now returns 'No, https://bugs.python.org is probably not
> blocked in Russia. Yet.'.
>
> > Obviously
> > these are not equivalent forms, so either this should be noted in the
> > documentation or corrected in the code.
>
> --
> Terry Jan Reedy
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-12-14 Thread Terry Reedy

On 7/26/2019 3:12 AM, Kirill Balunov wrote:

чт, 25 июл. 2019 г. в 20:28, eryk sun :


On 7/25/19, Kirill Balunov  wrote:



import os
from pathlib import Path
dummy = " "   # or "" or " "
os.path.isdir(dummy)

False

Path(dummy).is_dir()

True


I can't reproduce the above result in either Linux or Windows. The
results should only be different for an empty path string, since
Path('') is the same as Path('.'). The results should be the same for
Path(" "), depending on whether a directory named " " exists (normally
not allowed in Windows, but Linux allows it).



I need to confirm that it was my fault and for non-empty strings (`" "` or `"
"`), both `os.path.isdir(...)` and `Path(...).is_dir()` produce the same
results.So sorry for the noise.

Concerning the case with empty path string, I will open a ticket at the bug
tracker (but for some reason it is blocked in my country :(
https://isitblockedinrussia.com/?host=https%3A%2F%2Fbugs.python.org%2F).


For me, this now returns 'No, https://bugs.python.org is probably not 
blocked in Russia. Yet.'.



Obviously
these are not equivalent forms, so either this should be noted in the
documentation or corrected in the code.


--
Terry Jan Reedy


--
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-26 Thread Kirill Balunov
чт, 25 июл. 2019 г. в 20:28, eryk sun :

> On 7/25/19, Kirill Balunov  wrote:
> >
>  import os
>  from pathlib import Path
>  dummy = " "   # or "" or " "
>  os.path.isdir(dummy)
> > False
>  Path(dummy).is_dir()
> > True
>
> I can't reproduce the above result in either Linux or Windows. The
> results should only be different for an empty path string, since
> Path('') is the same as Path('.'). The results should be the same for
> Path(" "), depending on whether a directory named " " exists (normally
> not allowed in Windows, but Linux allows it).
>
>
I need to confirm that it was my fault and for non-empty strings (`" "` or `"
"`), both `os.path.isdir(...)` and `Path(...).is_dir()` produce the same
results.So sorry for the noise.

Concerning the case with empty path string, I will open a ticket at the bug
tracker (but for some reason it is blocked in my country :(
https://isitblockedinrussia.com/?host=https%3A%2F%2Fbugs.python.org%2F).
Obviously
these are not equivalent forms, so either this should be noted in the
documentation or corrected in the code.

with kind regards,
-gdg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Cameron Simpson

On 26Jul2019 03:43, Chris Angelico  wrote:

On Fri, Jul 26, 2019 at 3:28 AM eryk sun  wrote:

On 7/25/19, Kirill Balunov  wrote:
 import os
 from pathlib import Path
 dummy = " "   # or "" or " "
 os.path.isdir(dummy)
> False
 Path(dummy).is_dir()
> True

I can't reproduce the above result in either Linux or Windows. The
results should only be different for an empty path string, since
Path('') is the same as Path('.'). The results should be the same for
Path(" "), depending on whether a directory named " " exists (normally
not allowed in Windows, but Linux allows it).


Try an empty string, no spaces. To pathlib.Path, that means the
current directory. To os.path.abspath, that means the current
directory. To os.stat, it doesn't exist.


And for some context, on older UNIXen "" did stat successfully.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Cameron Simpson

On 25Jul2019 13:40, eryk sun  wrote:

Windows trims trailing spaces and dots from the final component of a
path, unless we use a non-normalized \\?\ path.


Hoo!

Well, that explains some extremely weird NAS behaviour I encountered the 
other month with some paths ending in spaces. (My machine and I think 
also the NAS were UNIX/Linux at each end, but speaking over SMB.) 
Guessing that the NAS was doing only a half hearted implementation of 
the trailing spaces semantics.


Interesting:-)

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Chris Angelico
On Fri, Jul 26, 2019 at 6:13 AM Kirill Balunov  wrote:
>
>
>
> чт, 25 июл. 2019 г. в 22:58, Chris Angelico :
>>
>> On Fri, Jul 26, 2019 at 5:52 AM Kirill Balunov  
>> wrote:
>> [...]
>> > No, it's not just because of curiosity. I will try to tell the background, 
>> > and maybe I went the wrong way initially. There is a very cool project 
>> > https://github.com/3b1b/manim, it allows you to visualize math (I don’t 
>> > know how to describe it better you can see some examples here 
>> > https://www.3blue1brown.com) and it works lovely on Linux. For some 
>> > reason, I need to use it on Windows. Problems began to arise when I tried 
>> > my scripts were some latex was included in the animation.
>> >
>>
>> Ah, I love 3b1b! Great videos. I toyed with manim once (wanting to
>> create new Fourier visualizations), but the open source parts weren't
>> enough for what I was trying to do. Very cool though.
>>
>
> If you can tell, what parts did you miss?

Basically everything to do with Fourier transforms. I wanted to hand
the program a new SVG file and see it animate it, but (a) I didn't
understand the code very well, and (b) a lot of the code isn't part of
the freely licensed part (it's all in the same repo, but some is
MIT-licensed and isn't), which means it's not documented for public
use and isn't designed to be broadly usable.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Kirill Balunov
чт, 25 июл. 2019 г. в 22:58, Chris Angelico :

> On Fri, Jul 26, 2019 at 5:52 AM Kirill Balunov 
> wrote:
> [...]
> > No, it's not just because of curiosity. I will try to tell the
> background, and maybe I went the wrong way initially. There is a very cool
> project https://github.com/3b1b/manim, it allows you to visualize math (I
> don’t know how to describe it better you can see some examples here
> https://www.3blue1brown.com) and it works lovely on Linux. For some
> reason, I need to use it on Windows. Problems began to arise when I tried
> my scripts were some latex was included in the animation.
> >
>
> Ah, I love 3b1b! Great videos. I toyed with manim once (wanting to
> create new Fourier visualizations), but the open source parts weren't
> enough for what I was trying to do. Very cool though.
>
>
If you can tell, what parts did you miss?

with kind regards,
-gdg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Chris Angelico
On Fri, Jul 26, 2019 at 5:52 AM Kirill Balunov  wrote:
>
>
>
> чт, 25 июл. 2019 г. в 19:16, Chris Angelico :
>>
>> On Fri, Jul 26, 2019 at 1:30 AM Kirill Balunov  
>> wrote:
>> >
>> >  Hi all! It is expected that:
>> > ```
>> > >>> import os
>> > >>> from pathlib import Path
>> > >>> dummy = " "   # or "" or " "
>> > >>> os.path.isdir(dummy)
>> > False
>> > >>> Path(dummy).is_dir()
>> > True
>> > ```
>> >
>> > or was it overlooked?
>> >
>> []
>> I'm not sure if this is considered an important enough bug to actually fix, 
>> or
>> if it's merely a curiosity that occurs when you trigger undocumented
>> behaviour.
>>
>
> No, it's not just because of curiosity. I will try to tell the background, 
> and maybe I went the wrong way initially. There is a very cool project 
> https://github.com/3b1b/manim, it allows you to visualize math (I don’t know 
> how to describe it better you can see some examples here 
> https://www.3blue1brown.com) and it works lovely on Linux. For some reason, I 
> need to use it on Windows. Problems began to arise when I tried my scripts 
> were some latex was included in the animation.
>

Ah, I love 3b1b! Great videos. I toyed with manim once (wanting to
create new Fourier visualizations), but the open source parts weren't
enough for what I was trying to do. Very cool though.

> So I installed TexLive, but it didn't produce any output :) In `manim` it is 
> invoked through a system call 
> https://github.com/3b1b/manim/blob/master/manimlib/utils/tex_file_writing.py#L40
>  like this:
>
> $ latex -interaction=batchmode -halt-on-error -output-directory=... input.tex 
> > /dev/null
>
> For some reason TexLive does not understand Windows relative paths of this 
> form -output-directory =".\Output" and  ".\Input\file.tex", but it 
> understands the absolute paths in Windows form like 
> "C:\path\to\the\input\file.tex". I read that Windows allows also to provide 
> paths in the usual form "./Input/file.tex" (maybe I'm wrong with my 
> understanding what does it mean on Windows),
>

It means the same thing as your other relative path. The two types of
slash should basically be interchangeable.

> I've tested and this worked. But the problem is that Python always inserts 
> '\' as path separators on Windows and there is no control to set it up. I 
> decided to rewrite all this stuff with the help of `pathlib` module and to 
> use `Path`  and `.as_posix` method everywhere. Paths are set here 
> https://github.com/3b1b/manim/blob/c7e6d9d4742ec47098bd86a9bbb4212cc637206b/manimlib/constants.py#L10
>  and the author uses  `MEDIA_DIR = ""` as a default unset value, and then 
> checks  `if not os.path.isdir(MEDIA_DIR)`. The documentation states that  
> `os.path.isdir(...)` is equivalent to `Path(...).is_dir()` but it is not 
> true. So I wrote here.
>

Gotcha. It'd probably be safe to change it to "." instead; that way,
it's an actual valid directory name and can be combined normally with
other components.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Kirill Balunov
чт, 25 июл. 2019 г. в 19:16, Chris Angelico :

> On Fri, Jul 26, 2019 at 1:30 AM Kirill Balunov 
> wrote:
> >
> >  Hi all! It is expected that:
> > ```
> > >>> import os
> > >>> from pathlib import Path
> > >>> dummy = " "   # or "" or " "
> > >>> os.path.isdir(dummy)
> > False
> > >>> Path(dummy).is_dir()
> > True
> > ```
> >
> > or was it overlooked?
> >
> []
> I'm not sure if this is considered an important enough bug to actually
> fix, or
> if it's merely a curiosity that occurs when you trigger undocumented
> behaviour.
>
>
No, it's not just because of curiosity. I will try to tell the background,
and maybe I went the wrong way initially. There is a very cool project
https://github.com/3b1b/manim, it allows you to visualize math (I don’t
know how to describe it better you can see some examples here
https://www.3blue1brown.com) and it works lovely on Linux. For some reason,
I need to use it on Windows. Problems began to arise when I tried my
scripts were some latex was included in the animation.
So I installed TexLive, but it didn't produce any output :) In `manim` it
is invoked through a system call
https://github.com/3b1b/manim/blob/master/manimlib/utils/tex_file_writing.py#L40
like this:

$ latex -interaction=batchmode -halt-on-error -output-directory=...
input.tex > /dev/null

For some reason TexLive does not understand Windows relative paths of this
form -output-directory =".\Output" and  ".\Input\file.tex", but it
understands the absolute paths in Windows form like
"C:\path\to\the\input\file.tex".
I read that Windows allows also to provide paths in the usual form
"./Input/file.tex"
(maybe I'm wrong with my understanding what does it mean on Windows), I've
tested and this worked. But the problem is that Python always inserts '\'
as path separators on Windows and there is no control to set it up. I
decided to rewrite all this stuff with the help of `pathlib` module and to
use `Path`  and `.as_posix` method everywhere. Paths are set here
https://github.com/3b1b/manim/blob/c7e6d9d4742ec47098bd86a9bbb4212cc637206b/manimlib/constants.py#L10
and the author uses  `MEDIA_DIR = ""` as a default unset value, and then
checks  `if not os.path.isdir(MEDIA_DIR)`. The documentation states that
`os.path.isdir(...)` is equivalent to `Path(...).is_dir()` but it is not
true. So I wrote here.

with kind regards,
-gdg
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Kirill Balunov
чт, 25 июл. 2019 г. в 20:28, eryk sun :

> On 7/25/19, Kirill Balunov  wrote:
> >
>  import os
>  from pathlib import Path
>  dummy = " "   # or "" or " "
>  os.path.isdir(dummy)
> > False
>  Path(dummy).is_dir()
> > True
>
> I can't reproduce the above result in either Linux or Windows. The
> results should only be different for an empty path string, since
> Path('') is the same as Path('.'). The results should be the same for
> Path(" "), depending on whether a directory named " " exists (normally
> not allowed in Windows, but Linux allows it).
>
>
Heh, something fishy is going on. I also can't reproduce that behavior
(with " " and "   ") at home comp on Windows 10 Python 3.7.4. Tomorrow I'll
check again at work and let you know. I apologize in advance. The main
problem arose огые with an empty line, but then I checked with " " and
apparently made a mistake somewhere.

with kind regards,
-gdg
-- 
https://mail.python.org/mailman/listinfo/python-list


Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Maksim Fomin via Python-list

‐‐‐ Original Message ‐‐‐
On Thursday, July 25, 2019 3:27 PM, Kirill Balunov  
wrote:

> Hi all! It is expected that:
>
> >>> import os
> >>> from pathlib import Path
> >>> dummy = " "   # or "" or " "
> >>> os.path.isdir(dummy)
>
> False
> >>> Path(dummy).is_dir()
>
> True
>
>
> or was it overlooked?
>
> with kind regards,
> -gdg
>
> -
>
> https://mail.python.org/mailman/listinfo/python-list

I also cannot reproduce it on linux (python 3.7.3). Which version do you use?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread eryk sun
On 7/25/19, Chris Angelico  wrote:
> On Fri, Jul 26, 2019 at 3:54 AM eryk sun  wrote:
>
>> That's what I said. But the OP shows os.path.isdir(" ") == False and
>> Path(" ").is_dir() == True, which is what I cannot reproduce and
>> really should not be able to reproduce, unless there's a bug
>> somewhere.
>
> Yeah but WHY is it different for an empty string?

Path.__fspath__ returns str(self), and Path.__str__ returns "." if the
path is empty, i.e. there's no drive, root, or parts.

I assume this is related to os.path.normpath("") == ".", which is
related to os.path.normpath("spam/..") == ".". However, an empty path
string isn't consistently handled as the current directory throughout
the os and os.path modules.

> I can well imagine that some OS/FS combinations will happily strip
> spaces, thus devolving the " " case to the "" one.

Windows trims trailing spaces and dots from the final component of a
path, unless we use a non-normalized \\?\ path.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Chris Angelico
On Fri, Jul 26, 2019 at 3:54 AM eryk sun  wrote:
>
> On 7/25/19, Chris Angelico  wrote:
> > On Fri, Jul 26, 2019 at 3:28 AM eryk sun  wrote:
> >>
> >> On 7/25/19, Kirill Balunov  wrote:
> >> >
> >>  import os
> >>  from pathlib import Path
> >>  dummy = " "   # or "" or " "
> >>  os.path.isdir(dummy)
> >> > False
> >>  Path(dummy).is_dir()
> >> > True
> >>
> >> I can't reproduce the above result in either Linux or Windows. The
> >> results should only be different for an empty path string, since
> >> Path('') is the same as Path('.'). The results should be the same for
> >> Path(" "), depending on whether a directory named " " exists (normally
> >> not allowed in Windows, but Linux allows it).
> >
> > Try an empty string, no spaces. To pathlib.Path, that means the
> > current directory. To os.path.abspath, that means the current
> > directory. To os.stat, it doesn't exist.
>
> That's what I said. But the OP shows os.path.isdir(" ") == False and
> Path(" ").is_dir() == True, which is what I cannot reproduce and
> really should not be able to reproduce, unless there's a bug
> somewhere.

Yeah but WHY is it different for an empty string?

I can well imagine that some OS/FS combinations will happily strip
spaces, thus devolving the " " case to the "" one.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread eryk sun
On 7/25/19, Chris Angelico  wrote:
> On Fri, Jul 26, 2019 at 3:28 AM eryk sun  wrote:
>>
>> On 7/25/19, Kirill Balunov  wrote:
>> >
>>  import os
>>  from pathlib import Path
>>  dummy = " "   # or "" or " "
>>  os.path.isdir(dummy)
>> > False
>>  Path(dummy).is_dir()
>> > True
>>
>> I can't reproduce the above result in either Linux or Windows. The
>> results should only be different for an empty path string, since
>> Path('') is the same as Path('.'). The results should be the same for
>> Path(" "), depending on whether a directory named " " exists (normally
>> not allowed in Windows, but Linux allows it).
>
> Try an empty string, no spaces. To pathlib.Path, that means the
> current directory. To os.path.abspath, that means the current
> directory. To os.stat, it doesn't exist.

That's what I said. But the OP shows os.path.isdir(" ") == False and
Path(" ").is_dir() == True, which is what I cannot reproduce and
really should not be able to reproduce, unless there's a bug
somewhere.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Chris Angelico
On Fri, Jul 26, 2019 at 3:28 AM eryk sun  wrote:
>
> On 7/25/19, Kirill Balunov  wrote:
> >
>  import os
>  from pathlib import Path
>  dummy = " "   # or "" or " "
>  os.path.isdir(dummy)
> > False
>  Path(dummy).is_dir()
> > True
>
> I can't reproduce the above result in either Linux or Windows. The
> results should only be different for an empty path string, since
> Path('') is the same as Path('.'). The results should be the same for
> Path(" "), depending on whether a directory named " " exists (normally
> not allowed in Windows, but Linux allows it).

Try an empty string, no spaces. To pathlib.Path, that means the
current directory. To os.path.abspath, that means the current
directory. To os.stat, it doesn't exist.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread eryk sun
On 7/25/19, Kirill Balunov  wrote:
>
 import os
 from pathlib import Path
 dummy = " "   # or "" or " "
 os.path.isdir(dummy)
> False
 Path(dummy).is_dir()
> True

I can't reproduce the above result in either Linux or Windows. The
results should only be different for an empty path string, since
Path('') is the same as Path('.'). The results should be the same for
Path(" "), depending on whether a directory named " " exists (normally
not allowed in Windows, but Linux allows it).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Chris Angelico
On Fri, Jul 26, 2019 at 1:30 AM Kirill Balunov  wrote:
>
>  Hi all! It is expected that:
> ```
> >>> import os
> >>> from pathlib import Path
> >>> dummy = " "   # or "" or " "
> >>> os.path.isdir(dummy)
> False
> >>> Path(dummy).is_dir()
> True
> ```
>
> or was it overlooked?
>

Was not aware of that. A bit of digging shows that asking to convert
an empty path to an absolute one will give you the name of the current
directory (whether you use os.path or pathlib.Path), but os.path.isdir
starts by seeing if it can os.stat the given path, and if that fails,
it returns False (because if something doesn't exist, it can't be a
directory).

As a workaround, you could simply call
os.path.isdir(os.path.abspath(x)) to get consistent results. I'm not
sure if this is considered an important enough bug to actually fix, or
if it's merely a curiosity that occurs when you trigger undocumented
behaviour.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Difference between os.path.isdir and Path.is_dir

2019-07-25 Thread Kirill Balunov
 Hi all! It is expected that:
```
>>> import os
>>> from pathlib import Path
>>> dummy = " "   # or "" or " "
>>> os.path.isdir(dummy)
False
>>> Path(dummy).is_dir()
True
```

or was it overlooked?

with kind regards,
-gdg
-- 
https://mail.python.org/mailman/listinfo/python-list