2
1

0001-Remove-deprecated-use-of-distutils-fix-for-Python-3..patch 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From 1ee5670803f89b21d84a6a84acbb578da051c119 Mon Sep 17 00:00:00 2001
  2. From: Ryan Volz <ryan.volz@gmail.com>
  3. Date: Tue, 26 Sep 2023 14:56:59 -0400
  4. Subject: [PATCH] Remove deprecated use of distutils, fix for Python 3.12+
  5. Remove deprecated use of distutils, fix for Python 3.12+
  6. This switches to using sysconfig from distutils, which is necessary for
  7. Python 3.12+ since distutils is deprecated and has been removed.
  8. It is necessary to specify the install scheme when a prefix other than
  9. the Python default is used so that changes to the default scheme made by
  10. distributions (e.g. Debian, Fedora) do not produce an incorrect Python
  11. installation directory. For example, Debian patches the default scheme
  12. to prepend the path with '/local', but if a user specifies a prefix of
  13. '/usr/local', then the path using the default scheme would be
  14. '/usr/local/local/...' with a duplicated 'local' directory. Specifying
  15. an unmodified install scheme fixes that.
  16. Signed-off-by: Ryan Volz <ryan.volz@gmail.com>
  17. Upstream: https://github.com/pothosware/SoapySDR/commit/1ee5670803f89b21d84a6a84acbb578da051c119
  18. Signed-off-by: Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
  19. ---
  20. swig/python/get_python_lib.py | 36 ++++++++++++++++++++++++-----------
  21. 1 file changed, 25 insertions(+), 11 deletions(-)
  22. diff --git a/python/get_python_lib.py b/python/get_python_lib.py
  23. index 0c71652..574f0b6 100644
  24. --- a/python/get_python_lib.py
  25. +++ b/python/get_python_lib.py
  26. @@ -1,19 +1,33 @@
  27. import os
  28. +import pathlib
  29. import sys
  30. -import site
  31. -from distutils.sysconfig import get_python_lib
  32. +import sysconfig
  33. if __name__ == '__main__':
  34. - prefix = sys.argv[1]
  35. + prefix = pathlib.Path(sys.argv[1]).resolve()
  36. - #ask distutils where to install the python module
  37. - install_dir = get_python_lib(plat_specific=True, prefix=prefix)
  38. + # default install dir for the running Python interpreter
  39. + default_install_dir = pathlib.Path(sysconfig.get_path('platlib')).resolve()
  40. - #use sites when the prefix is already recognized
  41. + # if default falls under the desired prefix, we're done
  42. try:
  43. - paths = [p for p in site.getsitepackages() if p.startswith(prefix)]
  44. - if len(paths) == 1: install_dir = paths[0]
  45. - except AttributeError: pass
  46. + relative_install_dir = default_install_dir.relative_to(prefix)
  47. + except ValueError:
  48. + # get install dir for the specified prefix
  49. + # can't use the default scheme because distributions modify it
  50. + # newer Python versions have 'venv' scheme, use for all OSs.
  51. + if 'venv' in sysconfig.get_scheme_names():
  52. + scheme = 'venv'
  53. + elif os.name == 'nt':
  54. + scheme = 'nt'
  55. + else:
  56. + scheme = 'posix_prefix'
  57. + prefix_install_dir = pathlib.Path(sysconfig.get_path(
  58. + 'platlib',
  59. + scheme=scheme,
  60. + vars={'base': prefix, 'platbase': prefix},
  61. + )).resolve()
  62. + relative_install_dir = prefix_install_dir.relative_to(prefix)
  63. - #strip the prefix to return a relative path
  64. - print(os.path.relpath(install_dir, prefix))
  65. + # want a relative path for use in the build system
  66. + print(relative_install_dir)
  67. --
  68. 2.49.0