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

Provide pylint plugin to avoid warnings in IDE when working with conanfile.py #2706

Closed
ytimenkov opened this issue Apr 3, 2018 · 8 comments
Milestone

Comments

@ytimenkov
Copy link
Contributor

Problem

When editing conanfile.py with editor which has linter support (VS Code with Python extension in my case) there are a bunch of errors related to dynamic fields (like self.copy is not callable or Instance of ConanFile doesn't have package_folder member).

Proposal

Conan has a built-in linting support for conanfile.py, but it deals with dynamic fields by post-processing json output.

It would be useful if this logic is moved to a pylint plugin which can be reused by editor/IDE or via command line options.

There are few tutorials on the Internet about how to do it.

@memsharded
Copy link
Member

Yes, this is a good idea, thanks!
Actually, extracting the linting functionality to a conan plugin system (where other custom checkers can be provided by users) is something that we want to do.

We will check this when we do that, and will try to make this plugin reusable, not only for conan, but for editors too.

@ytimenkov
Copy link
Contributor Author

I've created a prototype of pylint plugin: ytimenkov/conan@dd1c20e
Will try later today how it integrates with VS Code.

@sourcedelica
Copy link

Pycharm warns on self.settings.xxx (for example self.settings.compiler, where compiler is flagged). The reason is self.settings is an attribute with a tuple of strings (settings = "os", "compiler", "build_type", "arch"). The same thing goes for self.options.xxx.

I'm wondering if there could be a less dynamic alternative API that would be less confusing to IDEs.

@ytimenkov
Copy link
Contributor Author

@sourcedelica ConanFile.settings actually has type of conans.model.settings.Settings

You may try using get_safe method, for example self.settings.get_safe("os.arch")

There could be a way to help IDE to infer the type. E.g. VS Code's plugin understands assert isinstance(x, type). See microsoft/PTVS#82

@sourcedelica
Copy link

sourcedelica commented May 16, 2018 via email

@mmatrosov
Copy link

@sourcedelica I can't even go that far, I have immediate error "[pylint] E0401:Unable to import 'conans'". How did you pass through that? :) (Note that I have conan installed with the stand-alone installer, not as python package, maybe this might be the problem?)

@ytimenkov
Copy link
Contributor Author

@mmatrosov It works better if you install conan via pip. If you have standalone installer which provides python modules (not sure if the official one does, pyinstaller explicitly hides modules so they can't be imported) you can add it to sys.path. For example my .pylintrc looks like:

[MASTER]
init-hook='import sys; sys.path.extend(["/home/user/conan-install"])'

load-plugins=conans.client.conanfile_plugin

[MESSAGES CONTROL]
disable=C,R

(the plugin is in PR yet)

@ghost ghost removed the stage: review label Jul 13, 2018
memsharded pushed a commit that referenced this issue Jul 13, 2018
* Replaced linter message filtering with plugin.

Fixes #2706

* More evident name for plugin.
@memsharded memsharded added this to the 1.6 milestone Jul 13, 2018
@memsharded
Copy link
Member

Hi all!

Many thanks to @ytimenkov for implementing it! It will be released in next 1.6, keep tuned for testing it!

grisumbras pushed a commit to grisumbras/conan that referenced this issue Dec 27, 2018
* Replaced linter message filtering with plugin.

Fixes conan-io#2706

* More evident name for plugin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants