Patchwork [1,of,8] py3: don't use os.getcwdb() on Windows to avoid DeprecationWarnings

login
register
mail settings
Submitter Matt Harbison
Date Sept. 22, 2018, 3:28 p.m.
Message ID <758cf8cdf99494217423.1537630117@Envy>
Download mbox | patch
Permalink /patch/34915/
State Accepted
Headers show

Comments

Matt Harbison - Sept. 22, 2018, 3:28 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1537573703 14400
#      Fri Sep 21 19:48:23 2018 -0400
# Node ID 758cf8cdf994942174238c28c8f06ece63dae2b5
# Parent  7e99b02768ef396b5c4b7a9126c329f49af3e2bf
py3: don't use os.getcwdb() on Windows to avoid DeprecationWarnings

See also ac32685011a3.
Yuya Nishihara - Sept. 23, 2018, 6:37 a.m.
On Sat, 22 Sep 2018 11:28:37 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1537573703 14400
> #      Fri Sep 21 19:48:23 2018 -0400
> # Node ID 758cf8cdf994942174238c28c8f06ece63dae2b5
> # Parent  7e99b02768ef396b5c4b7a9126c329f49af3e2bf
> py3: don't use os.getcwdb() on Windows to avoid DeprecationWarnings
> 
> See also ac32685011a3.
> 
> diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
> --- a/mercurial/pycompat.py
> +++ b/mercurial/pycompat.py
> @@ -100,6 +100,13 @@ if ispy3:
>      # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which
>      # returns bytes.
>      getcwd = os.getcwdb
> +
> +    # Python 3 on Windows issues a DeprecationWarning about using the bytes API
> +    # when os.getcwdb() is called.
> +    if osname == 'nt':
> +        from . import encoding   # encoding imports pycompat
> +        getcwd = lambda: encoding.strtolocal(os.getcwd())

Can you move this to encoding.getcwd() just like encoding.environ?
Matt Harbison - Sept. 24, 2018, 2:54 a.m.
On Sun, 23 Sep 2018 02:37:37 -0400, Yuya Nishihara <yuya@tcha.org> wrote:

> On Sat, 22 Sep 2018 11:28:37 -0400, Matt Harbison wrote:
>> # HG changeset patch
>> # User Matt Harbison <matt_harbison@yahoo.com>
>> # Date 1537573703 14400
>> #      Fri Sep 21 19:48:23 2018 -0400
>> # Node ID 758cf8cdf994942174238c28c8f06ece63dae2b5
>> # Parent  7e99b02768ef396b5c4b7a9126c329f49af3e2bf
>> py3: don't use os.getcwdb() on Windows to avoid DeprecationWarnings
>>
>> See also ac32685011a3.
>>
>> diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
>> --- a/mercurial/pycompat.py
>> +++ b/mercurial/pycompat.py
>> @@ -100,6 +100,13 @@ if ispy3:
>>      # os.getcwd() on Python 3 returns string, but it has os.getcwdb()  
>> which
>>      # returns bytes.
>>      getcwd = os.getcwdb
>> +
>> +    # Python 3 on Windows issues a DeprecationWarning about using the  
>> bytes API
>> +    # when os.getcwdb() is called.
>> +    if osname == 'nt':
>> +        from . import encoding   # encoding imports pycompat
>> +        getcwd = lambda: encoding.strtolocal(os.getcwd())
>
> Can you move this to encoding.getcwd() just like encoding.environ?

How was the rule banning os.getcwd() avoided when it was in pycompat?  I  
don't see anything obvious, and it's also complaining about os.getcwd too,  
because the regex isn't anchored.
Yuya Nishihara - Sept. 24, 2018, 5:33 a.m.
On Sun, 23 Sep 2018 22:54:27 -0400, Matt Harbison wrote:
> On Sun, 23 Sep 2018 02:37:37 -0400, Yuya Nishihara <yuya@tcha.org> wrote:
> 
> > On Sat, 22 Sep 2018 11:28:37 -0400, Matt Harbison wrote:
> >> # HG changeset patch
> >> # User Matt Harbison <matt_harbison@yahoo.com>
> >> # Date 1537573703 14400
> >> #      Fri Sep 21 19:48:23 2018 -0400
> >> # Node ID 758cf8cdf994942174238c28c8f06ece63dae2b5
> >> # Parent  7e99b02768ef396b5c4b7a9126c329f49af3e2bf
> >> py3: don't use os.getcwdb() on Windows to avoid DeprecationWarnings
> >>
> >> See also ac32685011a3.
> >>
> >> diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
> >> --- a/mercurial/pycompat.py
> >> +++ b/mercurial/pycompat.py
> >> @@ -100,6 +100,13 @@ if ispy3:
> >>      # os.getcwd() on Python 3 returns string, but it has os.getcwdb()  
> >> which
> >>      # returns bytes.
> >>      getcwd = os.getcwdb
> >> +
> >> +    # Python 3 on Windows issues a DeprecationWarning about using the  
> >> bytes API
> >> +    # when os.getcwdb() is called.
> >> +    if osname == 'nt':
> >> +        from . import encoding   # encoding imports pycompat
> >> +        getcwd = lambda: encoding.strtolocal(os.getcwd())
> >
> > Can you move this to encoding.getcwd() just like encoding.environ?
> 
> How was the rule banning os.getcwd() avoided when it was in pycompat?  I  
> don't see anything obvious, and it's also complaining about os.getcwd too,  
> because the regex isn't anchored.

Maybe add '#.*re-exports' to the exclude pattern? See os.environ.

Patch

diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -100,6 +100,13 @@  if ispy3:
     # os.getcwd() on Python 3 returns string, but it has os.getcwdb() which
     # returns bytes.
     getcwd = os.getcwdb
+
+    # Python 3 on Windows issues a DeprecationWarning about using the bytes API
+    # when os.getcwdb() is called.
+    if osname == 'nt':
+        from . import encoding   # encoding imports pycompat
+        getcwd = lambda: encoding.strtolocal(os.getcwd())
+
     sysplatform = sys.platform.encode('ascii')
     sysexecutable = sys.executable
     if sysexecutable: