0001-replace-imp.patch 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. From e2372bbecdf46a100b09126f2951431c1929637b Mon Sep 17 00:00:00 2001
  2. From: Adam Duskett <adam.duskett@amarulasolutions.com>
  3. Date: Tue, 24 Oct 2023 08:59:21 +0200
  4. Subject: [PATCH] Replace imp
  5. The imp module has been removed in python 3.12.0.
  6. This change has also been tested with Python 3.9.2 on Debian 11.
  7. From: https://docs.python.org/3.12/whatsnew/3.12.html#removed, follow the
  8. instructions to add the load_source method back into setup.py.
  9. Upstream: https://github.com/gorakhargosh/pathtools/pull/14
  10. Signed-off-by: Adam Duskett <adam.duskett@amarulasolutions.com>
  11. ---
  12. setup.py | 19 ++++++++++++++++---
  13. 1 file changed, 16 insertions(+), 3 deletions(-)
  14. diff --git a/setup.py b/setup.py
  15. index 4718885..1be0315 100644
  16. --- a/setup.py
  17. +++ b/setup.py
  18. @@ -22,12 +22,25 @@
  19. # THE SOFTWARE.
  20. import os
  21. -import imp
  22. +import importlib.util
  23. +import importlib.machinery
  24. from setuptools import setup
  25. PKG_DIR = 'pathtools'
  26. -version = imp.load_source('version',
  27. - os.path.join(PKG_DIR, 'version.py'))
  28. +
  29. +# From: https://docs.python.org/3.12/whatsnew/3.12.html#removed
  30. +def load_source(modname, filename):
  31. + loader = importlib.machinery.SourceFileLoader(modname, filename)
  32. + spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
  33. + module = importlib.util.module_from_spec(spec)
  34. + # The module is always executed and not cached in sys.modules.
  35. + # Uncomment the following line to cache the module.
  36. + # sys.modules[module.__name__] = module
  37. + loader.exec_module(module)
  38. + return module
  39. +
  40. +version = load_source('version',
  41. + os.path.join(PKG_DIR, 'version.py'))
  42. def read_file(filename):
  43. """
  44. --
  45. 2.41.0