public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] BaseTools: Fix python3.8 SyntaxWarning
@ 2019-07-12 17:29 Cole Robinson
  2019-07-12 21:03 ` Laszlo Ersek
  0 siblings, 1 reply; 4+ messages in thread
From: Cole Robinson @ 2019-07-12 17:29 UTC (permalink / raw)
  To: devel; +Cc: Laszlo Ersek, Cole Robinson

Building with python3.8 shows a warning like:

SyntaxWarning: invalid escape sequence \(
  GuidName = re.compile("\(GUID=[-a-fA-F0-9]+")

It seems harmless, but it's easy enough to fix: mark the string as
raw with the 'r' prefix like is used elsewhere in the file

Signed-off-by: Cole Robinson <crobinso@redhat.com>
---
 BaseTools/Source/Python/build/build.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py
index 8c3315619a..d6006b651f 100644
--- a/BaseTools/Source/Python/build/build.py
+++ b/BaseTools/Source/Python/build/build.py
@@ -1499,7 +1499,7 @@ class Build():
         if self.Fdf:
             # First get the XIP base address for FV map file.
             GuidPattern = re.compile("[-a-fA-F0-9]+")
-            GuidName = re.compile("\(GUID=[-a-fA-F0-9]+")
+            GuidName = re.compile(r"\(GUID=[-a-fA-F0-9]+")
             for FvName in Wa.FdfProfile.FvDict:
                 FvMapBuffer = os.path.join(Wa.FvDir, FvName + '.Fv.map')
                 if not os.path.exists(FvMapBuffer):
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] BaseTools: Fix python3.8 SyntaxWarning
  2019-07-12 17:29 [PATCH] BaseTools: Fix python3.8 SyntaxWarning Cole Robinson
@ 2019-07-12 21:03 ` Laszlo Ersek
  2019-07-13  2:54   ` Bob Feng
  0 siblings, 1 reply; 4+ messages in thread
From: Laszlo Ersek @ 2019-07-12 21:03 UTC (permalink / raw)
  To: Cole Robinson, devel; +Cc: Bob Feng, Liming Gao

On 07/12/19 19:29, Cole Robinson wrote:
> Building with python3.8 shows a warning like:
> 
> SyntaxWarning: invalid escape sequence \(
>   GuidName = re.compile("\(GUID=[-a-fA-F0-9]+")
> 
> It seems harmless, but it's easy enough to fix: mark the string as
> raw with the 'r' prefix like is used elsewhere in the file

I think the intent is to escape the opening paren '(' so that it lose
its special regex meaning. Is that correct?

And, the issue is that the backslash, meant for escaping the paren, in
effect introduces a *string literal* escape sequence. Is that correct?

If so, would it be correct to replace '\(' with '\\('?

(IOW, use the string literal escape sequence \\ to encode a raw \, and
then let the raw \ escape the ( on the regex level.)

Anyway, after reading up a bit on raw string literals, the patch appears
to do the same, only more readably. :)

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

(CC'ing BaseTools maintainers Bob and Liming.)

Thanks!
Laszlo

> 
> Signed-off-by: Cole Robinson <crobinso@redhat.com>
> ---
>  BaseTools/Source/Python/build/build.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py
> index 8c3315619a..d6006b651f 100644
> --- a/BaseTools/Source/Python/build/build.py
> +++ b/BaseTools/Source/Python/build/build.py
> @@ -1499,7 +1499,7 @@ class Build():
>          if self.Fdf:
>              # First get the XIP base address for FV map file.
>              GuidPattern = re.compile("[-a-fA-F0-9]+")
> -            GuidName = re.compile("\(GUID=[-a-fA-F0-9]+")
> +            GuidName = re.compile(r"\(GUID=[-a-fA-F0-9]+")
>              for FvName in Wa.FdfProfile.FvDict:
>                  FvMapBuffer = os.path.join(Wa.FvDir, FvName + '.Fv.map')
>                  if not os.path.exists(FvMapBuffer):
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] BaseTools: Fix python3.8 SyntaxWarning
  2019-07-12 21:03 ` Laszlo Ersek
@ 2019-07-13  2:54   ` Bob Feng
  2019-07-15 14:46     ` [edk2-devel] " Laszlo Ersek
  0 siblings, 1 reply; 4+ messages in thread
From: Bob Feng @ 2019-07-13  2:54 UTC (permalink / raw)
  To: Laszlo Ersek, Cole Robinson, devel@edk2.groups.io; +Cc: Gao, Liming

I tested this patch on python2.7 and 3.7. It works fine.

Reviewed-by: Bob Feng <bob.c.feng@intel.com>

-----Original Message-----
From: Laszlo Ersek [mailto:lersek@redhat.com] 
Sent: Saturday, July 13, 2019 5:03 AM
To: Cole Robinson <crobinso@redhat.com>; devel@edk2.groups.io
Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: Re: [PATCH] BaseTools: Fix python3.8 SyntaxWarning

On 07/12/19 19:29, Cole Robinson wrote:
> Building with python3.8 shows a warning like:
> 
> SyntaxWarning: invalid escape sequence \(
>   GuidName = re.compile("\(GUID=[-a-fA-F0-9]+")
> 
> It seems harmless, but it's easy enough to fix: mark the string as raw 
> with the 'r' prefix like is used elsewhere in the file

I think the intent is to escape the opening paren '(' so that it lose its special regex meaning. Is that correct?

And, the issue is that the backslash, meant for escaping the paren, in effect introduces a *string literal* escape sequence. Is that correct?

If so, would it be correct to replace '\(' with '\\('?

(IOW, use the string literal escape sequence \\ to encode a raw \, and then let the raw \ escape the ( on the regex level.)

Anyway, after reading up a bit on raw string literals, the patch appears to do the same, only more readably. :)

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

(CC'ing BaseTools maintainers Bob and Liming.)

Thanks!
Laszlo

> 
> Signed-off-by: Cole Robinson <crobinso@redhat.com>
> ---
>  BaseTools/Source/Python/build/build.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/BaseTools/Source/Python/build/build.py 
> b/BaseTools/Source/Python/build/build.py
> index 8c3315619a..d6006b651f 100644
> --- a/BaseTools/Source/Python/build/build.py
> +++ b/BaseTools/Source/Python/build/build.py
> @@ -1499,7 +1499,7 @@ class Build():
>          if self.Fdf:
>              # First get the XIP base address for FV map file.
>              GuidPattern = re.compile("[-a-fA-F0-9]+")
> -            GuidName = re.compile("\(GUID=[-a-fA-F0-9]+")
> +            GuidName = re.compile(r"\(GUID=[-a-fA-F0-9]+")
>              for FvName in Wa.FdfProfile.FvDict:
>                  FvMapBuffer = os.path.join(Wa.FvDir, FvName + '.Fv.map')
>                  if not os.path.exists(FvMapBuffer):
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [edk2-devel] [PATCH] BaseTools: Fix python3.8 SyntaxWarning
  2019-07-13  2:54   ` Bob Feng
@ 2019-07-15 14:46     ` Laszlo Ersek
  0 siblings, 0 replies; 4+ messages in thread
From: Laszlo Ersek @ 2019-07-15 14:46 UTC (permalink / raw)
  To: devel, bob.c.feng, Cole Robinson; +Cc: Gao, Liming

On 07/13/19 04:54, Bob Feng wrote:
> I tested this patch on python2.7 and 3.7. It works fine.
> 
> Reviewed-by: Bob Feng <bob.c.feng@intel.com>

(This is commit eebc135ffb21 now, thanks!)
Laszlo

> -----Original Message-----
> From: Laszlo Ersek [mailto:lersek@redhat.com] 
> Sent: Saturday, July 13, 2019 5:03 AM
> To: Cole Robinson <crobinso@redhat.com>; devel@edk2.groups.io
> Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: Re: [PATCH] BaseTools: Fix python3.8 SyntaxWarning
> 
> On 07/12/19 19:29, Cole Robinson wrote:
>> Building with python3.8 shows a warning like:
>>
>> SyntaxWarning: invalid escape sequence \(
>>   GuidName = re.compile("\(GUID=[-a-fA-F0-9]+")
>>
>> It seems harmless, but it's easy enough to fix: mark the string as raw 
>> with the 'r' prefix like is used elsewhere in the file
> 
> I think the intent is to escape the opening paren '(' so that it lose its special regex meaning. Is that correct?
> 
> And, the issue is that the backslash, meant for escaping the paren, in effect introduces a *string literal* escape sequence. Is that correct?
> 
> If so, would it be correct to replace '\(' with '\\('?
> 
> (IOW, use the string literal escape sequence \\ to encode a raw \, and then let the raw \ escape the ( on the regex level.)
> 
> Anyway, after reading up a bit on raw string literals, the patch appears to do the same, only more readably. :)
> 
> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
> 
> (CC'ing BaseTools maintainers Bob and Liming.)
> 
> Thanks!
> Laszlo
> 
>>
>> Signed-off-by: Cole Robinson <crobinso@redhat.com>
>> ---
>>  BaseTools/Source/Python/build/build.py | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/BaseTools/Source/Python/build/build.py 
>> b/BaseTools/Source/Python/build/build.py
>> index 8c3315619a..d6006b651f 100644
>> --- a/BaseTools/Source/Python/build/build.py
>> +++ b/BaseTools/Source/Python/build/build.py
>> @@ -1499,7 +1499,7 @@ class Build():
>>          if self.Fdf:
>>              # First get the XIP base address for FV map file.
>>              GuidPattern = re.compile("[-a-fA-F0-9]+")
>> -            GuidName = re.compile("\(GUID=[-a-fA-F0-9]+")
>> +            GuidName = re.compile(r"\(GUID=[-a-fA-F0-9]+")
>>              for FvName in Wa.FdfProfile.FvDict:
>>                  FvMapBuffer = os.path.join(Wa.FvDir, FvName + '.Fv.map')
>>                  if not os.path.exists(FvMapBuffer):
>>
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-07-15 14:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-12 17:29 [PATCH] BaseTools: Fix python3.8 SyntaxWarning Cole Robinson
2019-07-12 21:03 ` Laszlo Ersek
2019-07-13  2:54   ` Bob Feng
2019-07-15 14:46     ` [edk2-devel] " Laszlo Ersek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox