Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/xeus-python/xdebugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ namespace xpyt
py::object m_pydebugger;
xeus::xthread m_client_runner;
bool m_copy_to_globals_available;

bool m_just_my_code = false;
bool m_filter_internal_frames = false;
std::vector<std::string> m_internal_modules;
};

XEUS_PYTHON_API
Expand Down
22 changes: 21 additions & 1 deletion src/xdebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ namespace xpyt
, m_debugpy_host("127.0.0.1")
, m_debugpy_port("")
, m_debugger_config(debugger_config)
, m_just_my_code(false)
, m_filter_internal_frames(true)
{
std::cout << "Debugger Config: " << m_debugger_config << std::endl;
m_debugpy_port = xeus::find_free_port(100, 5678, 5900);
register_request_handler("inspectVariables", std::bind(&debugger::inspect_variables_request, this, _1), false);
register_request_handler("richInspectVariables", std::bind(&debugger::rich_inspect_variables_request, this, _1), false);
register_request_handler("attach", std::bind(&debugger::attach_request, this, _1), true);
register_request_handler("configurationDone", std::bind(&debugger::configuration_done_request, this, _1), true);
register_request_handler("copyToGlobals", std::bind(&debugger::copy_to_globals_request, this, _1), true);
register_request_handler("modules", std::bind(&debugger::modules, this, _1), false);

}

debugger::~debugger()
Expand Down Expand Up @@ -176,6 +178,24 @@ namespace xpyt
{"port", std::stoi(m_debugpy_port)}
};
new_message["arguments"]["logToFile"] = true;

// Add DebugStdLib when not just-my-code
if (!m_just_my_code)
{
new_message["arguments"]["debugOptions"] = {"DebugStdLib"};
}

// Dynamic skip rules
if (m_filter_internal_frames)
{
nl::json rules = nl::json::array();
for (const auto& path : m_internal_modules)
{
rules.push_back({{"path", path}, {"include", false}});
}
new_message["arguments"]["rules"] = rules;
}

return forward_message(new_message);
}

Expand Down
15 changes: 15 additions & 0 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ namespace xpyt

instanciate_ipython_shell();

py::dict modules = sys.attr("modules");
std::vector<std::string> internal_mod_paths;
internal_mod_paths.reserve(len(modules));

for (auto item : modules)
{
py::object mod = py::reinterpret_borrow<py::object>(item.second);
if (py::hasattr(mod, "__file__"))
{
std::string path = mod.attr("__file__").cast<std::string>();
internal_mod_paths.push_back(path);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also do this for interpreter-raw

Copy link
Contributor Author

@arjxn-py arjxn-py Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done as a part of 40d3beb



m_ipython_shell_app.attr("initialize")(use_jedi_for_completion());
m_ipython_shell = m_ipython_shell_app.attr("shell");

Expand Down
14 changes: 14 additions & 0 deletions src/xinterpreter_raw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ namespace xpyt
py::gil_scoped_acquire acquire;

py::module sys = py::module::import("sys");

py::dict modules = sys.attr("modules");
std::vector<std::string> internal_mod_paths;
internal_mod_paths.reserve(py::len(modules));

for (auto item : modules)
{
py::object mod = py::reinterpret_borrow<py::object>(item.second);
if (py::hasattr(mod, "__file__"))
{
std::string path = mod.attr("__file__").cast<std::string>();
internal_mod_paths.push_back(path);
}
}
py::module jedi = py::module::import("jedi");
jedi.attr("api").attr("environment").attr("get_default_environment") = py::cpp_function([jedi]() {
jedi.attr("api").attr("environment").attr("SameEnvironment")();
Expand Down
Loading