From f03c78ff148efb647157cc6ac2c3bff8daba1541 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 1 Aug 2022 12:03:40 +0200 Subject: [PATCH] (#11948) [linter] Add more checks to migrate import for tools * [linter] Add more checks to migrate import for tools * add link --- docs/v2_linter.md | 19 ++++++++----------- linter/transform_imports.py | 6 ++++++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/docs/v2_linter.md b/docs/v2_linter.md index 5b0a6b0371..5d8e04144c 100644 --- a/docs/v2_linter.md +++ b/docs/v2_linter.md @@ -33,21 +33,18 @@ 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 +should start to import their tools from this new module. Some of the new tools accept new argument, please, check the [Conan documentation](https://docs.conan.io/en/latest/reference/conanfile/tools.html). -For example, the `cross_building` tool now should be used like: +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): -```python -from conan.tools.build import cross_building +| **Conan v1** | **Conan v2** | +|---|---| +| conans.tools.get | [conan.tools.files.get](https://docs.conan.io/en/latest/reference/conanfile/tools/files/downloads.html#conan-tools-files-get) | +| conans.tools.cross_building | [conan.tools.build.cross_building](https://docs.conan.io/en/latest/reference/conanfile/tools/build.html#conan-tools-build-cross-building) | +| conans.tools.rmdir | [conan.tools.files.rmdir](https://docs.conan.io/en/latest/reference/conanfile/tools/files/basic.html#conan-tools-files-rmdir) | +| conans.tools.Version | [conans.tools.scm.Version](https://docs.conan.io/en/latest/reference/conanfile/tools/scm/other.html#version) | -... -class Recipe(ConanFile): - - def test(self): - if not cross_building(self): - pass -``` # Disable linter for `test_v1_*/conanfile.py` diff --git a/linter/transform_imports.py b/linter/transform_imports.py index cb1c117a58..e3d4b2c573 100644 --- a/linter/transform_imports.py +++ b/linter/transform_imports.py @@ -16,8 +16,14 @@ def register(linter: PyLinter): def transform_tools(module): """ Transform import module """ + if 'get' in module.locals: + del module.locals['get'] if 'cross_building' in module.locals: del module.locals['cross_building'] + if 'rmdir' in module.locals: + del module.locals['rmdir'] + if 'Version' in module.locals: + del module.locals['Version'] astroid.MANAGER.register_transform(