Skip to content

Commit f38f6e5

Browse files
author
Kartik Raj
authored
Add npm project for Python API (#21631)
For #20949
1 parent ea76858 commit f38f6e5

30 files changed

+728
-102
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pythonExtensionApi/out/
2+
13
# The following files were grandfathered out of eslint. They can be removed as time permits.
24

35
src/test/analysisEngineTest.ts

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ cucumber-report.json
2323
port.txt
2424
precommit.hook
2525
pythonFiles/lib/**
26+
pythonFiles/get_pip.py
2627
debug_coverage*/**
2728
languageServer/**
2829
languageServer.*/**

build/azure-pipelines/pipeline.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
###############################################################################################
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
###############################################################################################
5+
name: $(Date:yyyyMMdd)$(Rev:.r)
6+
7+
pr: none
8+
9+
resources:
10+
repositories:
11+
- repository: templates
12+
type: github
13+
name: microsoft/vscode-engineering
14+
ref: main
15+
endpoint: Monaco
16+
17+
parameters:
18+
- name: quality
19+
displayName: Quality
20+
type: string
21+
default: latest
22+
values:
23+
- latest
24+
- next
25+
- name: publishPythonApi
26+
displayName: 🚀 Publish pythonExtensionApi
27+
type: boolean
28+
default: false
29+
30+
extends:
31+
template: azure-pipelines/npm-package/pipeline.yml@templates
32+
parameters:
33+
npmPackages:
34+
- name: pythonExtensionApi
35+
testPlatforms:
36+
- name: Linux
37+
nodeVersions:
38+
- 16.17.1
39+
- name: MacOS
40+
nodeVersions:
41+
- 16.17.1
42+
- name: Windows
43+
nodeVersions:
44+
- 16.17.1
45+
testSteps:
46+
- template: /build/azure-pipelines/templates/test-steps.yml@self
47+
parameters:
48+
package: pythonExtensionApi
49+
buildSteps:
50+
- template: /build/azure-pipelines/templates/pack-steps.yml@self
51+
parameters:
52+
package: pythonExtensionApi
53+
ghTagPrefix: release/pythonExtensionApi/
54+
tag: ${{ parameters.quality }}
55+
publishPackage: ${{ parameters.publishPythonApi }}
56+
workingDirectory: $(Build.SourcesDirectory)/pythonExtensionApi
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
###############################################################################################
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
###############################################################################################
5+
parameters:
6+
- name: package
7+
8+
steps:
9+
- script: npm install --root-only
10+
workingDirectory: $(Build.SourcesDirectory)
11+
displayName: Install root dependencies
12+
- script: npm install
13+
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.package }}
14+
displayName: Install package dependencies
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
###############################################################################################
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
###############################################################################################
5+
parameters:
6+
- name: package
7+
type: string
8+
- name: script
9+
type: string
10+
default: 'all:publish'
11+
12+
steps:
13+
- script: npm install --root-only
14+
workingDirectory: $(Build.SourcesDirectory)
15+
displayName: Install root dependencies
16+
- bash: |
17+
/usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
18+
echo ">>> Started xvfb"
19+
displayName: Start xvfb
20+
condition: eq(variables['Agent.OS'], 'Linux')
21+
- script: npm run ${{ parameters.script }}
22+
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.package }}
23+
displayName: Verify package

build/fail.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
process.exitCode = 1;

gulpfile.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const tsProject = ts.createProject('./tsconfig.json', { typescript });
2727

2828
const isCI = process.env.TRAVIS === 'true' || process.env.TF_BUILD !== undefined;
2929

