Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pylintrc search #805

Merged
merged 5 commits into from
Feb 19, 2018
Merged

Fix pylintrc search #805

merged 5 commits into from
Feb 19, 2018

Conversation

MikhailArkhipov
Copy link

@MikhailArkhipov MikhailArkhipov commented Feb 16, 2018

Fixes #788
run changes working folder to workspace root while config search searches from the file path.

Fixes #786
Added handling of quote escapes

@codecov
Copy link

codecov bot commented Feb 16, 2018

Codecov Report

Merging #805 into master will increase coverage by 0.21%.
The diff coverage is 96.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #805      +/-   ##
==========================================
+ Coverage   63.42%   63.64%   +0.21%     
==========================================
  Files         258      258              
  Lines       11770    11807      +37     
  Branches     2082     2088       +6     
==========================================
+ Hits         7465     7514      +49     
+ Misses       4297     4285      -12     
  Partials        8        8
Impacted Files Coverage Δ
src/client/language/tokenizer.ts 96.29% <100%> (+0.07%) ⬆️
src/client/linters/pylint.ts 98.33% <100%> (+0.41%) ⬆️
src/client/linters/baseLinter.ts 91.66% <88.88%> (+6.4%) ⬆️
src/client/debugger/mainV2.ts 0% <0%> (ø) ⬆️
src/client/common/installer/productInstaller.ts 67.6% <0%> (+3.28%) ⬆️
src/client/common/application/applicationShell.ts 30.76% <0%> (+7.69%) ⬆️
src/client/common/logger.ts 73.33% <0%> (+20%) ⬆️
src/client/linters/errorHandlers/errorHandler.ts 100% <0%> (+22.22%) ⬆️
src/client/linters/errorHandlers/notInstalled.ts 94.44% <0%> (+61.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 18be595...1ee0be2. Read the comment docs.

@MikhailArkhipov MikhailArkhipov changed the title Fix pylint search Fix pylintrc search Feb 16, 2018
@@ -30,7 +30,7 @@ export class Pylint extends BaseLinter {
const settings = this.configService.getSettings(uri);
if (settings.linting.pylintUseMinimalCheckers
&& this.info.linterArgs(uri).length === 0
&& !await Pylint.hasConfigurationFile(this.fileSystem, uri.fsPath, this.platformService)) {
&& !await Pylint.hasConfigurationFile(this.fileSystem, this.getWorkspaceRootPath(document), this.platformService)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its possible to have pylintrc next to the file itself, and not in the root directory. I don't think this would work under that scenario.

const uri = document.uri;
const settings = this.configService.getSettings(uri);
if (settings.linting.pylintUseMinimalCheckers
&& this.info.linterArgs(uri).length === 0
// Check pylintrc next to the file
&& !await Pylint.hasConfigurationFile(this.fileSystem, path.dirname(uri.fsPath), this.platformService)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work if we have a pylintrc in a sub directory? Not in workspace root, and not in same directory as pylint.
Workspace = c:\dev\project
Pylintrc = c:\dev\project\modules.pylintrc
Python file = c:\dev\project\modules\module1\helper.py

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i'm not mistaken, pylint searces from current file path upwards.

Copy link
Author

@MikhailArkhipov MikhailArkhipov Feb 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to pylint code it only searches upwards within modules and breaks search if __init__.py is missing.

https://pylint.readthedocs.io/en/latest/user_guide/run.html#command-line-options

  1. pylintrc in the current working directory
  2. .pylintrc in the current working directory
  3. If the current working directory is in a Python module, Pylint searches up the hierarchy of Python modules until it finds a pylintrc file. This allows you to specify coding standards on a module-by-module basis. Of course, a directory is judged to be a Python module if it contains an __init__.py file.
  4. The file named by environment variable PYLINTRC
  5. if you have a home directory which isn’t /root:
    a. .pylintrc in your home directory
    b. .config/pylintrc in your home directory
  6. /etc/pylintrc

which is what pylint code does.

def find_pylintrc():
...
        curdir = os.path.abspath(os.getcwd())
        while os.path.isfile(os.path.join(curdir, '__init__.py')):
            curdir = os.path.abspath(os.path.join(curdir, '..'))
            if os.path.isfile(os.path.join(curdir, 'pylintrc')):
                return os.path.join(curdir, 'pylintrc')
            if os.path.isfile(os.path.join(curdir, '.pylintrc')):
                return os.path.join(curdir, '.pylintrc')

We do exactly this from the file location - but linter.run may change working directory to the root - this case was missing. Hence need to check file location and the root.

However, I don't mind relaxing the rule and search upwards in all cases, but it won't match pylint behavior.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there may be case when there is no config at the root, but there is one in B but not in C
root -> B -> C so we won't find it but pylint will. Let me relax the search.

Copy link

@DonJayamanne DonJayamanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m

@MikhailArkhipov MikhailArkhipov merged commit 3fe37a2 into microsoft:master Feb 19, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants