[edk2] [PATCH 07/14] BaseTools: Use absolute import in BPDG

Gary Lin posted 14 patches 7 years, 7 months ago
There is a newer version of this series
[edk2] [PATCH 07/14] BaseTools: Use absolute import in BPDG
Posted by Gary Lin 7 years, 7 months ago
Based on "futurize -f libfuturize.fixes.fix_absolute_import

Contributed-under: TianoCore Contribution Agreement 1.1
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Gary Lin <glin@suse.com>
---
 BaseTools/Source/Python/BPDG/BPDG.py   | 5 +++--
 BaseTools/Source/Python/BPDG/GenVpd.py | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/BaseTools/Source/Python/BPDG/BPDG.py b/BaseTools/Source/Python/BPDG/BPDG.py
index 07cee8976208..2ec1516c0a08 100644
--- a/BaseTools/Source/Python/BPDG/BPDG.py
+++ b/BaseTools/Source/Python/BPDG/BPDG.py
@@ -21,6 +21,7 @@
 # Import Modules
 #
 from __future__ import print_function
+from __future__ import absolute_import
 import Common.LongFilePathOs as os
 import sys
 import encodings.ascii
@@ -30,8 +31,8 @@ from Common import EdkLogger
 from Common.BuildToolError import *
 from Common.BuildVersion import gBUILD_VERSION
 
-import StringTable as st
-import GenVpd
+from . import StringTable as st
+from . import GenVpd
 
 PROJECT_NAME       = st.LBL_BPDG_LONG_UNI
 VERSION            = (st.LBL_BPDG_VERSION + " Build " + gBUILD_VERSION)
diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py b/BaseTools/Source/Python/BPDG/GenVpd.py
index 2eefcc24905f..cd272a2d9a79 100644
--- a/BaseTools/Source/Python/BPDG/GenVpd.py
+++ b/BaseTools/Source/Python/BPDG/GenVpd.py
@@ -13,9 +13,10 @@
 #  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #
 
+from __future__ import absolute_import
 import Common.LongFilePathOs as os
 from io import BytesIO
-import StringTable as st
+from . import StringTable as st
 import array
 import re
 from Common.LongFilePathSupport import OpenLongFilePath as open
-- 
2.18.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 07/14] BaseTools: Use absolute import in BPDG
Posted by Zhu, Yonghong 7 years, 7 months ago
Hi Gary,

I got below error:

Traceback (most recent call last):
  File "C:\TCWork\Edk2\BaseTools\Source\Python\BPDG\BPDG.py", line 34, in <module>
    from . import StringTable as st
ValueError: Attempted relative import in non-package

Best Regards,
Zhu Yonghong


-----Original Message-----
From: Gary Lin [mailto:glin@suse.com] 
Sent: Tuesday, July 10, 2018 11:31 AM
To: edk2-devel@lists.01.org
Cc: Zhu, Yonghong <yonghong.zhu@intel.com>; Gao, Liming <liming.gao@intel.com>
Subject: [PATCH 07/14] BaseTools: Use absolute import in BPDG

Based on "futurize -f libfuturize.fixes.fix_absolute_import

Contributed-under: TianoCore Contribution Agreement 1.1
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Gary Lin <glin@suse.com>
---
 BaseTools/Source/Python/BPDG/BPDG.py   | 5 +++--
 BaseTools/Source/Python/BPDG/GenVpd.py | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/BaseTools/Source/Python/BPDG/BPDG.py b/BaseTools/Source/Python/BPDG/BPDG.py
index 07cee8976208..2ec1516c0a08 100644
--- a/BaseTools/Source/Python/BPDG/BPDG.py
+++ b/BaseTools/Source/Python/BPDG/BPDG.py
@@ -21,6 +21,7 @@
 # Import Modules
 #
 from __future__ import print_function
+from __future__ import absolute_import
 import Common.LongFilePathOs as os
 import sys
 import encodings.ascii
@@ -30,8 +31,8 @@ from Common import EdkLogger  from Common.BuildToolError import *  from Common.BuildVersion import gBUILD_VERSION
 
