Skip to content

Commit

Permalink
make linter actually compatible with v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ericLemanissier committed Sep 23, 2024
1 parent 5485fa9 commit 3f70e1d
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions linter/transform_conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,10 @@
import textwrap
import astroid
from astroid.builder import AstroidBuilder
from astroid.builder import extract_node
from astroid.inference_tip import inference_tip
from astroid.manager import AstroidManager


def _settings_transform():
module = AstroidBuilder(AstroidManager()).string_build(
textwrap.dedent("""
class Settings(object):
os = None
arch = None
compiler = None
build_type = None
""")
)
return module['Settings']

def _user_info_build_transform():
module = AstroidBuilder(AstroidManager()).string_build(
textwrap.dedent("""
Expand All @@ -41,28 +30,24 @@ def transform_conanfile(node):
info_class = astroid.MANAGER.ast_from_module_name("conans.model.info").lookup(
"ConanInfo")
build_requires_class = astroid.MANAGER.ast_from_module_name(
"conans.client.graph.graph_manager").lookup("_RecipeBuildRequires")
file_copier_class = astroid.MANAGER.ast_from_module_name(
"conans.client.file_copier").lookup("FileCopier")
file_importer_class = astroid.MANAGER.ast_from_module_name(
"conans.client.importer").lookup("_FileImporter")
"conans.model.requires").lookup("BuildRequirements")
tool_requires_class = astroid.MANAGER.ast_from_module_name(
"conans.model.requires").lookup("ToolRequirements")
test_requires_class = astroid.MANAGER.ast_from_module_name(
"conans.model.requires").lookup("TestRequirements")
python_requires_class = astroid.MANAGER.ast_from_module_name(
"conans.client.graph.python_requires").lookup("PyRequires")

dynamic_fields = {
"conan_data": str_class,
"build_requires": build_requires_class,
"test_requires" : build_requires_class,
"tool_requires": build_requires_class,
"test_requires" : test_requires_class,
"tool_requires": tool_requires_class,
"info_build": info_class,
"user_info_build": [_user_info_build_transform()],
"info": info_class,
"copy": file_copier_class,
"copy_deps": file_importer_class,
"python_requires": [str_class, python_requires_class],
"recipe_folder": str_class,
"settings_build": [_settings_transform()],
"settings_target": [_settings_transform()],
"conf": dict_class,
}

Expand All @@ -73,3 +58,17 @@ def transform_conanfile(node):
astroid.MANAGER.register_transform(
astroid.ClassDef, transform_conanfile,
lambda node: node.qname() == "conans.model.conan_file.ConanFile")


def _looks_like_settings(node: astroid.Attribute) -> bool:
return node.attrname in ["settings", "settings_build", "settings_target"]

def infer_settings(node, context):
return astroid.MANAGER.ast_from_module_name(
"conans.model.settings").lookup("Settings")[1][0].instantiate_class().infer(context=context)

astroid.MANAGER.register_transform(
astroid.Attribute,
inference_tip(infer_settings),
_looks_like_settings,
)

0 comments on commit 3f70e1d

Please sign in to comment.