30-
gulp.task('compile', (done) => {
30+
gulp.task('compileCore', (done) => {
3131
let failed = false;
3232
tsProject
3333
.src()
@@ -39,6 +39,22 @@ gulp.task('compile', (done) => {
3939
.on('finish', () => (failed ? done(new Error('TypeScript compilation errors')) : done()));
4040
});
4141

42+
const apiTsProject = ts.createProject('./pythonExtensionApi/tsconfig.json', { typescript });
43+
44+
gulp.task('compileApi', (done) => {
45+
let failed = false;
46+
apiTsProject
47+
.src()
48+
.pipe(apiTsProject())
49+
.on('error', () => {
50+
failed = true;
51+
})
52+
.js.pipe(gulp.dest('./pythonExtensionApi/out'))
53+
.on('finish', () => (failed ? done(new Error('TypeScript compilation errors')) : done()));
54+
});
55+
56+
gulp.task('compile', gulp.series('compileCore', 'compileApi'));
57+
4258
gulp.task('precommit', (done) => run({ exitOnError: true, mode: 'staged' }, done));
4359

4460
gulp.task('output:clean', () => del(['coverage']));

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,8 +2064,8 @@
20642064
"testSmoke": "cross-env INSTALL_JUPYTER_EXTENSION=true \"node ./out/test/smokeTest.js\"",
20652065
"testInsiders": "cross-env VSC_PYTHON_CI_TEST_VSC_CHANNEL=insiders INSTALL_PYLANCE_EXTENSION=true TEST_FILES_SUFFIX=insiders.test CODE_TESTS_WORKSPACE=src/testMultiRootWkspc/smokeTests \"node ./out/test/standardTest.js\"",
20662066
"lint-staged": "node gulpfile.js",
2067-
"lint": "eslint --ext .ts,.js src build",
2068-
"lint-fix": "eslint --fix --ext .ts,.js src build gulpfile.js",
2067+
"lint": "eslint --ext .ts,.js src build pythonExtensionApi",
2068+
"lint-fix": "eslint --fix --ext .ts,.js src build pythonExtensionApi gulpfile.js",
20692069
"format-check": "prettier --check 'src/**/*.ts' 'build/**/*.js' '.github/**/*.yml' gulpfile.js",
20702070
"format-fix": "prettier --write 'src/**/*.ts' 'build/**/*.js' '.github/**/*.yml' gulpfile.js",
20712071
"clean": "gulp clean",

pythonExtensionApi/.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
example/**
2+
dist/
3+
out/**/*.map
4+
out/**/*.tsbuildInfo
5+
src/
6+
.eslintrc*
7+
.eslintignore
8+
tsconfig*.json

pythonExtensionApi/LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright (c) Microsoft Corporation. All rights reserved.
2+
3+
MIT License
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED _AS IS_, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

pythonExtensionApi/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Python extension's API
2+
3+
This npm module implements an API facade for the Python extension in VS Code.
4+
5+
## Example
6+
7+
The source code of the example can be found [here](TODO Update example extension link here)
8+
9+
First we need to define a `package.json` for the extension that wants to use the API:
10+
11+
```jsonc
12+
{
13+
"name": "...",
14+
...
15+
// depend on the Python extension
16+
"extensionDependencies": [
17+
"ms-python.python"
18+
],
19+
// Depend on the Python extension facade npm module to get easier API access to the
20+
// core extension.
21+
"dependencies": {
22+
"@vscode/python-extension": "..."
23+
},
24+
}
25+
```
26+
27+
TODO insert example here
28+
29+
```typescript
30+
TODO
31+
```

pythonExtensionApi/SECURITY.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.5 BLOCK -->
2+
3+
## Security
4+
5+
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/).
6+
7+
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below.
8+
9+
## Reporting Security Issues
10+
11+
**Please do not report security vulnerabilities through public GitHub issues.**
12+
13+
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report).
14+
15+
If you prefer to submit without logging in, send email to [[email protected]](mailto:[email protected]). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc).
16+
17+
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).
18+
19+
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:
20+
21+
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22+
* Full paths of source file(s) related to the manifestation of the issue
23+
* The location of the affected source code (tag/branch/commit or direct URL)
24+
* Any special configuration required to reproduce the issue
25+
* Step-by-step instructions to reproduce the issue
26+
* Proof-of-concept or exploit code (if possible)
27+
* Impact of the issue, including how an attacker might exploit the issue
28+
29+
This information will help us triage your report more quickly.
30+
31+
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.
32+
33+
## Preferred Languages
34+
35+
We prefer all communications to be in English.
36+
37+
## Policy
38+
39+
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd).
40+
41+
<!-- END MICROSOFT SECURITY.MD BLOCK -->

