Require Python 3
PATCH 1/6 Require Python 3
We don't need to support Python 2 anymore, so drop the comment and add the minimum required version. Use version 3.8 since I am not sure that it works on older versions and 3.7 has reached end-of-life.
---
setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
setup.py +1 -3
@@ -1,9 +1,6 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) -# While Python 3 is the default, it's also possible to invoke -# this setup.py script with Python 2. - """ setup.py file for SWIG libfdt Copyright (C) 2017 Google, Inc.
@@ -60,6 +57,7 @@ setup( ext_modules=[libfdt_module], package_dir={'': os.path.join(srcdir, 'pylibfdt')}, py_modules=['libfdt'], + python_requires=">=3.8", long_description=long_description, long_description_content_type="text/plain",
Signature · 1 line
2.34.1
PATCH 2/6 Tidy up some pylint warnings
Resolve all the pylint warnings currently in setup.py
---
setup.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
setup.py +16 -9
@@ -7,28 +7,32 @@ Copyright (C) 2017 Google, Inc. Written by Simon Glass <[email protected]> """ +import os +import sys + from setuptools import setup, Extension from setuptools.command.build_py import build_py as _build_py -import os -import re -import sys srcdir = os.path.dirname(__file__) -with open(os.path.join(srcdir, "README.md"), "r") as fh: +with open(os.path.join(srcdir, "README.md"), "r", encoding='utf-8') as fh: long_description = fh.read() -with open(os.path.join(srcdir, "VERSION.txt"), "r") as fh: +with open(os.path.join(srcdir, "VERSION.txt"), "r", encoding='utf-8') as fh: version = fh.readline().strip() def get_top_builddir(): + """Figure out the top-level directory containing the source code + + Returns: + str: Directory to build in + """ if '--top-builddir' in sys.argv: index = sys.argv.index('--top-builddir') sys.argv.pop(index) return sys.argv.pop(index) - else: - return srcdir + return srcdir top_builddir = get_top_builddir()
@@ -42,15 +46,18 @@ libfdt_module = Extension( swig_opts=['-I' + os.path.join(srcdir, 'libfdt')], ) -class build_py(_build_py): + +class BuildPy(_build_py): + """Small class to run the build_ext command""" def run(self): self.run_command("build_ext") return super().run() + setup( name='libfdt', version=version, - cmdclass = {'build_py' : build_py}, + cmdclass = {'build_py' : BuildPy}, author='Simon Glass', author_email='[email protected]', description='Python binding for libfdt',
Signature · 1 line
2.34.1
David Gibson
AppliedRe: [PATCH 2/6] Tidy up some pylint warnings
Quoted 3 lines · Simon Glass
Resolve all the pylint warnings currently in
setup.pySigned-off-by Simon Glass <[email protected]>
Applied, thanks.
Quoted 70 lines
---
setup.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)setup.py +16
-9@@ -7,28 +7,32 @@ Copyright (C) 2017 Google, Inc. Written by Simon Glass <[email protected]> """ +import os +import sys + from setuptools import setup, Extension from setuptools.command.build_py import build_py as _build_py -import os -import re -import sys srcdir = os.path.dirname(__file__) -with open(os.path.join(srcdir, "README.md"), "r") as fh: +with open(os.path.join(srcdir, "README.md"), "r", encoding='utf-8') as fh: long_description = fh.read() -with open(os.path.join(srcdir, "VERSION.txt"), "r") as fh: +with open(os.path.join(srcdir, "VERSION.txt"), "r", encoding='utf-8') as fh: version = fh.readline().strip() def get_top_builddir(): + """Figure out the top-level directory containing the source code + + Returns: + str: Directory to build in + """ if '--top-builddir' in sys.argv: index = sys.argv.index('--top-builddir') sys.argv.pop(index) return sys.argv.pop(index) - else: - return srcdir + return srcdir top_builddir = get_top_builddir()@@ -42,15 +46,18 @@ libfdt_module = Extension( swig_opts=['-I' + os.path.join(srcdir, 'libfdt')], ) -class build_py(_build_py): + +class BuildPy(_build_py): + """Small class to run the build_ext command""" def run(self): self.run_command("build_ext") return super().run() + setup( name='libfdt', version=version, - cmdclass = {'build_py' : build_py}, + cmdclass = {'build_py' : BuildPy}, author='Simon Glass', author_email='[email protected]', description='Python binding for libfdt',
Signature · 4 lines
David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson
PATCH 3/6 setup: Move version and full_description into a function
In reply to Simon GlassDo this processing in a function and return the result, to reduce the amount of code at the top level.
---
setup.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
setup.py +18 -4
@@ -16,11 +16,24 @@ from setuptools.command.build_py import build_py as _build_py srcdir = os.path.dirname(__file__) -with open(os.path.join(srcdir, "README.md"), "r", encoding='utf-8') as fh: - long_description = fh.read() +def scan_for_info(srcdir): + """Scan for the version and long_description fields + + Args: + srcdir (str): Source-directory path + + Returns: tuple + str: Full description (contents of README.md) + str: Version string + """ + with open(os.path.join(srcdir, "VERSION.txt"), "r", encoding='utf-8') as fh: + version = fh.readline().strip() + + with open(os.path.join(srcdir, "README.md"), "r", encoding='utf-8') as fh: + long_description = fh.read() + + return version, long_description -with open(os.path.join(srcdir, "VERSION.txt"), "r", encoding='utf-8') as fh: - version = fh.readline().strip() def get_top_builddir(): """Figure out the top-level directory containing the source code
@@ -53,6 +66,7 @@ class BuildPy(_build_py): self.run_command("build_ext") return super().run() +version, long_description = scan_for_info(srcdir) setup( name='libfdt',
Signature · 1 line
2.34.1
David Gibson
AppliedRe: [PATCH 3/6] setup: Move version and full_description into a function
Quoted 4 lines · Simon Glass
Do this processing in a function and return the result, to reduce the amount of code at the top level.
Signed-off-by Simon Glass <[email protected]>
Applied, thanks.
Quoted 46 lines
---
setup.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)setup.py +18
-4@@ -16,11 +16,24 @@ from setuptools.command.build_py import build_py as _build_py srcdir = os.path.dirname(__file__) -with open(os.path.join(srcdir, "README.md"), "r", encoding='utf-8') as fh: - long_description = fh.read() +def scan_for_info(srcdir): + """Scan for the version and long_description fields + + Args: + srcdir (str): Source-directory path + + Returns: tuple + str: Full description (contents of README.md) + str: Version string + """ + with open(os.path.join(srcdir, "VERSION.txt"), "r", encoding='utf-8') as fh: + version = fh.readline().strip() + + with open(os.path.join(srcdir, "README.md"), "r", encoding='utf-8') as fh: + long_description = fh.read() + + return version, long_description -with open(os.path.join(srcdir, "VERSION.txt"), "r", encoding='utf-8') as fh: - version = fh.readline().strip() def get_top_builddir(): """Figure out the top-level directory containing the source code@@ -53,6 +66,7 @@ class BuildPy(_build_py): self.run_command("build_ext") return super().run() +version, long_description = scan_for_info(srcdir) setup( name='libfdt',
Signature · 4 lines
David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson
PATCH 4/6 setup: Collect top-level code together
In reply to Simon GlassMove most of the top-level code together, with the classes and functions above, for easier reading.
The srcdir is left where it is for now.
---
setup.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
setup.py +9 -8
@@ -47,6 +47,15 @@ def get_top_builddir(): return sys.argv.pop(index) return srcdir + +class BuildPy(_build_py): + """Small class to run the build_ext command""" + def run(self): + self.run_command("build_ext") + return super().run() + + +version, long_description = scan_for_info(srcdir) top_builddir = get_top_builddir() libfdt_module = Extension(
@@ -60,14 +69,6 @@ libfdt_module = Extension( ) -class BuildPy(_build_py): - """Small class to run the build_ext command""" - def run(self): - self.run_command("build_ext") - return super().run() - -version, long_description = scan_for_info(srcdir) - setup( name='libfdt', version=version,
Signature · 1 line
2.34.1
PATCH 5/6 setup: Move setting of srcdir down to the bottom
In reply to Simon GlassPut this variable assignment next to the others. Pass it to get_top_builddir() instead of relying on the global variable.
---
setup.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
setup.py +6 -5
@@ -14,8 +14,6 @@ from setuptools import setup, Extension from setuptools.command.build_py import build_py as _build_py -srcdir = os.path.dirname(__file__) - def scan_for_info(srcdir): """Scan for the version and long_description fields
@@ -35,9 +33,12 @@ def scan_for_info(srcdir): return version, long_description -def get_top_builddir(): +def get_top_builddir(srcdir): """Figure out the top-level directory containing the source code + Args: + srcdir (str): Source-directory path + Returns: str: Directory to build in """
@@ -55,8 +56,8 @@ class BuildPy(_build_py): return super().run() +srcdir = os.path.dirname(__file__) version, long_description = scan_for_info(srcdir) -top_builddir = get_top_builddir() libfdt_module = Extension( '_libfdt',
@@ -64,7 +65,7 @@ libfdt_module = Extension( define_macros=[('PY_SSIZE_T_CLEAN', None)], include_dirs=[os.path.join(srcdir, 'libfdt')], libraries=['fdt'], - library_dirs=[os.path.join(top_builddir, 'libfdt')], + library_dirs=[os.path.join(get_top_builddir(srcdir), 'libfdt')], swig_opts=['-I' + os.path.join(srcdir, 'libfdt')], )
Signature · 1 line
2.34.1
David Gibson
AppliedRe: [PATCH 5/6] setup: Move setting of srcdir down to the bottom
Quoted 4 lines · Simon Glass
Put this variable assignment next to the others. Pass it to
get_top_builddir()instead of relying on the global variable.Signed-off-by Simon Glass <[email protected]>
Applied, thanks.
Quoted 51 lines
---
setup.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)setup.py +6
-5@@ -14,8 +14,6 @@ from setuptools import setup, Extension from setuptools.command.build_py import build_py as _build_py -srcdir = os.path.dirname(__file__) - def scan_for_info(srcdir): """Scan for the version and long_description fields@@ -35,9 +33,12 @@ def scan_for_info(srcdir): return version, long_description -def get_top_builddir(): +def get_top_builddir(srcdir): """Figure out the top-level directory containing the source code + Args: + srcdir (str): Source-directory path + Returns: str: Directory to build in """@@ -55,8 +56,8 @@ class BuildPy(_build_py): return super().run() +srcdir = os.path.dirname(__file__) version, long_description = scan_for_info(srcdir) -top_builddir = get_top_builddir() libfdt_module = Extension( '_libfdt',@@ -64,7 +65,7 @@ libfdt_module = Extension( define_macros=[('PY_SSIZE_T_CLEAN', None)], include_dirs=[os.path.join(srcdir, 'libfdt')], libraries=['fdt'], - library_dirs=[os.path.join(top_builddir, 'libfdt')], + library_dirs=[os.path.join(get_top_builddir(srcdir), 'libfdt')], swig_opts=['-I' + os.path.join(srcdir, 'libfdt')], )
Signature · 4 lines
David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson
PATCH 6/6 setup: Add dependencies for Windows
In reply to Simon GlassFrom: Gua Guo <[email protected]>
Windows apparently builds pylibfdt if swig is declared as a dependency in the setup file. Otherwise it must be installed manually and Windows does not sport a package manager, so this is hard for users.
This change seems to have no ill effects on Linux, at least.
So add a new setup_requires line.
---
This was picked up from:
https://github.com/devicetree-org/pylibfdt/pull/2
setup.py | 1 + 1 file changed, 1 insertion(+)
setup.py +1 -0
@@ -76,6 +76,7 @@ setup( cmdclass = {'build_py' : BuildPy}, author='Simon Glass', author_email='[email protected]', + setup_requires = ['swig'], description='Python binding for libfdt', ext_modules=[libfdt_module], package_dir={'': os.path.join(srcdir, 'pylibfdt')},
Signature · 1 line
2.34.1
David Gibson
AppliedRe: [PATCH 6/6] setup: Add dependencies for Windows
Quoted 6 lines · Simon Glass
From: Gua Guo <[email protected]>
Windows apparently builds pylibfdt if swig is declared as a dependency in the setup file. Otherwise it must be installed manually and Windows does not sport a package manager, so this is hard for users.
Quoted 6 lines
This change seems to have no ill effects on Linux, at least.
So add a new
setup_requiresline.Signed-off-by Gua Guo <[email protected]>Signed-off-by Simon Glass <[email protected]>
Applied.
We do have windows build in our github actions. It would be great if a test for building pylibfdt properly there were added.
Quoted 20 lines
---
This was picked up from:https://github.com/devicetree-org/pylibfdt/pull/2
setup.py | 1 + 1 file changed, 1 insertion(+)setup.py +1
-0@@ -76,6 +76,7 @@ setup( cmdclass = {'build_py' : BuildPy}, author='Simon Glass', author_email='[email protected]', + setup_requires = ['swig'], description='Python binding for libfdt', ext_modules=[libfdt_module], package_dir={'': os.path.join(srcdir, 'pylibfdt')},
Signature · 4 lines
David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson
Re: [PATCH 6/6] setup: Add dependencies for Windows
Quoted 7 lines · David Gibson
Quoted 6 lines · Simon Glass
From: Gua Guo <[email protected]>
Windows apparently builds pylibfdt if swig is declared as a dependency in the setup file. Otherwise it must be installed manually and Windows does not sport a package manager, so this is hard for users.
Quoted 8 lines
Quoted 6 lines
This change seems to have no ill effects on Linux, at least.
So add a new
setup_requiresline.Signed-off-by Gua Guo <[email protected]>Signed-off-by Simon Glass <[email protected]>Applied.
Oops, spoke too soon. While this works locally for me, it breaks on the github CI. See:
https://github.com/dgibson/dtc/actions/runs/10344711112
Quoted 2 lines
We do have windows build in our github actions. It would be great if a test for building pylibfdt properly there were added.
This remains true, once the Linux breakage is fixed.
Signature · 4 lines
David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson
Re: [PATCH 6/6] setup: Add dependencies for Windows
Hi David,
Quoted 21 lines · David Gibson
Quoted 7 lines · David Gibson
Quoted 6 lines · Simon Glass
From: Gua Guo <[email protected]>
Windows apparently builds pylibfdt if swig is declared as a dependency in the setup file. Otherwise it must be installed manually and Windows does not sport a package manager, so this is hard for users.
Quoted 8 lines
Quoted 6 lines
This change seems to have no ill effects on Linux, at least.
So add a new
setup_requiresline.Signed-off-by Gua Guo <[email protected]>Signed-off-by Simon Glass <[email protected]>Applied.
Oops, spoke too soon. While this works locally for me, it breaks on the github CI. See:
Quoted 6 lines
https://github.com/dgibson/dtc/actions/runs/10344711112Quoted 2 lines
We do have windows build in our github actions. It would be great if a test for building pylibfdt properly there were added.
This remains true, once the Linux breakage is fixed.
Thanks for that. We'll try to figure out that MSYS2 error.
Regards,
Simon
Quoted 6 lines
--
David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around.
+Rob Herring too in case you are not on this list
Quoted 36 lines · Simon Glass
We don't need to support Python 2 anymore, so drop the comment and add the minimum required version. Use version 3.8 since I am not sure that it works on older versions and 3.7 has reached end-of-life.
Signed-off-by Simon Glass <[email protected]>---
setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)setup.py +1
-4@@ -1,9 +1,6 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) -# While Python 3 is the default, it's also possible to invoke -# this setup.py script with Python 2. - """ setup.py file for SWIG libfdt Copyright (C) 2017 Google, Inc.@@ -60,6 +57,7 @@ setup( ext_modules=[libfdt_module], package_dir={'': os.path.join(srcdir, 'pylibfdt')}, py_modules=['libfdt'], + python_requires=">=3.8", long_description=long_description, long_description_content_type="text/plain", --2.34.1
David Gibson
AppliedQuoted 5 lines · Simon Glass
We don't need to support Python 2 anymore, so drop the comment and add the minimum required version. Use version 3.8 since I am not sure that it works on older versions and 3.7 has reached end-of-life.
Signed-off-by Simon Glass <[email protected]>
Applied, thanks.
Quoted 27 lines
---
setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)setup.py +1
-3@@ -1,9 +1,6 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) -# While Python 3 is the default, it's also possible to invoke -# this setup.py script with Python 2. - """ setup.py file for SWIG libfdt Copyright (C) 2017 Google, Inc.@@ -60,6 +57,7 @@ setup( ext_modules=[libfdt_module], package_dir={'': os.path.join(srcdir, 'pylibfdt')}, py_modules=['libfdt'], + python_requires=">=3.8", long_description=long_description, long_description_content_type="text/plain",
Signature · 4 lines
David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson