Skip to content

Commit

Permalink
Remove unnecessary string test by removing the lambda in pydevd_sys_m…
Browse files Browse the repository at this point in the history
…onitoring
  • Loading branch information
rchiodo committed Oct 29, 2024
1 parent 6a447b7 commit 45b2de7
Show file tree
Hide file tree
Showing 9 changed files with 4,447 additions and 3,084 deletions.
21 changes: 13 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ Using `pydevd_log.debug` you can add logging just about anywhere in the pydevd c

## Updating pydevd

Pydevd (at src/debugpy/_vendored/pydevd) is a copy of https://github.com/fabioz/PyDev.Debugger. We do not use a git submodule but instead just copy the source.
Pydevd (at src/debugpy/_vendored/pydevd) is a subrepo of https://github.com/fabioz/PyDev.Debugger. We use the [subrepo](https://github.com/ingydotnet/git-subrepo) to have a copy of pydevd inside of debugpy

In order to update the source, you would:
- Sync to the appropriate commit in a pydevd repo
- Diff this against the src/debugpy/_vendored/pydevd folder, being careful to not remove the edits made in the debugpy version
- Run our tests
- Make any fixes to get the tests to pass (see logging on how to debug)
- git checkout -b "branch name"
- python subrepo.py pull
- git push
- Fix any debugpy tests that are failing as a result of the pull
- Create a PR from your branch

You might need to regenerate the Cython modules after any changes. This can be done by:

Expand All @@ -123,13 +124,17 @@ You might need to regenerate the Cython modules after any changes. This can be d

If you've made changes to pydevd (at src/debugpy/_vendored/pydevd), you'll want to push back changes to pydevd so as Fabio makes changes to pydevd we can continue to share updates.

To do this, you would:

- python subrepo.py branch -m "pydevd branch you want to create"
- git push -f https://github.com/fabioz/PyDev.Debugger subrepo/src/debugpy/_vendored/pydevd:$(pydevd branch you want to create)
- Create a PR from that branch
- Get Fabio's buyoff on the changes

### Setting up pydevd to be testable

Follow these steps to get pydevd testable:

