Files
conan-center-index/docs/v2_linter.md
Daniel f03c78ff14 (#11948) [linter] Add more checks to migrate import for tools
* [linter] Add more checks to migrate import for tools

* add link
2022-08-01 12:03:40 +02:00

2.8 KiB

Linter to help migration to Conan v2

Contents

On our path to Conan v2 we are leveraging on custom Pylint rules. This linter will run for every pull-request that is submitted to the repository and will raise some warnings and errors that should be addressed in order to migrate the recipes to Conan v2.

It is important to note that these rules are targetting Conan v2 compatibility layer, their purpose is to fail for v1 syntax that will be no longer available in v2. Even if the syntax if perfectly valid in Conan v1, the recipe might fail here because it is not v2-compliant.

Note.- Some of the errored checks might be just plain Python syntax errors, while others might be related to the custom rules added by us.

Here you can find some examples of the extra rules we are adding:

Import ConanFile from conan

The module conans is deprecated in Conan v2. Now all the imports should be done from module conan:

from conan import ConanFile

Import tools from conan

All v2-compatible tools are available in module conan.tools under different submodules. Recipes should start to import their tools from this new module. Some of the new tools accept new argument, please, check the Conan documentation.

Here is a list of different imports and their new equivalent (note that the interface for most of this functions changed, see their respective link to the documentation):

Conan v1 Conan v2
conans.tools.get conan.tools.files.get
conans.tools.cross_building conan.tools.build.cross_building
conans.tools.rmdir conan.tools.files.rmdir
conans.tools.Version conans.tools.scm.Version

Disable linter for test_v1_*/conanfile.py

Using the pattern test_v1_*/conanfile.py you can write a test that will be executed using only Conan v1, you probably don't want v2-migration linter to check this file, as it will likely contain syntax that is specific to Conan v1.

To skip the file you just need to add the following comment to the file and pylint will skip it:

test_v1_*/conanfile.py

# pylint: skip-file
from conans import ConanFile, CMake, tools
...