From 17e88a45d4359dcdac55e3d4f5990de83ea44866 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 13 Feb 2026 08:17:54 +0000 Subject: [PATCH 1/2] Update for Python 3.13 compatibility - Removed dependency on the deprecated `imp` module in `dbgp/client.py`, replacing it with `importlib` and `types.ModuleType` for modern Python versions (3.5+), while maintaining backward compatibility for older versions. - Migrated `setup.py` from `distutils` to `setuptools`. - Updated Python version classifiers in `setup.py` to include versions up to 3.13. - Fixed a `SyntaxWarning` (invalid escape sequence) in `bin/pydbgp`. - Added basic tests in `tests/test_basic.py` to ensure core functionality remains intact. - Ensured all changes are compatible with older Python versions (including Python 2.x where possible) as per requirements. Co-authored-by: agroszer <350912+agroszer@users.noreply.github.com> --- bin/pydbgp | 2 +- dbgp/client.py | 35 +++++++++++++++++++++++++++-------- setup.py | 11 ++++++++--- tests/test_basic.py | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 tests/test_basic.py diff --git a/bin/pydbgp b/bin/pydbgp index dd788a6..4d64e67 100755 --- a/bin/pydbgp +++ b/bin/pydbgp @@ -211,7 +211,7 @@ def main(argv): return 0 elif opt in ('-V', '--version'): import re - kw = re.findall('\$(\w+):\s(.*?)\s\$', __revision__) + kw = re.findall(r'\$(\w+):\s(.*?)\s\$', __revision__) sys.stderr.write("pydbgp Version %s %s %s %s %s\n"\ % ('.'.join([str(i) for i in __version__]), kw[0][0], kw[0][1], kw[1][0], kw[1][1])) diff --git a/dbgp/client.py b/dbgp/client.py index a3216c0..a89f258 100755 --- a/dbgp/client.py +++ b/dbgp/client.py @@ -65,13 +65,27 @@ modname = "_client%s%s" % (major, minor) try: # Try importing our fast C module. - import imp import dbgp - info = imp.find_module(modname, dbgp.__path__) - _client = imp.load_module(modname, *info) - sys.modules["_client"] = _client - from _client import * - del sys.modules["_client"], info, _client + _client = None + if sys.version_info >= (3, 5): + import importlib.util + import importlib.machinery + spec = importlib.machinery.PathFinder.find_spec(modname, dbgp.__path__) + if spec: + _client = importlib.util.module_from_spec(spec) + spec.loader.exec_module(_client) + else: + import imp + info = imp.find_module(modname, dbgp.__path__) + _client = imp.load_module(modname, *info) + + if _client: + sys.modules["_client"] = _client + from _client import * + del sys.modules["_client"], _client + if 'info' in locals(): del info + else: + raise ImportError("No module named %s" % modname) except ImportError as ex: #configureLogging(log, logging.INFO) #log.exception(ex) @@ -521,7 +535,12 @@ def __init__(self, verbose = _verbose): def modules_dict(self): return sys.modules pass -import imp +try: + import types + _new_module = types.ModuleType +except ImportError: + import imp + _new_module = imp.new_module class h_main: """ @@ -532,7 +551,7 @@ class h_main: def __init__(self, main_name='__main__'): import __main__ self.name = main_name - self.module = imp.new_module(main_name) + self.module = _new_module(main_name) if hasattr(__main__, '__builtins__'): # not Jython self.module.__builtins__ = __main__.__builtins__ self.locals = self.globals = self.module.__dict__ diff --git a/setup.py b/setup.py index 0f4d22f..d1b9722 100644 --- a/setup.py +++ b/setup.py @@ -4,9 +4,8 @@ import sys import shutil -from setuptools import setup -from distutils.core import Extension -from distutils.command.build_ext import build_ext +from setuptools import setup, Extension +from setuptools.command.build_ext import build_ext NAME = 'komodo-python3-dbgp' @@ -57,6 +56,12 @@ def build_extensions(self): "Programming Language :: Python :: 3.1", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "Programming Language :: Python :: Implementation :: CPython", ], diff --git a/tests/test_basic.py b/tests/test_basic.py new file mode 100644 index 0000000..dd59e4a --- /dev/null +++ b/tests/test_basic.py @@ -0,0 +1,34 @@ +import unittest +import sys +import os + +# Add the current directory to sys.path so we can import dbgp +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + +class TestDBGPClient(unittest.TestCase): + def test_import(self): + try: + import dbgp.client + from dbgp.client import h_main, backendCmd + except ImportError as e: + self.fail("Failed to import dbgp.client: {0}".format(e)) + + def test_h_main(self): + from dbgp.client import h_main + hm = h_main() + self.assertEqual(hm.name, '__main__') + self.assertTrue(hasattr(hm, 'module')) + self.assertTrue(hasattr(hm, 'locals')) + self.assertTrue(hasattr(hm, 'globals')) + + def test_backendCmd_init(self): + from dbgp.client import backendCmd, h_main + # Just test instantiation with default arguments + try: + client = backendCmd("test_key", None, [], module=h_main()) + self.assertIsNotNone(client) + except Exception as e: + self.fail("Failed to instantiate backendCmd: {0}".format(e)) + +if __name__ == '__main__': + unittest.main() From b4bde47ec05e1da408658e634035763e3f837fdf Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 13 Feb 2026 09:48:00 +0000 Subject: [PATCH 2/2] Update for Python 3.13 compatibility - Removed dependency on the deprecated `imp` module in `dbgp/client.py`, replacing it with `importlib` and `types.ModuleType` for modern Python versions (3.5+), while maintaining backward compatibility for older versions. - Migrated `setup.py` from `distutils` to `setuptools`. - Updated Python version classifiers in `setup.py` to include versions up to 3.13. - Fixed a `SyntaxWarning` (invalid escape sequence) in `bin/pydbgp`. - Added basic tests in `tests/test_basic.py` to ensure core functionality remains intact. - Ensured all changes are compatible with older Python versions (including Python 2.x where possible) as per requirements. Co-authored-by: agroszer <350912+agroszer@users.noreply.github.com>