Skip to content

Commit

Permalink
Rename ptvsd -> debugpy.
Browse files Browse the repository at this point in the history
  • Loading branch information
int19h committed Jan 17, 2020
1 parent 2731604 commit 8b4c40e
Show file tree
Hide file tree
Showing 744 changed files with 580 additions and 531 deletions.
12 changes: 6 additions & 6 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[run]
branch = True
include =
src/ptvsd/*
src/debugpy/*
omit =
src/ptvsd/__init__.py
src/ptvsd/_version.py
src/ptvsd/_vendored/*
src/ptvsd/server/*
src/debugpy/__init__.py
src/debugpy/_version.py
src/debugpy/_vendored/*
src/debugpy/server/*
data_file = coverage/.coverage

[report]
Expand All @@ -29,7 +29,7 @@ exclude_lines =

[html]
directory = coverage/html
title = ptvsd coverage report
title = debugpy coverage report

[xml]
output = coverage/coverage.xml
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ exclude =
build,
dist,
versioneer.py,
src/ptvsd/_vendored/pydevd
src/debugpy/_vendored/pydevd
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ptvsd/_version.py export-subst
debugpy/_version.py export-subst
6 changes: 0 additions & 6 deletions .pylintrc

This file was deleted.

4 changes: 2 additions & 2 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sonar.sources=src/ptvsd
sonar.exclusions=src/ptvsd/_vendored/**/*,src/ptvsd/_version.py
sonar.sources=src/debugpy
sonar.exclusions=src/debugpy/_vendored/**/*,src/debugpy/_version.py
sonar.cfamily.build-wrapper-output.bypass=true
sonar.c.file.suffixes=-
sonar.cpp.file.suffixes=-
Expand Down
15 changes: 9 additions & 6 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
This project has adopted the [Microsoft Open Source Code of
Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct
FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com)
with any additional questions or comments.
# Microsoft Open Source Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).

Resources:

- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
100 changes: 61 additions & 39 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to `ptvsd`
# Contributing to `debugpy`

