mirror of
https://github.com/RustyRaptor/python-task-provider.git
synced 2026-12-03 21:35:15 -07:00
initial project
This commit is contained in:
18 files changed
+2588
No files matched your search
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/naming-convention": "warn",
|
||||
"@typescript-eslint/semi": "warn",
|
||||
"curly": "warn",
|
||||
"eqeqeq": "warn",
|
||||
"no-throw-literal": "warn",
|
||||
"semi": "off"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
out
|
||||
dist
|
||||
node_modules
|
||||
.vscode-test/
|
||||
*.vsix
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"dbaeumer.vscode-eslint"
|
||||
]
|
||||
}
|
||||
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
// A launch configuration that compiles the extension and then opens it inside a new window
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Run Extension",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/out/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "${defaultBuildTask}"
|
||||
},
|
||||
{
|
||||
"name": "Extension Tests",
|
||||
"type": "extensionHost",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"--extensionDevelopmentPath=${workspaceFolder}",
|
||||
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
|
||||
],
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/out/test/**/*.js"
|
||||
],
|
||||
"preLaunchTask": "${defaultBuildTask}"
|
||||
}
|
||||
]
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// Place your settings in this file to overwrite default and user settings.
|
||||
{
|
||||
"files.exclude": {
|
||||
"out": false // set this to true to hide the "out" folder with the compiled JS files
|
||||
},
|
||||
"search.exclude": {
|
||||
"out": true // set this to false to include "out" folder in search results
|
||||
},
|
||||
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
|
||||
"typescript.tsc.autoDetect": "off"
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "watch",
|
||||
"problemMatcher": "$tsc-watch",
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "never"
|
||||
},
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
.vscode/**
|
||||
.vscode-test/**
|
||||
out/test/**
|
||||
src/**
|
||||
.gitignore
|
||||
.yarnrc
|
||||
vsc-extension-quickstart.md
|
||||
**/tsconfig.json
|
||||
**/.eslintrc.json
|
||||
**/*.map
|
||||
**/*.ts
|
||||
@@ -0,0 +1,9 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to the "python-task-provider" extension will be documented in this file.
|
||||
|
||||
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- Initial release
|
||||
@@ -0,0 +1,10 @@
|
||||
# python-task-provider
|
||||
|
||||
An extension for VS Code that provides tasks to the VS Code Task system for Python applications.
|
||||
|
||||
|
||||
## Setuptools Task Provider
|
||||
|
||||
Automatically discovers available commands for setuptools (`setup.py`) and exposes them to the **Run Task** command:
|
||||
|
||||
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 194 KiB |
Generated
+2113
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,57 @@
|
||||
{
|
||||
"name": "python-task-provider",
|
||||
"displayName": "Python task provider",
|
||||
"description": "Provide tasks for common Python code snippets into the VS Code tasks API",
|
||||
"version": "0.0.1",
|
||||
"engines": {
|
||||
"vscode": "^1.52.0"
|
||||
},
|
||||
"categories": [
|
||||
"Other"
|
||||
],
|
||||
"activationEvents": [
|
||||
"onCommand:workbench.action.tasks.runTask"
|
||||
],
|
||||
"main": "./out/extension.js",
|
||||
"contributes": {
|
||||
"taskDefinitions": [
|
||||
{
|
||||
"type": "setuptools",
|
||||
"required": [
|
||||
"task"
|
||||
],
|
||||
"properties": {
|
||||
"task": {
|
||||
"type": "string",
|
||||
"description": "The setuptools command to customize"
|
||||
},
|
||||
"file": {
|
||||
"type": "string",
|
||||
"description": "The setup.py file path that provides the command. Can be omitted."
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"vscode:prepublish": "npm run compile",
|
||||
"compile": "tsc -p ./",
|
||||
"watch": "tsc -watch -p ./",
|
||||
"pretest": "npm run compile && npm run lint",
|
||||
"lint": "eslint src --ext ts",
|
||||
"test": "node ./out/test/runTest.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/vscode": "^1.52.0",
|
||||
"@types/glob": "^7.1.3",
|
||||
"@types/mocha": "^8.0.0",
|
||||
"@types/node": "^12.11.7",
|
||||
"eslint": "^7.9.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.1.1",
|
||||
"@typescript-eslint/parser": "^4.1.1",
|
||||
"glob": "^7.1.6",
|
||||
"mocha": "^8.1.3",
|
||||
"typescript": "^4.0.2",
|
||||
"vscode-test": "^1.4.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { SetupToolsTaskProvider } from './setupToolsTaskProvider';
|
||||
|
||||
let setupToolsProvider: vscode.Disposable | undefined;
|
||||
|
||||
export function activate(_context: vscode.ExtensionContext): void {
|
||||
const workspaceRoots = vscode.workspace.workspaceFolders;
|
||||
if (!workspaceRoots) {
|
||||
return;
|
||||
}
|
||||
|
||||
setupToolsProvider = vscode.tasks.registerTaskProvider(SetupToolsTaskProvider.SetupToolsType, new SetupToolsTaskProvider());
|
||||
|
||||
}
|
||||
|
||||
export function deactivate(): void {
|
||||
if (setupToolsProvider) {
|
||||
setupToolsProvider.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as cp from 'child_process';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export class SetupToolsTaskProvider implements vscode.TaskProvider {
|
||||
static SetupToolsType = 'setuptools';
|
||||
private setuptoolsPromise: Thenable<vscode.Task[]> | undefined = undefined;
|
||||
|
||||
constructor() {
|
||||
if (!vscode.workspace.workspaceFolders) {
|
||||
return;
|
||||
}
|
||||
vscode.workspace.workspaceFolders.forEach(workspaceRoot => {
|
||||
const pattern = path.join(workspaceRoot.uri.fsPath, 'setup.py');
|
||||
const fileWatcher = vscode.workspace.createFileSystemWatcher(pattern);
|
||||
fileWatcher.onDidChange(() => this.setuptoolsPromise = undefined);
|
||||
fileWatcher.onDidCreate(() => this.setuptoolsPromise = undefined);
|
||||
fileWatcher.onDidDelete(() => this.setuptoolsPromise = undefined);
|
||||
});
|
||||
}
|
||||
|
||||
public provideTasks(): Thenable<vscode.Task[]> | undefined {
|
||||
if (!this.setuptoolsPromise) {
|
||||
this.setuptoolsPromise = getSetupToolsTasks();
|
||||
}
|
||||
return this.setuptoolsPromise;
|
||||
}
|
||||
|
||||
public resolveTask(_task: vscode.Task): vscode.Task | undefined {
|
||||
const task = _task.definition.task;
|
||||
|
||||
if (task) {
|
||||
// resolveTask requires that the same definition object be used.
|
||||
const definition: SetupToolsTaskDefinition = <any>_task.definition;
|
||||
return new vscode.Task(definition, _task.scope ?? vscode.TaskScope.Workspace, definition.task, 'setuptools', new vscode.ShellExecution(`python ${definition.task}`));
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function exists(file: string): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, _reject) => {
|
||||
fs.exists(file, (value) => {
|
||||
resolve(value);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function exec(command: string, options: cp.ExecOptions): Promise<{ stdout: string; stderr: string }> {
|
||||
return new Promise<{ stdout: string; stderr: string }>((resolve, reject) => {
|
||||
cp.exec(command, options, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject({ error, stdout, stderr });
|
||||
}
|
||||
resolve({ stdout, stderr });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
let _channel: vscode.OutputChannel;
|
||||
function getOutputChannel(): vscode.OutputChannel {
|
||||
if (!_channel) {
|
||||
_channel = vscode.window.createOutputChannel('Setuptools Auto Detection');
|
||||
}
|
||||
return _channel;
|
||||
}
|
||||
|
||||
interface SetupToolsTaskDefinition extends vscode.TaskDefinition {
|
||||
/**
|
||||
* The task name
|
||||
*/
|
||||
task: string;
|
||||
|
||||
/**
|
||||
* The python file containing the task
|
||||
*/
|
||||
file?: string;
|
||||
}
|
||||
|
||||
const buildNames: string[] = ['bdist', 'bdist_wheel', 'sdist', 'build'];
|
||||
function isBuildTask(name: string): boolean {
|
||||
for (const buildName of buildNames) {
|
||||
if (name.indexOf(buildName) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const testNames: string[] = ['test'];
|
||||
function isTestTask(name: string): boolean {
|
||||
for (const testName of testNames) {
|
||||
if (name.indexOf(testName) !== -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function getSetupToolsTasks(): Promise<vscode.Task[]> {
|
||||
const workspaceFolders = vscode.workspace.workspaceFolders;
|
||||
const result: vscode.Task[] = [];
|
||||
if (!workspaceFolders || workspaceFolders.length === 0) {
|
||||
return result;
|
||||
}
|
||||
for (const workspaceFolder of workspaceFolders) {
|
||||
const folderString = workspaceFolder.uri.fsPath;
|
||||
if (!folderString) {
|
||||
continue;
|
||||
}
|
||||
const setupPyFile = path.join(folderString, 'setup.py');
|
||||
if (!await exists(setupPyFile)) {
|
||||
continue;
|
||||
}
|
||||
var pythonPath = vscode.workspace.getConfiguration('python').get('pythonPath');
|
||||
if (!pythonPath){
|
||||
pythonPath = 'python';
|
||||
}
|
||||
const commandLine = `${pythonPath} setup.py --help-commands`;
|
||||
var isStandardCommands = false;
|
||||
var isExtraCommands = false;
|
||||
try {
|
||||
const { stdout, stderr } = await exec(commandLine, { cwd: folderString });
|
||||
if (stderr && stderr.length > 0) {
|
||||
getOutputChannel().appendLine(stderr);
|
||||
getOutputChannel().show(true);
|
||||
}
|
||||
if (stdout) {
|
||||
const lines = stdout.split(/\r{0,1}\n/);
|
||||
for (const line of lines) {
|
||||
if (line.length === 0) {
|
||||
isStandardCommands = false;
|
||||
isExtraCommands = false;
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith("Standard commands:")){
|
||||
isStandardCommands = true;
|
||||
continue;
|
||||
}
|
||||
if (line.startsWith("Extra commands:")){
|
||||
isExtraCommands = true;
|
||||
continue;
|
||||
}
|
||||
if (isStandardCommands || isExtraCommands){
|
||||
const taskName = line.trim().split(" ")[0];
|
||||
const kind: SetupToolsTaskDefinition = {
|
||||
type: 'setuptools',
|
||||
task: taskName
|
||||
};
|
||||
const task = new vscode.Task(kind, workspaceFolder, taskName, 'setuptools', new vscode.ShellExecution(`${pythonPath} setup.py ${taskName}`));
|
||||
result.push(task);
|
||||
const lowerCaseLine = line.toLowerCase();
|
||||
if (isBuildTask(lowerCaseLine)) {
|
||||
task.group = vscode.TaskGroup.Build;
|
||||
} else if (isTestTask(lowerCaseLine)) {
|
||||
task.group = vscode.TaskGroup.Test;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
const channel = getOutputChannel();
|
||||
if (err.stderr) {
|
||||
channel.appendLine(err.stderr);
|
||||
}
|
||||
if (err.stdout) {
|
||||
channel.appendLine(err.stdout);
|
||||
}
|
||||
channel.appendLine('Auto detecting setup.py commands failed.');
|
||||
channel.show(true);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import * as path from 'path';
|
||||
|
||||
import { runTests } from 'vscode-test';
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// The folder containing the Extension Manifest package.json
|
||||
// Passed to `--extensionDevelopmentPath`
|
||||
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
|
||||
|
||||
// The path to test runner
|
||||
// Passed to --extensionTestsPath
|
||||
const extensionTestsPath = path.resolve(__dirname, './suite/index');
|
||||
|
||||
// Download VS Code, unzip it and run the integration test
|
||||
await runTests({ extensionDevelopmentPath, extensionTestsPath });
|
||||
} catch (err) {
|
||||
console.error('Failed to run tests');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -0,0 +1,15 @@
|
||||
import * as assert from 'assert';
|
||||
|
||||
// You can import and use all API from the 'vscode' module
|
||||
// as well as import your extension to test it
|
||||
import * as vscode from 'vscode';
|
||||
// import * as myExtension from '../../extension';
|
||||
|
||||
suite('Extension Test Suite', () => {
|
||||
vscode.window.showInformationMessage('Start all tests.');
|
||||
|
||||
test('Sample test', () => {
|
||||
assert.equal(-1, [1, 2, 3].indexOf(5));
|
||||
assert.equal(-1, [1, 2, 3].indexOf(0));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
import * as path from 'path';
|
||||
import * as Mocha from 'mocha';
|
||||
import * as glob from 'glob';
|
||||
|
||||
export function run(): Promise<void> {
|
||||
// Create the mocha test
|
||||
const mocha = new Mocha({
|
||||
ui: 'tdd',
|
||||
color: true
|
||||
});
|
||||
|
||||
const testsRoot = path.resolve(__dirname, '..');
|
||||
|
||||
return new Promise((c, e) => {
|
||||
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
|
||||
if (err) {
|
||||
return e(err);
|
||||
}
|
||||
|
||||
// Add files to the test suite
|
||||
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
|
||||
|
||||
try {
|
||||
// Run the mocha test
|
||||
mocha.run(failures => {
|
||||
if (failures > 0) {
|
||||
e(new Error(`${failures} tests failed.`));
|
||||
} else {
|
||||
c();
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
e(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"outDir": "out",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"sourceMap": true,
|
||||
"rootDir": "src",
|
||||
"strict": true /* enable all strict type-checking options */
|
||||
/* Additional Checks */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
".vscode-test"
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user