-import StringTable as st
-import GenVpd
+from . import StringTable as st
+from . import GenVpd
 
 PROJECT_NAME       = st.LBL_BPDG_LONG_UNI
 VERSION            = (st.LBL_BPDG_VERSION + " Build " + gBUILD_VERSION)
diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py b/BaseTools/Source/Python/BPDG/GenVpd.py
index 2eefcc24905f..cd272a2d9a79 100644
--- a/BaseTools/Source/Python/BPDG/GenVpd.py
+++ b/BaseTools/Source/Python/BPDG/GenVpd.py
@@ -13,9 +13,10 @@
 #  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #
 
+from __future__ import absolute_import
 import Common.LongFilePathOs as os
 from io import BytesIO
-import StringTable as st
+from . import StringTable as st
 import array
 import re
 from Common.LongFilePathSupport import OpenLongFilePath as open
--
2.18.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [PATCH 07/14] BaseTools: Use absolute import in BPDG
Posted by Gary Lin 7 years, 7 months ago
On Thu, Jul 12, 2018 at 12:52:32AM +0000, Zhu, Yonghong wrote:
> Hi Gary,
> 
> I got below error:
> 
> Traceback (most recent call last):
>   File "C:\TCWork\Edk2\BaseTools\Source\Python\BPDG\BPDG.py", line 34, in <module>
>     from . import StringTable as st
> ValueError: Attempted relative import in non-package
> 
Hmmm, so BPDG also uses the module in its own directory. I'll modify
BPDG in BinWrappers as GenFds.

Thanks,

Gary Lin

> Best Regards,
> Zhu Yonghong
> 
> 
> -----Original Message-----
> From: Gary Lin [mailto:glin@suse.com] 
> Sent: Tuesday, July 10, 2018 11:31 AM
> To: edk2-devel@lists.01.org
> Cc: Zhu, Yonghong <yonghong.zhu@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [PATCH 07/14] BaseTools: Use absolute import in BPDG
> 
> Based on "futurize -f libfuturize.fixes.fix_absolute_import
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Cc: Yonghong Zhu <yonghong.zhu@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Signed-off-by: Gary Lin <glin@suse.com>
> ---
>  BaseTools/Source/Python/BPDG/BPDG.py   | 5 +++--
>  BaseTools/Source/Python/BPDG/GenVpd.py | 3 ++-
>  2 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/BaseTools/Source/Python/BPDG/BPDG.py b/BaseTools/Source/Python/BPDG/BPDG.py
> index 07cee8976208..2ec1516c0a08 100644
> --- a/BaseTools/Source/Python/BPDG/BPDG.py
> +++ b/BaseTools/Source/Python/BPDG/BPDG.py
> @@ -21,6 +21,7 @@
>  # Import Modules
>  #
>  from __future__ import print_function
> +from __future__ import absolute_import
>  import Common.LongFilePathOs as os
>  import sys
>  import encodings.ascii
> @@ -30,8 +31,8 @@ from Common import EdkLogger  from Common.BuildToolError import *  from Common.BuildVersion import gBUILD_VERSION
>  
> -import StringTable as st
> -import GenVpd
> +from . import StringTable as st
> +from . import GenVpd
>  
>  PROJECT_NAME       = st.LBL_BPDG_LONG_UNI
>  VERSION            = (st.LBL_BPDG_VERSION + " Build " + gBUILD_VERSION)
> diff --git a/BaseTools/Source/Python/BPDG/GenVpd.py b/BaseTools/Source/Python/BPDG/GenVpd.py
> index 2eefcc24905f..cd272a2d9a79 100644
> --- a/BaseTools/Source/Python/BPDG/GenVpd.py
> +++ b/BaseTools/Source/Python/BPDG/GenVpd.py
> @@ -13,9 +13,10 @@
>  #  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>  #
>  
> +from __future__ import absolute_import
>  import Common.LongFilePathOs as os
>  from io import BytesIO
> -import StringTable as st
> +from . import StringTable as st
>  import array
>  import re
>  from Common.LongFilePathSupport import OpenLongFilePath as open
> --
> 2.18.0
> 
> 
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel