Some linter configuration files are available in the folder linter, which are executed by Github Actions to improve recipe quality. They consume python scripts which are executed to fit CCI rules. Those scripts use astroid and pylint classes to parse Conan recipe files and manage their warnings and errors.
Pylint by itself is not able to find ConanCenterIndex rules, so astroid is used to iterate over conanfiles content and validate CCI conditions. Also, pylint uses rcfile (a configuration file based on toml format) to configure plugins, warnings and errors which should be enabled or disabled.
Also, the Github code review is integrated with the pylint output,
parsed by recipe_linter.json, then presented to all users on the tab Files changed
.
- Running the linter locally
- Pylint configuration files
- Linter Warning and Errors
- E9006 - conan-import-conanfile: ConanFile should be imported from conan
- E9005 - conan-missing-name: Every conan recipe must contain the attribute name
- E9004 - conan-package-name: Conan package names must be lower-case
- E9007 - conan-test-no-name: Do not add name attribute in test package recipes
- E9008 - conan-import-errors: Deprecated imports should be replaced by new imports
- E9009 - conan-import-error-conanexception: conans.errors is deprecated and conan.errors should be used instead
- E9010 - conan-import-error-conaninvalidconfiguration: conans.errors is deprecated and conan.errors should be used instead
- E9011 - conan-import-tools: Importing conan.tools or conan.tools.xxx.zzz.yyy should be considered as private
Check the Developing Recipes page for details.
- Pylint Recipe: This
rcfile
lists plugins and rules to be executed over all recipes (not test package) and validate them. - Pylint Test Package Recipe: This
rcfile
lists plugins and rules to be executed over all recipes in test package folders only:
Here is the list of current warning and errors provided by pylint, when using CCI configuration.
from conans import ConanFile
Should be replaced by:
from conan import Conanfile
The attribute name
is always expected. On the other hand, version
should not be listed.
def BazConanfile(ConanFile):
name = "baz"
The package name is always lower-case, even when the upstream uses another format
def FoobarConanfile(ConanFile):
name = "foobar"
The test package is not a recipe, thus, it should not have a name
def TestPackageConanFile(ConanFile):
name = "test_package" # Wrong!
Read v2_linter for a list of mappings of v1 to v2.
Regular imports from conans.tools
are now updated:
from conans import tools
...
tools.rmdir(os.path.join(self.package_folder, "shared"))
Should be replaced by specialized tools, prepared for Conan 2.0
from conan.tools.files import rmdir
...
rmdir(self, os.path.join(self.package_folder, "shared"))
E9009 - conan-import-error-conanexception: conans.errors is deprecated and conan.errors should be used instead
from conans.errors import ConanException
Should be replaced by:
from conan.errors import ConanException
Only the namespace conans
has been replaced by conan
.
E9010 - conan-import-error-conaninvalidconfiguration: conans.errors is deprecated and conan.errors should be used instead
from conans.errors import ConanInvalidConfiguration
Should be replaced by:
from conan.errors import ConanInvalidConfiguration
Only the namespace conans
has been replaced by conan
.
E9011 - conan-import-tools: Importing conan.tools or conan.tools.xxx.zzz.yyy should be considered as private
Documented on conanfile.tools:
It's not allowed to use tools.xxx
directly:
from conan import tools
...
tools.scm.Version(self.version)
Neither sub modules:
from conan.tools.apple.apple import is_apple_os
Only modules under conan.tools
and conan.tools.xxx
are allowed:
from conan.tools.files import rmdir
from conan.tools import scm