[![Build Status](https://ptvsd.visualstudio.com/_apis/public/build/definitions/557bd35a-f98d-4c49-9bc9-c7d548f78e4d/1/badge)](https://ptvsd.visualstudio.com/ptvsd/ptvsd%20Team/_build/index?definitionId=1)
[![Build Status](https://travis-ci.org/Microsoft/ptvsd.svg?branch=master)](https://travis-ci.org/Microsoft/ptvsd)
Expand All @@ -15,55 +15,77 @@ When you submit a pull request, a CLA-bot will automatically determine whether y
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

### Prerequisites
Use [tests/requirements.txt](tests/requirements.txt) file to install the packages needed to run tests:
```console
pip install -r tests/requirements.txt
## Development tools

The following tools are required to work on debugpy:

- At least one version of [Python 3](https://www.python.org/downloads/)
- [Python 2.7](https://www.python.org/downloads/release/python-2717/) (to run tests)
- [Flake8](http://flake8.pycqa.org/en/stable/)
- [Black](https://black.readthedocs.io/en/stable/)
- [tox](https://tox.readthedocs.io/en/latest/)

We recommend using [Visual Studio Code](https://code.visualstudio.com/) with the (Python extension)[https://marketplace.visualstudio.com/items?itemName=ms-python.python] to work on debugpy, but it's not a requirement. A workspace file, [debugpy.code-workspace], is provided for the convenience of VSCode users, and sets it up to use the other tools listed above properly.

Tools that are Python packages should be installed via pip corresponding to the Python 3 installation. On Windows:
```
...> py -m pip install black flake8 tox
```
On Linux or macOS:
```
...$ python3 -m pip install black flake8 tox
```

### Linting
We use `flake8` for linting, and the settings can be found here [flake8](.flake8)
## Linting
We use Flake8 for linting. It should be run from the root of the repository, where [.flake8](.flake8) with project-specific linting settings is located. On Windows:
```
...\debugpy> py -m flake8
```
On Linux or macOS:
```
.../debugpy$ python3 -m flake8
```

### Formatting
This is optional. Use the following settings for `autopep8` or equivalent settings with the formatter of your choice:
VSC Python settings for formating:
```json
"python.formatting.provider": "autopep8",
"python.formatting.autopep8Args": [
"--ignore", "E24,E121,E123,E125,E126,E221,E226,E266,E704,E265,E722,E501,E731,E306,E401,E302,E222"
],
## Formatting
We use Black for formatting. All new code files, and all code files that were edited, should be reformatted before submitting a PR. On Windows:
```
...\debugpy> py -m black
```
On Linux or macOS:
```
.../debugpy$ python3 -m black
```

### Running tests
We are currently migrating the tests to use `pytest`. Please run both set of tests. Newer tests must go into the [tests](tests) directory. Use [test_requirements.txt](test_requirements.txt) to install packages needed to run the tests.
#### Windows
## Running tests

We use tox to run tests in an isolated environment. This ensures that debugpy is first built as a package, and tox also takes care of installing all the test prerequisites into the environment. On Windows:
```
...\debugpy> py -m tox
```
C:\> git clone https://github.com/Microsoft/ptvsd
C:\> cd ptvsd
C:\ptvsd> py -3.7 -m pip install -r test_requirements.txt
C:\ptvsd> py -3.7 -m pytest -v
On Linux or macOS:
```
#### Linux\Mac
.../debugpy$ python3 -m tox
```
~: git clone https://github.com/Microsoft/ptvsd
~: cd ptvsd
~/ptvsd: python3 -m pip install -r ./test_requirements.txt
~/ptvsd: python3 -m pytest -v
This will perform a full run with the default settings. A full run will run tests on Python 2.7 and 3.5-3.8, and requires all of those to be installed. If some versions are missing, or it is desired to skip them for a particular run, tox can be directed to only run tests on specific versions with `-e`. In addition, the `--developer` option can be used to skip the packaging step, running tests directly against the source code in `src/debugpy`. This should only be used when iterating on the code, and a proper run should be performed before submitting a PR. On Windows:
```
...\debugpy> py -m tox -e py27,py37 --develop
```
On Linux or macOS:
```
.../debugpy$ python3 -m tox -e py27,py37 --develop
```

### Running tests without tox

While tox is the recommended way to run the test suite, pytest can also be invoked directly from the root of the repository. This requires packages in tests/test_requirements.txt to be installed first.

## Using modified debugpy in Visual Studio Code
To test integration between debugpy and Visual Studio Code, the latter can be directed to use a custom version of debugpy in lieu of the one bundled with the Python extension. This is done by specifying `"debugAdapterPath"` in `launch.json` - it must point at the root directory of the *package*, which is `src/debugpy` inside the repository:

### Debug in VSC using development version
Set `PYTHONPATH` to point to cloned version of ptvsd, in `launch.json`, to debug any python project to test the debugger you are working on:
```json
```json5
{
"name": "Terminal (integrated)",
"type": "python",
"request": "launch",
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"env": {"PYTHONPATH":"C:\\GIT\\ptvsd"},
"internalConsoleOptions": "neverOpen",
},
"debugAdapterPath": ".../debugpy/src/debugpy",
...
}
```
4 changes: 2 additions & 2 deletions DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
The Python Visual Studio Debugger engine implements the Visual Studio Code debug protocol and is used as the debug engine in Visual Studio and Visual Studio Code.
debugpy is an implementation of the Debug Adapter Protocol for Python.

The source code and the issue tracker is [hosted on GitHub](https://github.com/Microsoft/ptvsd/).
The source code and the issue tracker is [hosted on GitHub](https://github.com/microsoft/debugpy/).
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ptvsd
debugpy

Copyright (c) Microsoft Corporation
All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ include LICENSE
include DESCRIPTION.md
global-exclude *.py[cdo]
include versioneer.py
include src/ptvsd/_version.py
include src/debugpy/_version.py
72 changes: 36 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
# Python Tools for Visual Studio debug server
# debugpy - a debugger for Python

[![Build Status](https://ptvsd.visualstudio.com/_apis/public/build/definitions/557bd35a-f98d-4c49-9bc9-c7d548f78e4d/1/badge)](https://ptvsd.visualstudio.com/ptvsd/ptvsd%20Team/_build/index?definitionId=1)
[![Build Status](https://travis-ci.org/Microsoft/ptvsd.svg?branch=master)](https://travis-ci.org/Microsoft/ptvsd)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=microsoft_ptvsd&metric=coverage)](https://sonarcloud.io/dashboard?id=microsoft_ptvsd)
[![GitHub](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://raw.githubusercontent.com/Microsoft/ptvsd/master/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/ptvsd.svg)](https://pypi.org/project/ptvsd/)
[![PyPI](https://img.shields.io/pypi/pyversions/ptvsd.svg)](https://pypi.org/project/ptvsd/)
[![Build Status](https://travis-ci.org/microsoft/debugpy.svg?branch=master)](https://travis-ci.org/microsoft/debugpy)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=microsoft_debugpy&metric=coverage)](https://sonarcloud.io/dashboard?id=microsoft_debugpy)
[![GitHub](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://raw.githubusercontent.com/microsoft/debugpy/master/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/debugpy.svg)](https://pypi.org/project/debugpy/)
[![PyPI](https://img.shields.io/pypi/pyversions/debugpy.svg)](https://pypi.org/project/debugpy/)

This debugger is based on the Debug Adapter Protocol for VS Code: [debugProtocol.json](https://github.com/Microsoft/vscode-debugadapter-node/blob/master/debugProtocol.json)
This debugger implements the Debug Adapter Protocol: [debugProtocol.json](https://github.com/Microsoft/vscode-debugadapter-node/blob/master/debugProtocol.json)

## `ptvsd` CLI Usage
## `debugpy` CLI Usage
### Debugging a script file
To run a script file with debugging enabled, but without waiting for the debugger to attach (i.e. code starts executing immediately):
To run a script file with debugging enabled, but without waiting for the IDE to attach (i.e. code starts executing immediately):
```console
-m ptvsd --host localhost --port 5678 myfile.py
-m debugpy --host localhost --port 5678 myfile.py
```
To wait until the debugger attaches before running your code, use the `--wait` switch.
To wait until the IDE attaches before running your code, use the `--wait` switch.
```console
-m ptvsd --host localhost --port 5678 --wait myfile.py
-m debugpy --host localhost --port 5678 --wait myfile.py
```
The `--host` option specifies the interface on which the debug server is listening for connections. To be able to attach from another machine, make sure that the server is listening on a public interface - using `0.0.0.0` will make it listen on all available interfaces:
```console
-m ptvsd --host 0.0.0.0 --port 5678 myfile.py
-m debugpy --host 0.0.0.0 --port 5678 myfile.py
```
This should only be done on secure networks, since anyone who can connect to the specified port can then execute arbitrary code within the debugged process.

To pass arguments to the script, just specify them after the filename. This works the same as with Python itself - everything up to the filename is processed by ptvsd, but everything after that becomes `sys.argv` of the running process.
To pass arguments to the script, just specify them after the filename. This works the same as with Python itself - everything up to the filename is processed by debugpy, but everything after that becomes `sys.argv` of the running process.

### Debugging a module
To run a module, use the `-m` switch instead of filename:
```console
-m ptvsd --host localhost --port 5678 -m mymodule
-m debugpy --host localhost --port 5678 -m mymodule
```
Same as with scripts, command line arguments can be passed to the module by specifying them after the module name. All other ptvsd switches work identically in this mode; in particular, `--wait` can be used to block execution until the debugger attaches.
Same as with scripts, command line arguments can be passed to the module by specifying them after the module name. All other debugpy switches work identically in this mode; in particular, `--wait` can be used to block execution until the IDE attaches.

### Attaching to a running process by ID
The following command injects the debugger into a process with a given PID that is running Python code. Once the command returns, a ptvsd server is running within the process, as if that process was launched via `-m ptvsd` itself.
The following command injects the debugger into a process with a given PID that is running Python code. Once the command returns, a debugpy server is running within the process, as if that process was launched via `-m debugpy` itself.
```console
-m ptvsd --host localhost --port 5678 --pid 12345
-m debugpy --host localhost --port 5678 --pid 12345
```

## `ptvsd` Import usage
## `debugpy` Import usage
### Enabling debugging
At the beginning of your script, import ptvsd, and call `ptvsd.enable_attach()` to start the debug server. The default hostname is `0.0.0.0`, and the default port is 5678; these can be overridden by passing a `(host, port)` tuple as the first argument of `enable_attach()`.
At the beginning of your script, import debugpy, and call `debugpy.enable_attach()` to start the debug server. The default hostname is `0.0.0.0`, and the default port is 5678; these can be overridden by passing a `(host, port)` tuple as the first argument of `enable_attach()`.
```python
import ptvsd
ptvsd.enable_attach()
import debugpy
debugpy.enable_attach()
...
```

### Waiting for the debugger to attach
Use the `ptvsd.wait_for_attach()` function to block program execution until the debugger is attached.
### Waiting for the IDE to attach
Use the `debugpy.wait_for_attach()` function to block program execution until the IDE is attached.
```python
import ptvsd
ptvsd.enable_attach()
ptvsd.wait_for_attach() # blocks execution until debugger is attached
import debugpy
debugpy.enable_attach()
debugpy.wait_for_attach() # blocks execution until IDE is attached
...
```

### `breakpoint()` function
In Python 3.7 and above, `ptvsd` supports the standard `breakpoint()` function. Use `ptvsd.break_into_debugger()` function for similar behavior and compatibility with older versions of Python (3.6 and below). If the debugger is attached when either of these functions is invoked, it will pause execution on the calling line, as if it had a breakpoint set. If there's no debugger attached, the functions do nothing, and the code continues to execute normally.
In Python 3.7 and above, `debugpy` supports the standard `breakpoint()` function. Use `debugpy.break_into_debugger()` function for similar behavior and compatibility with older versions of Python (3.6 and below). If the debugger is attached when either of these functions is invoked, it will pause execution on the calling line, as if it had a breakpoint set. If there's no IDE attached, the functions do nothing, and the code continues to execute normally.
```python
import ptvsd
ptvsd.enable_attach()
import debugpy
debugpy.enable_attach()

while True:
...
breakpoint() # or ptvsd.break_into_debugger() on <3.7
breakpoint() # or debugpy.break_into_debugger() on <3.7
...
```

Expand Down Expand Up @@ -103,7 +103,7 @@ while True:
],
"pathMappings": [
{
"localRoot": "C:\\Project\\src", // Local root (where source and debugger running)
"localRoot": "C:\\Project\\src", // Local root (where the IDE is running)
"remoteRoot": "/home/smith/proj" // Remote root (where remote code is running)
},
// Add more path mappings
Expand All @@ -115,15 +115,15 @@ while True:

To enable debugger internal logging via CLI, the `--log-dir` switch can be used:
```console
-m ptvsd --log-dir path/to/logs ...
-m debugpy --log-dir path/to/logs ...
```

When using `enable_attach`, the same can be done with `log_dir` argument:
```py
ptvsd.enable_attach(log_dir='path/to/logs')
debugpy.enable_attach(log_dir='path/to/logs')
```

In both cases, the environment variable `PTVSD_LOG_DIR` can also be set to the same effect.
In both cases, the environment variable `DEBUGPY_LOG_DIR` can also be set to the same effect.

When logging is enabled, ptvsd will create a log file with a name `ptvsd-<pid>.log` in the specified directory, where `<pid>` is the ID of the process being debugged. When subprocess debugging is enabled, a separate log is created for every subprocess.
When logging is enabled, debugpy will create several log files with names matching `debugpy*.log` in the specified directory, corresponding to different components of the debugger. When subprocess debugging is enabled, separate logs are created for every subprocess.

41 changes: 41 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.3 BLOCK -->

## Security

Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).

If you believe you have found a security vulnerability in any Microsoft-owned repository that meets Microsoft's [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)) of a security vulnerability, please report it to us as described below.

## Reporting Security Issues

**Please do not report security vulnerabilities through public GitHub issues.**

Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).

If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).

You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).

Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:

* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
* Full paths of source file(s) related to the manifestation of the issue
* The location of the affected source code (tag/branch/commit or direct URL)
* Any special configuration required to reproduce the issue
* Step-by-step instructions to reproduce the issue
* Proof-of-concept or exploit code (if possible)
* Impact of the issue, including how an attacker might exploit the issue

This information will help us triage your report more quickly.

If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs.

## Preferred Languages

We prefer all communications to be in English.

## Policy

Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).

<!-- END MICROSOFT SECURITY.MD BLOCK -->
Loading

0 comments on commit 8b4c40e

Please sign in to comment.