Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions .github/runlint.py

This file was deleted.

82 changes: 82 additions & 0 deletions .github/workflows/linter-conan-v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: "[linter] Conan v2 migration"

on:
pull_request:

env:
PYTHONPATH: ${{github.workspace}}
PYVER: "3.8"
SCORE_THRESHOLD: "9.0"
REQUIREMENTS: "pylint==2.14"

jobs:
test_linter:
name: Test linter changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Get changed files
uses: tj-actions/changed-files@v20
id: changed_files
with:
files: |
linter/**
- uses: actions/setup-python@v3
if: steps.changed_files.outputs.any_changed == 'true'
with:
python-version: ${{ env.PYVER }}
- name: Install requirements
if: steps.changed_files.outputs.any_changed == 'true'
run: |
pip install ${{ env.REQUIREMENTS }}
- name: Execute linter over all recipes in the repository
if: steps.changed_files.outputs.any_changed == 'true'
run: |
pylint --rcfile=linter/.pylintrc recipes/*/*/conanfile.py --output-format=json --output=out.json --score=y --fail-under=${{ env.SCORE_THRESHOLD }}
- name: Archive production artifacts
if: steps.changed_files.outputs.any_changed == 'true' && always()
uses: actions/upload-artifact@v3
with:
name: linter-output
path: |
out.json
- name: Create report
if: steps.changed_files.outputs.any_changed == 'true' && always()
run: |
echo '## Linter summary' >> $GITHUB_STEP_SUMMARY
jq 'map( select(.type=="error")) | group_by (.message)[] | {message: .[0].message, length: length}' out.json > out2.json
jq -r '" * \(.message): \(.length)"' out2.json >> $GITHUB_STEP_SUMMARY
echo '> Note.- Check uploaded artifact for a full report.' >> $GITHUB_STEP_SUMMARY

conanfile_recipe:
name: Lint changed conanfile.py
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v20
with:
files: |
**/conanfile.py
- uses: actions/setup-python@v3
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 }}
- 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 --output-format=parseable ${file}
done

# TODO: Add linting of test_package/conanfile.py files. The rules might be different from recipe files
35 changes: 0 additions & 35 deletions .github/workflows/linters.yml

This file was deleted.

18 changes: 18 additions & 0 deletions linter/.pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[MASTER]
load-plugins=linter.conanv2_transition
py-version=3.6
recursive=no
suggestion-mode=yes
unsafe-load-any-extension=no

[MESSAGES CONTROL]
disable=all
enable=conan-bad-name,
conan-missing-name

[REPORTS]
evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error) / statement) * 10))
output-format=text
reports=no
score=no

Empty file added linter/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions linter/conanv2_transition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""Pylint plugin for Conan Center Index"""
from pylint.lint import PyLinter
from linter.package_name import PackageName


def register(linter: PyLinter) -> None:
linter.register_checker(PackageName(linter))
39 changes: 39 additions & 0 deletions linter/package_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from pylint.checkers import BaseChecker
from pylint.interfaces import IAstroidChecker
from astroid import nodes, Const, AssignName


class PackageName(BaseChecker):
"""
All packages must have a lower-case name
"""

__implements__ = IAstroidChecker

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",
"The member attribute `name` must be declared: `name = 'foobar'`."
)
}

def visit_classdef(self, node: nodes) -> None:
if node.basenames == ['ConanFile']:
for attr in node.body:
children = list(attr.get_children())
if len(children) == 2 and \
isinstance(children[0], AssignName) and \
children[0].name == "name" and \
isinstance(children[1], Const):
value = children[1].as_string()
if value.lower() != value:
self.add_message("conan-bad-name", node=attr, line=attr.lineno)
return
self.add_message("conan-missing-name", node=node)
10 changes: 4 additions & 6 deletions .github/recipe_linter.json → linter/recipe_linter.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
"severity": "error",
"pattern": [
{
"regexp": "(\\S+):(\\d+):(\\d+):\\s(E\\d+):\\s(.+)\\s\\((\\S+)\\)",
"regexp": "(\\S+):(\\d+): \\[(E\\d+\\(\\S+\\)),\\s(.+?)\\](.+)",
"file": 1,
"line": 2,
"column": 3,
"message": 5,
"code": 4
"code": 3
}
]
},
Expand All @@ -19,12 +18,11 @@
"severity": "warning",
"pattern": [
{
"regexp": "(\\S+):(\\d+):(\\d+):\\s(W(?!0511)\\d+):\\s(.+)\\s\\((\\S+)\\)",
"regexp": "(\\S+):(\\d+): \\[(W\\d+\\(\\S+\\)),\\s(.+?)\\](.+)",
"file": 1,
"line": 2,
"column": 3,
"message": 5,
"code": 4
"code": 3
}
]
}
Expand Down