Skip to content

Commit 4c78f3b

Browse files
karthiknadigKartik Raj
and
Kartik Raj
authored
Cherry picks and version updates for bug fix release (#11878)
* Do not execute shebang as an interpreter until user has clicked on the codelens enclosing the shebang (#11816) * Do not execute shebang as an interpreter until user has clicked on the codelens enclosing the shebang * Rename * Oops * Update src/test/providers/shebangCodeLenseProvider.unit.test.ts Co-authored-by: Karthik Nadig <kanadig@microsoft.com> Co-authored-by: Karthik Nadig <kanadig@microsoft.com> * Update version and change log for bugfix release Co-authored-by: Kartik Raj <karraj@microsoft.com>
1 parent d1b7b8e commit 4c78f3b

File tree

7 files changed

+100
-13
lines changed

7 files changed

+100
-13
lines changed

CHANGELOG.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
# Changelog
22

3+
## 2020.5.1 (19 May 2020)
4+
5+
### Fixes
6+
7+
1. Do not execute shebang as an interpreter until user has clicked on the codelens enclosing the shebang.
8+
([#11687](https://github.com/Microsoft/vscode-python/issues/11687))
9+
10+
### Thanks
11+
12+
Thanks to the following projects which we fully rely on to provide some of
13+
our features:
14+
15+
- [debugpy](https://pypi.org/project/debugpy/)
16+
- [isort](https://pypi.org/project/isort/)
17+
- [jedi](https://pypi.org/project/jedi/)
18+
and [parso](https://pypi.org/project/parso/)
19+
- [Microsoft Python Language Server](https://github.com/microsoft/python-language-server)
20+
- [ptvsd](https://pypi.org/project/ptvsd/)
21+
- [exuberant ctags](http://ctags.sourceforge.net/) (user-installed)
22+
- [rope](https://pypi.org/project/rope/) (user-installed)
23+
24+
Also thanks to the various projects we provide integrations with which help
25+
make this extension useful:
26+
27+
- Debugging support:
28+
[Django](https://pypi.org/project/Django/),
29+
[Flask](https://pypi.org/project/Flask/),
30+
[gevent](https://pypi.org/project/gevent/),
31+
[Jinja](https://pypi.org/project/Jinja/),
32+
[Pyramid](https://pypi.org/project/pyramid/),
33+
[PySpark](https://pypi.org/project/pyspark/),
34+
[Scrapy](https://pypi.org/project/Scrapy/),
35+
[Watson](https://pypi.org/project/Watson/)
36+
- Formatting:
37+
[autopep8](https://pypi.org/project/autopep8/),
38+
[black](https://pypi.org/project/black/),
39+
[yapf](https://pypi.org/project/yapf/)
40+
- Interpreter support:
41+
[conda](https://conda.io/),
42+
[direnv](https://direnv.net/),
43+
[pipenv](https://pypi.org/project/pipenv/),
44+
[pyenv](https://github.com/pyenv/pyenv),
45+
[venv](https://docs.python.org/3/library/venv.html#module-venv),
46+
[virtualenv](https://pypi.org/project/virtualenv/)
47+
- Linting:
48+
[bandit](https://pypi.org/project/bandit/),
49+
[flake8](https://pypi.org/project/flake8/),
50+
[mypy](https://pypi.org/project/mypy/),
51+
[prospector](https://pypi.org/project/prospector/),
52+
[pylint](https://pypi.org/project/pylint/),
53+
[pydocstyle](https://pypi.org/project/pydocstyle/),
54+
[pylama](https://pypi.org/project/pylama/)
55+
- Testing:
56+
[nose](https://pypi.org/project/nose/),
57+
[pytest](https://pypi.org/project/pytest/),
58+
[unittest](https://docs.python.org/3/library/unittest.html#module-unittest)
59+
60+
And finally thanks to the [Python](https://www.python.org/) development team and
61+
community for creating a fantastic programming language and community to be a
62+
part of!
63+
364
## 2020.5.0 (12 May 2020)
465

566
### Enhancements

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "python",
33
"displayName": "Python",
44
"description": "Linting, Debugging (multi-threaded, remote), Intellisense, Jupyter Notebooks, code formatting, refactoring, unit tests, snippets, and more.",
5-
"version": "2020.5.0",
5+
"version": "2020.5.1",
66
"featureFlags": {
77
"usingNewInterpreterStorage": true
88
},

src/client/interpreter/configuration/interpreterSelector/commands/setShebangInterpreter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export class SetShebangInterpreterCommand extends BaseInterpreterSelectorCommand
3737

3838
protected async setShebangInterpreter(): Promise<void> {
3939
const shebang = await this.shebangCodeLensProvider.detectShebang(
40-
this.documentManager.activeTextEditor!.document
40+
this.documentManager.activeTextEditor!.document,
41+
true
4142
);
4243
if (!shebang) {
4344
return;

src/client/interpreter/contracts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export interface IInterpreterDisplay {
114114

115115
export const IShebangCodeLensProvider = Symbol('IShebangCodeLensProvider');
116116
export interface IShebangCodeLensProvider extends CodeLensProvider {
117-
detectShebang(document: TextDocument): Promise<string | undefined>;
117+
detectShebang(document: TextDocument, resolveShebangAsInterpreter?: boolean): Promise<string | undefined>;
118118
}
119119

120120
export const IInterpreterHelper = Symbol('IInterpreterHelper');

src/client/interpreter/display/shebangCodeLensProvider.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export class ShebangCodeLensProvider implements IShebangCodeLensProvider {
1919
// tslint:disable-next-line:no-any
2020
this.onDidChangeCodeLenses = (workspaceService.onDidChangeConfiguration as any) as Event<void>;
2121
}
22-
public async detectShebang(document: TextDocument): Promise<string | undefined> {
22+
public async detectShebang(
23+
document: TextDocument,
24+
resolveShebangAsInterpreter: boolean = false
25+
): Promise<string | undefined> {
2326
const firstLine = document.lineAt(0);
2427
if (firstLine.isEmptyOrWhitespace) {
2528
return;
@@ -30,8 +33,12 @@ export class ShebangCodeLensProvider implements IShebangCodeLensProvider {
3033
}
3134

3235
const shebang = firstLine.text.substr(2).trim();
33-
const pythonPath = await this.getFullyQualifiedPathToInterpreter(shebang, document.uri);
34-
return typeof pythonPath === 'string' && pythonPath.length > 0 ? pythonPath : undefined;
36+
if (resolveShebangAsInterpreter) {
37+
const pythonPath = await this.getFullyQualifiedPathToInterpreter(shebang, document.uri);
38+
return typeof pythonPath === 'string' && pythonPath.length > 0 ? pythonPath : undefined;
39+
} else {
40+
return typeof shebang === 'string' && shebang.length > 0 ? shebang : undefined;
41+
}
3542
}
3643
public async provideCodeLenses(document: TextDocument, _token?: CancellationToken): Promise<CodeLens[]> {
3744
return this.createShebangCodeLens(document);

src/test/providers/shebangCodeLenseProvider.unit.test.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,33 @@ suite('Shebang detection', () => {
6363

6464
return [doc, line];
6565
}
66-
test('Shebang should be empty when first line is empty', async () => {
66+
test('Shebang should be empty when first line is empty when resolving shebang as interpreter', async () => {
6767
const [document, line] = createDocument('');
6868

69-
const shebang = await provider.detectShebang(document.object);
69+
const shebang = await provider.detectShebang(document.object, true);
7070

7171
document.verifyAll();
7272
line.verifyAll();
7373
expect(shebang).to.be.equal(undefined, 'Shebang should be undefined');
7474
});
75+
test('Shebang should be empty when first line is empty when not resolving shebang as interpreter', async () => {
76+
const [document, line] = createDocument('');
77+
78+
const shebang = await provider.detectShebang(document.object, false);
79+
80+
document.verifyAll();
81+
line.verifyAll();
82+
expect(shebang).to.be.equal(undefined, 'Shebang should be undefined');
83+
});
84+
test('Shebang should be returned as it is when not resolving shebang as interpreter', async () => {
85+
const [document, line] = createDocument('#!HELLO');
86+
87+
const shebang = await provider.detectShebang(document.object, false);
88+
89+
document.verifyAll();
90+
line.verifyAll();
91+
expect(shebang).to.be.equal('HELLO', 'Shebang should be HELLO');
92+
});
7593
test('Shebang should be empty when python path is invalid in shebang', async () => {
7694
const [document, line] = createDocument('#!HELLO');
7795

@@ -80,7 +98,7 @@ suite('Shebang detection', () => {
8098
.returns(() => Promise.reject())
8199
.verifiable(typemoq.Times.once());
82100

83-
const shebang = await provider.detectShebang(document.object);
101+
const shebang = await provider.detectShebang(document.object, true);
84102

85103
document.verifyAll();
86104
line.verifyAll();
@@ -95,7 +113,7 @@ suite('Shebang detection', () => {
95113
.returns(() => Promise.resolve({ stdout: 'THIS_IS_IT' }))
96114
.verifiable(typemoq.Times.once());
97115

98-
const shebang = await provider.detectShebang(document.object);
116+
const shebang = await provider.detectShebang(document.object, true);
99117

100118
document.verifyAll();
101119
line.verifyAll();
@@ -113,7 +131,7 @@ suite('Shebang detection', () => {
113131
.returns(() => Promise.resolve({ stdout: 'THIS_IS_IT' }))
114132
.verifiable(typemoq.Times.once());
115133

116-
const shebang = await provider.detectShebang(document.object);
134+
const shebang = await provider.detectShebang(document.object, true);
117135

118136
document.verifyAll();
119137
line.verifyAll();
@@ -132,7 +150,7 @@ suite('Shebang detection', () => {
132150
.returns(() => Promise.resolve({ stdout: 'THIS_IS_IT' }))
133151
.verifiable(typemoq.Times.once());
134152

135-
const shebang = await provider.detectShebang(document.object);
153+
const shebang = await provider.detectShebang(document.object, true);
136154

137155
document.verifyAll();
138156
line.verifyAll();

0 commit comments

Comments
 (0)