Skip to content

Commit

Permalink
(#25323) [linter] Simplify Conan V2 migration linter
Browse files Browse the repository at this point in the history
* Remove check Conans import

Signed-off-by: Uilian Ries <[email protected]>

* Remove check conans import

Signed-off-by: Uilian Ries <[email protected]>

* Remove lower case name check

Signed-off-by: Uilian Ries <[email protected]>

* Use Conan 2.x for transition linter

Signed-off-by: Uilian Ries <[email protected]>

* Remove old linters from linters doc

Signed-off-by: Uilian Ries <[email protected]>

* Conan 2.x is mandatory

Signed-off-by: Uilian Ries <[email protected]>

---------

Signed-off-by: Uilian Ries <[email protected]>
  • Loading branch information
uilianries committed Sep 19, 2024
1 parent 33ccd9b commit 2ee7947
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 210 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/linter-conan-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
linter/**
.github/workflows/linter-conan-v2.yml
- name: Get Conan v1 version
id: parse_conan_v1_version
- name: Get Conan v2 version
id: parse_conan_v2_version
if: steps.changed_files.outputs.any_changed == 'true'
uses: mikefarah/yq@master
with:
cmd: yq '.conan.version' '.c3i/config_v1.yml'
cmd: yq '.conan.version' '.c3i/config_v2.yml'

- uses: actions/setup-python@v4
if: steps.changed_files.outputs.any_changed == 'true'
Expand All @@ -37,7 +37,7 @@ jobs:
- name: Install requirements
if: steps.changed_files.outputs.any_changed == 'true'
run: |
pip install ${{ env.REQUIREMENTS }} conan==${{ steps.parse_conan_v1_version.outputs.result }}
pip install ${{ env.REQUIREMENTS }} conan==${{ steps.parse_conan_v2_version.outputs.result }}
- name: Execute linter over all recipes in the repository
id: linter_recipes
Expand Down Expand Up @@ -68,20 +68,20 @@ jobs:
with:
files: |
recipes/*/*/conanfile.py
- name: Get Conan v1 version
id: parse_conan_v1_version
- name: Get Conan v2 version
id: parse_conan_v2_version
if: steps.changed-files.outputs.any_changed == 'true'
uses: mikefarah/yq@master
with:
cmd: yq '.conan.version' '.c3i/config_v1.yml'
cmd: yq '.conan.version' '.c3i/config_v2.yml'
- uses: actions/setup-python@v4
if: steps.changed-files.outputs.any_changed == 'true'
with:
python-version: ${{ env.PYVER }}
- name: Install dependencies
if: steps.changed-files.outputs.any_changed == 'true'
run: |
pip install ${{ env.REQUIREMENTS }} conan==${{ steps.parse_conan_v1_version.outputs.result }}
pip install ${{ env.REQUIREMENTS }} conan==${{ steps.parse_conan_v2_version.outputs.result }}
- name: Run linter
if: steps.changed-files.outputs.any_changed == 'true'
run: |
Expand All @@ -101,24 +101,24 @@ jobs:
with:
files: |
recipes/*/*/test_*/conanfile.py
- name: Get Conan v1 version
id: parse_conan_v1_version
- name: Get Conan v2 version
id: parse_conan_v2_version
if: steps.changed-files.outputs.any_changed == 'true'
uses: mikefarah/yq@master
with:
cmd: yq '.conan.version' '.c3i/config_v1.yml'
cmd: yq '.conan.version' '.c3i/config_v2.yml'
- uses: actions/setup-python@v4
if: steps.changed-files.outputs.any_changed == 'true'
with:
python-version: ${{ env.PYVER }}
- name: Install dependencies
if: steps.changed-files.outputs.any_changed == 'true'
run: |
pip install ${{ env.REQUIREMENTS }} conan==${{ steps.parse_conan_v1_version.outputs.result }}
pip install ${{ env.REQUIREMENTS }} conan==${{ steps.parse_conan_v2_version.outputs.result }}
- name: Run linter
if: steps.changed-files.outputs.any_changed == 'true'
run: |
echo "::add-matcher::linter/recipe_linter.json"
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
pylint --rcfile=linter/pylintrc_testpackage --ignore-paths="recipes/[^/]*/[^/]*/test_v1[^/]*/conanfile.py" --output-format=parseable ${file}
pylint --rcfile=linter/pylintrc_testpackage --ignore-paths="recipes/[^/]*/[^/]*/test_v2[^/]*/conanfile.py" --output-format=parseable ${file}
done
75 changes: 0 additions & 75 deletions docs/linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ to configure plugins, warnings and errors which should be enabled or disabled.
* [Running the linters locally](#running-the-linters-locally)
* [Pylint configuration files](#pylint-configuration-files)
* [Linter Warning and Errors](#linter-warning-and-errors)
* [E9006 - conan-import-conanfile: ConanFile should be imported from conan](#e9006---conan-import-conanfile-conanfile-should-be-imported-from-conan)
* [E9005 - conan-missing-name: Every conan recipe must contain the attribute name](#e9005---conan-missing-name-every-conan-recipe-must-contain-the-attribute-name)
* [E9004 - conan-package-name: Conan package names must be lower-case](#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](#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](#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](#e9009---conan-import-error-conanexception-conanserrors-is-deprecated-and-conanerrors-should-be-used-instead)
* [E9010 - conan-import-error-conaninvalidconfiguration: conans.errors is deprecated and conan.errors should be used instead](#e9010---conan-import-error-conaninvalidconfiguration-conanserrors-is-deprecated-and-conanerrors-should-be-used-instead)
* [E9011 - conan-import-tools: Importing conan.tools or conan.tools.xxx.zzz.yyy should be considered as private](#e9011---conan-import-tools-importing-conantools-or-conantoolsxxxzzzyyy-should-be-considered-as-private)
* [E9012 - conan-attr-version: Recipe should not contain version attribute](#e9012---conan-attr-version-recipe-should-not-contain-version-attribute)<!-- endToc -->

Expand All @@ -47,18 +42,6 @@ Check the [Developing Recipes](developing_recipes_locally.md) for more informati

Here is the list of current warning and errors provided by pylint, when using CCI configuration.

### E9006 - conan-import-conanfile: ConanFile should be imported from conan

```python
from conans import ConanFile
```

Should be replaced by:

```python
from conan import Conanfile
```

### E9005 - conan-missing-name: Every conan recipe must contain the attribute name

The attribute `name` is always expected. On the other hand, `version` should not be listed.
Expand All @@ -68,15 +51,6 @@ def BazConanfile(ConanFile):
name = "baz"
```

### E9004 - conan-package-name: Conan package names must be lower-case

The package name is always lower-case, even when the upstream uses another format

```python
def FoobarConanfile(ConanFile):
name = "foobar"
```

### E9007 - conan-test-no-name: Do not add name attribute in test package recipes

The test package is not a recipe, thus, it should not have a name
Expand All @@ -86,55 +60,6 @@ def TestPackageConanFile(ConanFile):
name = "test_package" # Wrong!
```

### E9008 - conan-import-errors: Deprecated imports should be replaced by new imports

Read [v2_linter](v2_linter.md) for a list of mappings of v1 to v2.
Regular imports from `conans.tools` are now updated:

```python
from conans import tools
...

tools.rmdir(os.path.join(self.package_folder, "shared"))
```

Should be replaced by specialized tools, prepared for Conan 2.0

```python
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

```python
from conans.errors import ConanException
```

Should be replaced by:

```python
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

```python
from conans.errors import ConanInvalidConfiguration
```

Should be replaced by:

```python
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](https://docs.conan.io/1/reference/conanfile/tools.html):
Expand Down
6 changes: 3 additions & 3 deletions docs/v2_migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This is expected for recipes to be updates in each pull request.

- Updated helpers are expected, this is enforced by the [v2_linter](v2_linter.md)
- Once a recipe publishes v2 packages, it must pass the v2 pipeline
- The v2 pipeline with **shortly be required** for changes to be merged.
- Once a recipe publishes v2 packages, it must pass the v2 pipeline always.
- The v2 pipeline with **is required** for changes to be merged.

<!-- toc -->
## Contents
Expand Down Expand Up @@ -127,7 +127,7 @@ generators using the ``set_property(property_name, value)`` method.
Both of these two models **will live together in recipes** to make
recipes compatible for both 1.x and 2.0 users. Deprecated feilds are not to be removed at this time.

To understand the impact of these and the relation between different generates, refer to the
To understand the impact of these and the relation between different generates, refer to the
[migrating properties](https://docs.conan.io/1/migrating_to_2.0/properties.html) documentation.

### Translating .names information to cmake_target_name, cmake_module_target_name and cmake_file_name
Expand Down
28 changes: 0 additions & 28 deletions linter/check_import_conanfile.py

This file was deleted.

77 changes: 0 additions & 77 deletions linter/check_import_errors.py

This file was deleted.

8 changes: 0 additions & 8 deletions linter/check_package_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ class PackageName(BaseChecker):

name = "conan-package-name"
msgs = {
"E9004": (
"Reference name should be all lowercase",
"conan-bad-name",
"Use only lower-case on the package name: `name = 'foobar'`."
),
"E9005": (
"Missing name attribute",
"conan-missing-name",
Expand All @@ -44,9 +39,6 @@ def visit_classdef(self, node: nodes) -> None:
if is_test:
self.add_message("conan-test-no-name", node=attr, line=attr.lineno)
return
value = children[1].as_string()
if value.lower() != value:
self.add_message("conan-bad-name", node=attr, line=attr.lineno)
return
if not is_test:
self.add_message("conan-missing-name", node=node)
6 changes: 0 additions & 6 deletions linter/conanv2_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@

from pylint.lint import PyLinter
from linter.check_package_name import PackageName
from linter.check_import_conanfile import ImportConanFile
from linter.check_import_errors import ImportErrorsConanException, ImportErrorsConanInvalidConfiguration, ImportErrors
from linter.check_import_tools import ImportTools
from linter.check_layout_src_folder import LayoutSrcFolder
from linter.check_version_attribute import VersionAttribute


def register(linter: PyLinter) -> None:
linter.register_checker(PackageName(linter))
linter.register_checker(ImportConanFile(linter))
linter.register_checker(ImportErrors(linter))
linter.register_checker(ImportErrorsConanException(linter))
linter.register_checker(ImportErrorsConanInvalidConfiguration(linter))
linter.register_checker(ImportTools(linter))
linter.register_checker(LayoutSrcFolder(linter))
linter.register_checker(VersionAttribute(linter))

0 comments on commit 2ee7947

Please sign in to comment.