pythonExtensionApi/example/todo.txt

Whitespace-only changes.

pythonExtensionApi/package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pythonExtensionApi/package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "@vscode/python-extension",
3+
"description": "An API facade for the Python extension in VS Code",
4+
"version": "1.0.0",
5+
"author": {
6+
"name": "Microsoft Corporation"
7+
},
8+
"keywords": [
9+
"Python",
10+
"VSCode",
11+
"API"
12+
],
13+
"main": "./out/main.js",
14+
"types": "./out/main.d.ts",
15+
"engines": {
16+
"node": ">=16.17.1",
17+
"vscode": "^1.78.0"
18+
},
19+
"license": "MIT",
20+
"homepage": "https://github.com/Microsoft/vscode-python",
21+
"repository": {
22+
"type": "git",
23+
"url": "https://github.com/Microsoft/vscode-python"
24+
},
25+
"bugs": {
26+
"url": "https://github.com/Microsoft/vscode-python/issues"
27+
},
28+
"dependencies": {
29+
"@types/vscode": "^1.78.0"
30+
},
31+
"scripts": {
32+
"prepublishOnly": "echo \"⛔ Can only publish from a secure pipeline ⛔\" && node ../build/fail",
33+
"prepack": "npm run all:publish",
34+
"compile": "node ../node_modules/typescript/lib/tsc.js -b ./tsconfig.json",
35+
"clean": "node ../node_modules/rimraf/bin.js out",
36+
"lint": "node ../node_modules/eslint/bin/eslint.js --ext ts src",
37+
"all": "npm run clean && npm run compile",
38+
"all:publish": "git clean -xfd . && npm install && npm run compile"
39+
}
40+
}
File renamed without changes.

pythonExtensionApi/tsconfig.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"paths": {
5+
"*": ["types/*"]
6+
},
7+
"module": "commonjs",
8+
"target": "es2018",
9+
"outDir": "./out",
10+
"lib": [
11+
"es6",
12+
"es2018",
13+
"dom",
14+
"ES2019",
15+
"ES2020"
16+
],
17+
"sourceMap": true,
18+
"rootDir": "src",
19+
"experimentalDecorators": true,
20+
"allowSyntheticDefaultImports": true,
21+
"strict": true,
22+
"noImplicitAny": true,
23+
"noImplicitThis": true,
24+
"noUnusedLocals": true,
25+
"noUnusedParameters": true,
26+
"noFallthroughCasesInSwitch": true,
27+
"resolveJsonModule": true,
28+
"removeComments": true
29+
},
30+
"exclude": [
31+
"node_modules",
32+
"out"
33+
]
34+
}

src/client/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { BaseLanguageClient, LanguageClientOptions } from 'vscode-languageclient
1010
import { LanguageClient } from 'vscode-languageclient/node';
1111
import { PYLANCE_NAME } from './activation/node/languageClientFactory';
1212
import { ILanguageServerOutputChannel } from './activation/types';
13-
import { PythonExtension } from './api/main';
13+
import { PythonExtension } from './api/types';
1414
import { isTestExecution, PYTHON_LANGUAGE } from './common/constants';
1515
import { IConfigurationService, Resource } from './common/types';
1616
import { getDebugpyLauncherArgs, getDebugpyPackagePath } from './debugger/extension/adapter/remoteLaunchers';

0 commit comments

Comments
 (0)