-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from tiagovtristao/python-debugging
Python debugging
- Loading branch information
Showing
35 changed files
with
1,268 additions
and
514 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ plz-out | |
out | ||
node_modules | ||
*.vsix | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import ast | ||
import json | ||
import sys | ||
|
||
|
||
def get_rule_calls(build_filename): | ||
""" | ||
Returns a list of top-level rule calls. | ||
ie. [{'id': 'python_test', 'name': 'calc_test', 'line': 1}, ...] | ||
""" | ||
|
||
with open(build_filename) as f: | ||
read_data = f.read() | ||
|
||
module_ast = ast.parse(read_data) | ||
|
||
calls = [] | ||
for stmt in module_ast.body: | ||
if isinstance(stmt, ast.Expr) and isinstance(stmt.value, ast.Call) and isinstance(stmt.value.func, ast.Name): | ||
for kw in stmt.value.keywords: | ||
if kw.arg == 'name' and isinstance(kw.value, ast.Str): | ||
calls.append({ | ||
'id': stmt.value.func.id, | ||
'name': kw.value.s, | ||
'line': stmt.value.lineno, | ||
}) | ||
|
||
return calls | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) != 2: | ||
print("Error: A BUILD filename is required.") | ||
sys.exit(1) | ||
|
||
rule_calls = get_rule_calls(sys.argv[1]) | ||
print(json.dumps(rule_calls)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import ast | ||
import json | ||
import sys | ||
|
||
|
||
def get_test_functions(filename): | ||
""" | ||
Returns a list of test functions. | ||
ie. [{'id': 'test_empty_array', 'line': 1}, ...] | ||
""" | ||
|
||
with open(filename) as f: | ||
read_data = f.read() | ||
|
||
module_ast = ast.parse(read_data) | ||
|
||
funcs = [] | ||
for stmt in module_ast.body: | ||
if isinstance(stmt, ast.ClassDef): | ||
for base in stmt.bases: | ||
if isinstance(base, ast.Attribute) and base.attr == 'TestCase' and isinstance(base.value, ast.Name) and (base.value.id == 'unittest' or base.value.id == 'asynctest'): | ||
for inner_stmt in stmt.body: | ||
if (isinstance(inner_stmt, ast.FunctionDef) or isinstance(inner_stmt, ast.AsyncFunctionDef)) and inner_stmt.name.startswith('test'): | ||
funcs.append({ | ||
'id': inner_stmt.name, | ||
'line': inner_stmt.lineno, | ||
}) | ||
|
||
return funcs | ||
|
||
if __name__ == '__main__': | ||
if len(sys.argv) != 2: | ||
print("Error: A file is required.") | ||
sys.exit(1) | ||
|
||
test_functions = get_test_functions(sys.argv[1]) | ||
print(json.dumps(test_functions)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './plzCommand'; | ||
export * from './plzDebugDocumentCommand'; | ||
export * from './plzDebugTargetCommand'; | ||
export * from './plzTestDocumentCommand'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as plz from '../please'; | ||
|
||
import { argumentPrompt } from './utils'; | ||
|
||
export async function plzCommand(args: { | ||
command: string; | ||
args?: string[]; | ||
runtime?: boolean; | ||
}): Promise<void> { | ||
const { command, args: commandArgs = [], runtime = false } = args; | ||
|
||
let runtimeArgs: string | undefined; | ||
if (runtime) { | ||
runtimeArgs = await argumentPrompt({ | ||
key: `key-plz-${command}-${commandArgs.join('-')}`, | ||
}); | ||
// Terminate if `Escape` key was pressed. | ||
if (runtimeArgs === undefined) { | ||
return; | ||
} | ||
} | ||
|
||
let wholeCommand = [command, ...commandArgs]; | ||
if (runtimeArgs) { | ||
wholeCommand = [...wholeCommand, '--', ...runtimeArgs.split(' ')]; | ||
} | ||
|
||
plz.detachCommand(wholeCommand); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
import { Language } from '../languages/constants'; | ||
import { languageTargetDebuggers } from '../languages/debug'; | ||
|
||
import { retrieveInputFileTarget } from './utils'; | ||
|
||
export async function plzDebugDocumentCommand(args: { | ||
document: vscode.TextDocument; | ||
functionName?: string; | ||
language: Language; | ||
}): Promise<void> { | ||
try { | ||
if (vscode.debug.activeDebugSession) { | ||
throw new Error('Debug session has already been initialised'); | ||
} | ||
|
||
const { | ||
document: { fileName }, | ||
functionName, | ||
language, | ||
} = args; | ||
|
||
const debugTarget = languageTargetDebuggers[language]; | ||
if (!debugTarget) { | ||
throw new Error( | ||
`The following language has no debugging support yet: ${language}.` | ||
); | ||
} | ||
|
||
const target = await retrieveInputFileTarget(fileName); | ||
if (target === undefined) { | ||
return; | ||
} | ||
|
||
debugTarget(target, functionName ? [functionName] : []); | ||
} catch (e) { | ||
vscode.window.showErrorMessage(e.message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
import { Language } from '../languages/constants'; | ||
import { languageTargetDebuggers } from '../languages/debug'; | ||
|
||
import { argumentPrompt } from './utils'; | ||
|
||
export async function plzDebugTargetCommand(args: { | ||
target: string; | ||
language: Language; | ||
}): Promise<void> { | ||
try { | ||
if (vscode.debug.activeDebugSession) { | ||
throw new Error('Debug session has already been initialised'); | ||
} | ||
|
||
const debugTarget = languageTargetDebuggers[args.language]; | ||
if (!debugTarget) { | ||
throw new Error( | ||
`The following language has no debugging support yet: ${args.language}.` | ||
); | ||
} | ||
|
||
const runtimeArgs = await argumentPrompt({ | ||
key: `key-debug-${args.target}`, | ||
}); | ||
// Terminate if `Escape` key was pressed. | ||
if (runtimeArgs === undefined) { | ||
return; | ||
} | ||
|
||
debugTarget(args.target, runtimeArgs ? runtimeArgs.split(' ') : []); | ||
} catch (e) { | ||
vscode.window.showErrorMessage(e.message); | ||
} | ||
} |
Oops, something went wrong.