From 0dadb8168fc3829f410e855f9510a9021d43405e Mon Sep 17 00:00:00 2001 From: Rich Chiodo false Date: Tue, 3 Dec 2024 13:35:25 -0800 Subject: [PATCH 1/2] Make sure attach binaries are built before running tox --- build_attach_binaries.py | 40 ++++++++++++++++++++++++++++++++++++++++ tests/requirements.txt | 6 +++++- tox.ini | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 build_attach_binaries.py diff --git a/build_attach_binaries.py b/build_attach_binaries.py new file mode 100644 index 000000000..136347218 --- /dev/null +++ b/build_attach_binaries.py @@ -0,0 +1,40 @@ +# This script is used for building the pydevd binaries +import argparse +import os + +def build_pydevd_binaries(force: bool): + os.environ["PYDEVD_USE_CYTHON"] = "yes" + + # Attempt to find where Visual Studio is installed if we're running on Windows. + if os.name == "nt": + try: + import pyMSVC + env = pyMSVC.Environment() + c_info = pyMSVC.VisualCInfo(env) + info = pyMSVC.VisualStudioInfo(env, c_info) + os.environ["FORCE_PYDEVD_VC_VARS"] = os.path.join(info.install_directory, "VC", "Auxiliary", "Build", "vcvars64.bat") + except ImportError: + pass + + # Run the pydevd build command. + pydevd_root = os.path.join(os.path.dirname(__file__), "src", "debugpy", "_vendored", "pydevd") + + # Run the appropriate batch script to build the binaries if necessary. + pydevd_attach_to_process_root = os.path.join(pydevd_root, "pydevd_attach_to_process") + if os.name == "nt": + if not os.path.exists(os.path.join(pydevd_attach_to_process_root, "attach_amd64.dll")) or force: + os.system(os.path.join(pydevd_attach_to_process_root, "windows", "compile_windows.bat")) + elif os.name == "posix": + if not os.path.exists(os.path.join(pydevd_attach_to_process_root, "attach_linux_amd64.so")) or force: + os.system(os.path.join(pydevd_attach_to_process_root, "linux_and_mac", "compile_linux.sh")) + else: + if not os.path.exists(os.path.join(pydevd_attach_to_process_root, "attach_x86_64.dylib")) or force: + os.system(os.path.join(pydevd_attach_to_process_root, "linux_and_mac", "compile_mac.sh")) + + +if __name__ == "__main__": + arg_parser = argparse.ArgumentParser(description="Build the pydevd binaries.") + arg_parser.add_argument("--force", action='store_true', help="Force a rebuild") + args = arg_parser.parse_args() + + build_pydevd_binaries(args.force) \ No newline at end of file diff --git a/tests/requirements.txt b/tests/requirements.txt index 7d48234e2..5b1cb2df4 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -19,4 +19,8 @@ flask gevent numpy requests -typing_extensions \ No newline at end of file +typing_extensions + +# Used to build pydevd attach to process binaries: +pyMSVC +Cython \ No newline at end of file diff --git a/tox.ini b/tox.ini index ade1981ac..6a0d21eba 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,7 @@ deps = -rtests/requirements.txt passenv = DEBUGPY_LOG_DIR,DEBUGPY_TESTS_FULL setenv = DEBUGPY_TEST=1 +commands_pre = python build_attach_binaries.py commands = py{38,39}-!cov: python -m pytest {posargs} py{38,39}-cov: python -m pytest --cov --cov-append --cov-config=.coveragerc {posargs} From b27776557783f30f0f99889e43eb3918dea71476 Mon Sep 17 00:00:00 2001 From: Rich Chiodo false Date: Tue, 3 Dec 2024 14:24:21 -0800 Subject: [PATCH 2/2] Fix errors on 3.13 --- build_attach_binaries.py | 11 +++++------ tests/requirements.txt | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/build_attach_binaries.py b/build_attach_binaries.py index 136347218..dc38fa08e 100644 --- a/build_attach_binaries.py +++ b/build_attach_binaries.py @@ -8,11 +8,10 @@ def build_pydevd_binaries(force: bool): # Attempt to find where Visual Studio is installed if we're running on Windows. if os.name == "nt": try: - import pyMSVC - env = pyMSVC.Environment() - c_info = pyMSVC.VisualCInfo(env) - info = pyMSVC.VisualStudioInfo(env, c_info) - os.environ["FORCE_PYDEVD_VC_VARS"] = os.path.join(info.install_directory, "VC", "Auxiliary", "Build", "vcvars64.bat") + import vswhere + install_path = vswhere.get_latest_path(prerelease=True) + if install_path is not None: + os.environ["FORCE_PYDEVD_VC_VARS"] = os.path.join(install_path, "VC", "Auxiliary", "Build", "vcvars64.bat") except ImportError: pass @@ -37,4 +36,4 @@ def build_pydevd_binaries(force: bool): arg_parser.add_argument("--force", action='store_true', help="Force a rebuild") args = arg_parser.parse_args() - build_pydevd_binaries(args.force) \ No newline at end of file + build_pydevd_binaries(args.force) diff --git a/tests/requirements.txt b/tests/requirements.txt index 5b1cb2df4..77fcfbe1e 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -22,5 +22,5 @@ requests typing_extensions # Used to build pydevd attach to process binaries: -pyMSVC +vswhere Cython \ No newline at end of file