Skip to content

Commit

Permalink
Disable pylint print statement flag + fix venv detection (#954)
Browse files Browse the repository at this point in the history
* Basic tokenizer

* Fixed property names

* Tests, round I

* Tests, round II

* tokenizer test

* Remove temorary change

* Fix merge issue

* Merge conflict

* Merge conflict

* Completion test

* Fix last line

* Fix javascript math

* Make test await for results

* Add license headers

* Rename definitions to types

* License headers

* Fix typo in completion details (typo)

* Fix hover test

* Russian translations

* Update to better translation

* Fix typo

*  #70 How to get all parameter info when filling in a function param list

* Fix #70 How to get all parameter info when filling in a function param list

* Clean up

* Clean imports

* CR feedback

* Trim whitespace for test stability

* More tests

* Better handle no-parameters documentation

* Better handle ellipsis and Python3

* #385 Auto-Indentation doesn't work after comment

* #141 Auto indentation broken when return keyword involved

* Undo changes

* #627 Docstrings for builtin methods are not parsed correctly

* reStructuredText converter

* Fix: period is not an operator

* Minor fixes

* Restructure

* Tests

* Tests

* Code heuristics

* Baselines

* HTML handling

* Lists

* State machine

* Baselines

* Squash

* no message

* Whitespace difference

* Update Jedi to 0.11.1

* Enable Travis

* Test fixes

* Undo change

* Jedi 0.11 with parser

* Undo changes

* Undo changes

* Test fixes

* More tests

* Tests

* Fix pylint search

* Handle quote escapes in strings

* Escapes in strings

* CR feedback

* Discover pylintrc better + tests

* Fix .pyenv/versions search

* Fix multiple linters output

* Better handle markdown underscore

* Test

* Fix 916: PyLint checks wrong files

* Test stability

* Try increase timeout

* Make sure linting is enabled in tests

* Try another way of waiting

* Simplify

* Fix clear diags on close tests

* Try writing settings directly

* Increase timeout

* Measure test time

* Measure time

* Simplify

* Set timeout

* Better venv detection

* Add test

* More reliable check

* Fix pylint switch key

* Remove incorrect flag

* Disable print

* Require pylint 1.8 on CI

* Fix working directory for standalone files

* Use an 'elif'

* Separate file for pylint root config
  • Loading branch information
Mikhail Arkhipov authored Mar 6, 2018
1 parent 8c94314 commit 77f3612
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 9 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
autopep8==1.2.1
yapf==0.6.2
pylint==1.5.4
pylint==1.8.2
pep8==1.7.0
prospector==0.11.7
flake8==2.6.0
Expand Down
10 changes: 5 additions & 5 deletions src/client/interpreter/virtualEnvs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ export class VirtualEnvironmentManager implements IVirtualEnvironmentManager {
}
public async getEnvironmentName(pythonPath: string): Promise<string> {
// https://stackoverflow.com/questions/1871549/determine-if-python-is-running-inside-virtualenv
const output = await this.processService.exec(pythonPath, ['-c', 'import sys;print(hasattr(sys, "real_prefix"))']);
// hasattr(sys, 'real_prefix') works for virtualenv while
// '(hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))' works for venv
const code = 'import sys\nif hasattr(sys, "real_prefix"):\n print("virtualenv")\nelif hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix:\n print("venv")';
const output = await this.processService.exec(pythonPath, ['-c', code]);
if (output.stdout.length > 0) {
const result = output.stdout.trim();
if (result === 'True') {
return 'virtualenv';
}
return output.stdout.trim();
}
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/linters/baseLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export abstract class BaseLinter implements ILinter {
protected getWorkspaceRootPath(document: vscode.TextDocument): string {
const workspaceFolder = this.workspace.getWorkspaceFolder(document.uri);
const workspaceRootPath = (workspaceFolder && typeof workspaceFolder.uri.fsPath === 'string') ? workspaceFolder.uri.fsPath : undefined;
return typeof workspaceRootPath === 'string' ? workspaceRootPath : __dirname;
return typeof workspaceRootPath === 'string' ? workspaceRootPath : path.dirname(document.uri.fsPath);
}
protected get logger(): ILogger {
return this.serviceContainer.get<ILogger>(ILogger);
Expand Down
3 changes: 2 additions & 1 deletion src/client/linters/pylint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export class Pylint extends BaseLinter {
&& !await Pylint.hasConfigurationFile(this.fileSystem, this.getWorkspaceRootPath(document), this.platformService)) {
minArgs = [
'--disable=all',
'--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode'
'--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,unused-wildcard-import,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode',
'–-disable=print-statement'
];
}
const args = [
Expand Down
53 changes: 53 additions & 0 deletions src/test/interpreters/virtualEnvManager.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { expect } from 'chai';
import { Container } from 'inversify';
import * as TypeMoq from 'typemoq';
import { BufferDecoder } from '../../client/common/process/decoder';
import { ProcessService } from '../../client/common/process/proc';
import { IBufferDecoder, IProcessService } from '../../client/common/process/types';
import { VirtualEnvironmentManager } from '../../client/interpreter/virtualEnvs';
import { ServiceContainer } from '../../client/ioc/container';
import { ServiceManager } from '../../client/ioc/serviceManager';

suite('Virtual environment manager', () => {
let serviceManager: ServiceManager;
let serviceContainer: ServiceContainer;
let process: TypeMoq.IMock<IProcessService>;

setup(async () => {
const cont = new Container();
serviceManager = new ServiceManager(cont);
serviceContainer = new ServiceContainer(cont);
});

test('Plain Python environment suffix', async () => await testSuffix(''));
test('Venv environment suffix', async () => await testSuffix('venv'));
test('Virtualenv Python environment suffix', async () => await testSuffix('virtualenv'));

test('Run actual virtual env detection code', async () => {
serviceManager.addSingleton<IProcessService>(IProcessService, ProcessService);
serviceManager.addSingleton<IBufferDecoder>(IBufferDecoder, BufferDecoder);
const venvManager = new VirtualEnvironmentManager(serviceContainer);
const name = await venvManager.getEnvironmentName('python');
const result = name === '' || name === 'venv' || name === 'virtualenv';
expect(result).to.be.equal(true, 'Running venv detection code failed.');
});

async function testSuffix(expectedName: string) {
process = TypeMoq.Mock.ofType<IProcessService>();
serviceManager.addSingletonInstance<IProcessService>(IProcessService, process.object);

const venvManager = new VirtualEnvironmentManager(serviceContainer);
process
.setup(x => x.exec('python', TypeMoq.It.isAny()))
.returns(() => Promise.resolve({
stdout: expectedName,
stderr: ''
}));

const name = await venvManager.getEnvironmentName('python');
expect(name).to.be.equal(expectedName, 'Virtual envrironment name suffix is incorrect.');
}
});
2 changes: 1 addition & 1 deletion src/test/linters/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ suite('Linting', () => {
});
test('PyLint with config in root', async () => {
await fs.copy(path.join(pylintConfigPath, '.pylintrc'), path.join(workspaceUri.fsPath, '.pylintrc'));
await testLinterMessages(Product.pylint, path.join(pylintConfigPath, 'file.py'), []);
await testLinterMessages(Product.pylint, path.join(pylintConfigPath, 'file2.py'), []);
});
test('Flake8 with config in root', async () => {
await testLinterMessages(Product.flake8, path.join(flake8ConfigPath, 'file.py'), filteredFlake8MessagesToBeReturned);
Expand Down
19 changes: 19 additions & 0 deletions src/test/pythonFiles/linting/pylintconfig/file2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""pylint option block-disable"""

__revision__ = None

class Foo(object):
"""block-disable test"""

def __init__(self):
pass

def meth1(self, arg):
"""meth1"""
print self.blop

def meth2(self, arg):
"""meth2"""
# pylint: disable=unused-argument
print self\
+ "foo"

0 comments on commit 77f3612

Please sign in to comment.