- git clone https://github.com/fabioz/PyDev.Debugger (or using your own fork)
- copy all of your changes from src/debugpy/_vendored/pydevd to the root of your PyDev.Debugger clone
- remove the pdb files (pydevd doesn't ship those) if you rebuilt the attach dlls
- create an environment to test. The list of stuff in your environment is outlined [here](https://github.com/fabioz/PyDev.Debugger/blob/6cd4d431e6a794448f33a73857d479149041500a/.github/workflows/pydevd-tests-python.yml#L83).
- set PYTHONPATH=. (make sure you don't forget this part, otherwise a lot of tests will fail)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ def short_frame(frame):

filename = frame.f_code.co_filename
name = splitext(basename(filename))[0]
return "%s::%s %s" % (name, frame.f_code.co_name, frame.f_lineno)
line = hasattr(frame, "f_lineno") and frame.f_lineno or 1
return "%s::%s %s" % (name, frame.f_code.co_name, line)


def short_stack(frame):
stack = []
while frame:
stack.append(short_frame(frame))
frame = frame.f_back
frame = frame.f_back if hasattr(frame, "f_back") else None
return "Stack: %s\n" % (" -> ".join(stack))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,15 +451,41 @@ def _get_thread_info(create: bool, depth: int) -> Optional[ThreadInfo]:
return _thread_local_info.thread_info


_CodeLineInfo = namedtuple("_CodeLineInfo", "line_to_offset, first_line, last_line")
# fmt: off
# IFDEF CYTHON
# cdef class _CodeLineInfo:
# cdef dict line_to_offset
# cdef int first_line
# cdef int last_line
# ELSE
class _CodeLineInfo:
line_to_offset: Dict[int, Any]
first_line: int
last_line: int
# ENDIF
# fmt: on

# fmt: off
# IFDEF CYTHON
# def __init__(self, dict line_to_offset, int first_line, int last_line):
# self.line_to_offset = line_to_offset
# self.first_line = first_line
# self.last_line = last_line
# ELSE
def __init__(self, line_to_offset, first_line, last_line):
self.line_to_offset = line_to_offset
self.first_line = first_line
self.last_line = last_line

# ENDIF
# fmt: on

# Note: this method has a version in cython too
# fmt: off
# IFDEF CYTHON
# cdef _get_code_line_info(code_obj, _cache={}):
# cdef _CodeLineInfo _get_code_line_info(code_obj, _cache={}):
# ELSE
def _get_code_line_info(code_obj, _cache={}):
def _get_code_line_info(code_obj, _cache={}) -> _CodeLineInfo:
# ENDIF
# fmt: on
try:
Expand Down
7,394 changes: 4,373 additions & 3,021 deletions src/debugpy/_vendored/pydevd/_pydevd_sys_monitoring/_pydevd_sys_monitoring_cython.c

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -457,15 +457,41 @@ cdef _get_thread_info(bint create, int depth):
return _thread_local_info.thread_info


_CodeLineInfo = namedtuple("_CodeLineInfo", "line_to_offset, first_line, last_line")
# fmt: off
# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated)
cdef class _CodeLineInfo:
cdef dict line_to_offset
cdef int first_line
cdef int last_line
# ELSE
# class _CodeLineInfo:
# line_to_offset: Dict[int, Any]
# first_line: int
# last_line: int
# ENDIF
# fmt: on

# fmt: off
# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated)
def __init__(self, dict line_to_offset, int first_line, int last_line):
self.line_to_offset = line_to_offset
self.first_line = first_line
self.last_line = last_line
# ELSE
# def __init__(self, line_to_offset, first_line, last_line):
# self.line_to_offset = line_to_offset
# self.first_line = first_line
# self.last_line = last_line
#
# ENDIF
# fmt: on

# Note: this method has a version in cython too
# fmt: off
# IFDEF CYTHON -- DONT EDIT THIS FILE (it is automatically generated)
cdef _get_code_line_info(code_obj, _cache={}):
cdef _CodeLineInfo _get_code_line_info(code_obj, _cache={}):
# ELSE
# def _get_code_line_info(code_obj, _cache={}):
# def _get_code_line_info(code_obj, _cache={}) -> _CodeLineInfo:
# ENDIF
# fmt: on
try:
Expand Down
11 changes: 0 additions & 11 deletions src/debugpy/_vendored/pydevd/pydevd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,17 +1073,6 @@ def get_file_type(self, frame, abs_real_path_and_basename=None, _cache_file_type
return _cache_file_type[cache_key]
except:
if abs_real_path_and_basename[0] == "<string>":
# TODO: This isn't ideal. We should make it so that "<string>" is
# never marked as pydevd (i.e.: investigate all the use cases
# where pydevd does this and actually mark it as "<pydevd-string>")

# Consider it an untraceable file unless there's no back frame (ignoring
# internal files and runpy.py).
if frame.f_back is not None and self.get_file_type(frame.f_back) == self.PYDEV_FILE:
# Special case, this is a string coming from pydevd itself. However we have to skip this logic for other
# files that are also marked as PYDEV_FILE (like external files marked this way)
return self.PYDEV_FILE

f = frame.f_back
while f is not None:
if self.get_file_type(f) != self.PYDEV_FILE and pydevd_file_utils.basename(f.f_code.co_filename) not in (
Expand Down

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions src/debugpy/_vendored/pydevd/tests_python/test_debugger_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5739,26 +5739,6 @@ def test_stop_on_entry2(case_setup_dap):
writer.finished_ok = True


def test_stop_on_entry_verify_strings(case_setup_dap):
with case_setup_dap.test_file("not_my_code/main_on_entry3.py") as writer:
json_facade = JsonFacade(writer)
json_facade.write_set_debugger_property([], ["main_on_entry3.py", "_pydevd_string_breakpoint.py"])
json_facade.write_launch(
justMyCode=True,
stopOnEntry=True,
showReturnValue=True,
rules=[
{"path": "**/main_on_entry3.py", "include": False},
{"path": "**/_pydevd_string_breakpoint.py", "include": False},
],
)

json_facade.write_make_initial_run()
json_facade.wait_for_thread_stopped("breakpoint", file="empty_file.py")
json_facade.write_continue()
writer.finished_ok = True


@pytest.mark.parametrize("val", [True, False])
def test_debug_options(case_setup_dap, val):
with case_setup_dap.test_file("_debugger_case_debug_options.py") as writer:
Expand Down

0 comments on commit 45b2de7

Please sign in to comment.