Skip to content

Commit

Permalink
Cherry picks and version updates for bug fix release (#11878)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
karthiknadig and Kartik Raj committed May 19, 2020
1 parent d1b7b8e commit 4c78f3b
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 13 deletions.
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
# Changelog

## 2020.5.1 (19 May 2020)

### Fixes

1. Do not execute shebang as an interpreter until user has clicked on the codelens enclosing the shebang.
([#11687](https://github.com/Microsoft/vscode-python/issues/11687))

### Thanks

Thanks to the following projects which we fully rely on to provide some of
our features:

- [debugpy](https://pypi.org/project/debugpy/)
- [isort](https://pypi.org/project/isort/)
- [jedi](https://pypi.org/project/jedi/)
and [parso](https://pypi.org/project/parso/)
- [Microsoft Python Language Server](https://github.com/microsoft/python-language-server)
- [ptvsd](https://pypi.org/project/ptvsd/)
- [exuberant ctags](http://ctags.sourceforge.net/) (user-installed)
- [rope](https://pypi.org/project/rope/) (user-installed)

Also thanks to the various projects we provide integrations with which help
make this extension useful:

- Debugging support:
[Django](https://pypi.org/project/Django/),
[Flask](https://pypi.org/project/Flask/),
[gevent](https://pypi.org/project/gevent/),
[Jinja](https://pypi.org/project/Jinja/),
[Pyramid](https://pypi.org/project/pyramid/),
[PySpark](https://pypi.org/project/pyspark/),
[Scrapy](https://pypi.org/project/Scrapy/),
[Watson](https://pypi.org/project/Watson/)
- Formatting:
[autopep8](https://pypi.org/project/autopep8/),
[black](https://pypi.org/project/black/),
[yapf](https://pypi.org/project/yapf/)
- Interpreter support:
[conda](https://conda.io/),
[direnv](https://direnv.net/),
[pipenv](https://pypi.org/project/pipenv/),
[pyenv](https://github.com/pyenv/pyenv),
[venv](https://docs.python.org/3/library/venv.html#module-venv),
[virtualenv](https://pypi.org/project/virtualenv/)
- Linting:
[bandit](https://pypi.org/project/bandit/),
[flake8](https://pypi.org/project/flake8/),
[mypy](https://pypi.org/project/mypy/),
[prospector](https://pypi.org/project/prospector/),
[pylint](https://pypi.org/project/pylint/),
[pydocstyle](https://pypi.org/project/pydocstyle/),
[pylama](https://pypi.org/project/pylama/)
- Testing:
[nose](https://pypi.org/project/nose/),
[pytest](https://pypi.org/project/pytest/),
[unittest](https://docs.python.org/3/library/unittest.html#module-unittest)

And finally thanks to the [Python](https://www.python.org/) development team and
community for creating a fantastic programming language and community to be a
part of!

## 2020.5.0 (12 May 2020)

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "python",
"displayName": "Python",
"description": "Linting, Debugging (multi-threaded, remote), Intellisense, Jupyter Notebooks, code formatting, refactoring, unit tests, snippets, and more.",
"version": "2020.5.0",
"version": "2020.5.1",
"featureFlags": {
"usingNewInterpreterStorage": true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export class SetShebangInterpreterCommand extends BaseInterpreterSelectorCommand

protected async setShebangInterpreter(): Promise<void> {
const shebang = await this.shebangCodeLensProvider.detectShebang(
this.documentManager.activeTextEditor!.document
this.documentManager.activeTextEditor!.document,
true
);
if (!shebang) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/client/interpreter/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export interface IInterpreterDisplay {

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

export const IInterpreterHelper = Symbol('IInterpreterHelper');
Expand Down
13 changes: 10 additions & 3 deletions src/client/interpreter/display/shebangCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ export class ShebangCodeLensProvider implements IShebangCodeLensProvider {
// tslint:disable-next-line:no-any
this.onDidChangeCodeLenses = (workspaceService.onDidChangeConfiguration as any) as Event<void>;
}
public async detectShebang(document: TextDocument): Promise<string | undefined> {
public async detectShebang(
document: TextDocument,
resolveShebangAsInterpreter: boolean = false
): Promise<string | undefined> {
const firstLine = document.lineAt(0);
if (firstLine.isEmptyOrWhitespace) {
return;
Expand All @@ -30,8 +33,12 @@ export class ShebangCodeLensProvider implements IShebangCodeLensProvider {
}

const shebang = firstLine.text.substr(2).trim();
const pythonPath = await this.getFullyQualifiedPathToInterpreter(shebang, document.uri);
return typeof pythonPath === 'string' && pythonPath.length > 0 ? pythonPath : undefined;
if (resolveShebangAsInterpreter) {
const pythonPath = await this.getFullyQualifiedPathToInterpreter(shebang, document.uri);
return typeof pythonPath === 'string' && pythonPath.length > 0 ? pythonPath : undefined;
} else {
return typeof shebang === 'string' && shebang.length > 0 ? shebang : undefined;
}
}
public async provideCodeLenses(document: TextDocument, _token?: CancellationToken): Promise<CodeLens[]> {
return this.createShebangCodeLens(document);
Expand Down
30 changes: 24 additions & 6 deletions src/test/providers/shebangCodeLenseProvider.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,33 @@ suite('Shebang detection', () => {

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

const shebang = await provider.detectShebang(document.object);
const shebang = await provider.detectShebang(document.object, true);

document.verifyAll();
line.verifyAll();
expect(shebang).to.be.equal(undefined, 'Shebang should be undefined');
});
test('Shebang should be empty when first line is empty when not resolving shebang as interpreter', async () => {
const [document, line] = createDocument('');

const shebang = await provider.detectShebang(document.object, false);

document.verifyAll();
line.verifyAll();
expect(shebang).to.be.equal(undefined, 'Shebang should be undefined');
});
test('Shebang should be returned as it is when not resolving shebang as interpreter', async () => {
const [document, line] = createDocument('#!HELLO');

const shebang = await provider.detectShebang(document.object, false);

document.verifyAll();
line.verifyAll();
expect(shebang).to.be.equal('HELLO', 'Shebang should be HELLO');
});
test('Shebang should be empty when python path is invalid in shebang', async () => {
const [document, line] = createDocument('#!HELLO');

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

const shebang = await provider.detectShebang(document.object);
const shebang = await provider.detectShebang(document.object, true);

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

const shebang = await provider.detectShebang(document.object);
const shebang = await provider.detectShebang(document.object, true);

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

const shebang = await provider.detectShebang(document.object);
const shebang = await provider.detectShebang(document.object, true);

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

const shebang = await provider.detectShebang(document.object);
const shebang = await provider.detectShebang(document.object, true);

document.verifyAll();
line.verifyAll();
Expand Down

0 comments on commit 4c78f3b

Please sign in to comment.