Repository: conan-io/conan

Issue:
[bug] Linter "Unable to import" warning when importing a shared Python Conan package in the build() step
- [x] I've read the [CONTRIBUTING guide](https://raw.githubusercontent.com/conan-io/conan/develop/.github/CONTRIBUTING.md).
- [x] I've specified the Conan version, operating system version and any tool that can be relevant.
- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.

---

I followed the instructions on http://docs.conan.io/en/latest/howtos/python_code_reuse.html.  When I get to the "Requiring a python conan package" step, the linter gives me a warning about importing the shared package:

    $ git clone https://github.com/smokris/conan-test-library
    $ cd conan-test-library
    $ conan export . me/testing
    $ cd ..

    $ git clone https://github.com/smokris/conan-test-consumer
    $ cd conan-test-consumer
    $ conan create . me/testing
    HelloPyReuse/1.0@me/testing: Exporting package recipe
    Linter warnings
        WARN: Linter. Line 9: Unable to import 'hello'
    …
    HelloPyReuse/1.0@me/testing: Calling build()
    Hello World from Python!
    …


(The imported package works fine; the problem is just that the linter is emitting a warning.  I'd prefer that the linter not show this false-positive warning, to improve the linter's signal-to-noise ratio.)

I'm able to reproduce this using:

- Conan 1.1.1 on my local macOS 10.13.3 system
- Conan 1.1.1 on Travis CI's Mac OS 10.10.5 image
- Conan 1.1.1 on Travis CI's Ubuntu 14.04.5 image
- Conan 1.2.0 on CentOS 7.4



Discussion:
Thanks for reporting. Could you confirm the issue in Conan 1.2? We released it today.
> Could you confirm the issue in Conan 1.2? We released it today.

Oh, thanks, I hadn't seen that it was released already.

I just tested with Conan 1.2.0 on CentOS 7.4, but I'm still seeing the linter warning described above.

Resolving patch:
diff --git a/conans/client/cmd/export_linter.py b/conans/client/cmd/export_linter.py
--- a/conans/client/cmd/export_linter.py
+++ b/conans/client/cmd/export_linter.py
@@ -76,6 +76,8 @@ def _accept_message(msg):
             return False
         if symbol in ("bare-except", "broad-except"):  # No exception type(s) specified
             return False
+        if symbol == "import-error" and msg.get("column") > 3:  # Import of a conan python package
+            return False
 
         return True
 


Test patch:
diff --git a/conans/test/integration/python_build_test.py b/conans/test/integration/python_build_test.py
--- a/conans/test/integration/python_build_test.py
+++ b/conans/test/integration/python_build_test.py
@@ -89,7 +89,7 @@ def reuse_build_test(self):
         client = TestClient()
         client.save({CONANFILE: conanfile, "__init__.py": "", "mytest.py": test})
         client.run("export . lasote/stable")
-        reuse = """from conans import ConanFile, tools
+        reuse = """from conans import ConanFile
 class ToolsTest(ConanFile):
     name = "Consumer"
     version = "0.1"
@@ -102,13 +102,14 @@ def build(self):
         client.save({CONANFILE: reuse}, clean_first=True)
         client.run("create . conan/testing")
         self.assertIn("Consumer/0.1@conan/testing: Hello Foo", client.out)
+        self.assertNotIn("WARN: Linter. Line 8: Unable to import 'mytest'", client.out)
 
     def reuse_source_test(self):
         # https://github.com/conan-io/conan/issues/2644
         client = TestClient()
         client.save({CONANFILE: conanfile, "__init__.py": "", "mytest.py": test})
         client.run("export . lasote/stable")
-        reuse = """from conans import ConanFile, tools
+        reuse = """from conans import ConanFile
 class ToolsTest(ConanFile):
     name = "Consumer"
     version = "0.1"
@@ -121,6 +122,7 @@ def source(self):
         client.save({CONANFILE: reuse}, clean_first=True)
         client.run("create . conan/testing")
         self.assertIn("Consumer/0.1@conan/testing: Hello Baz", client.out)
+        self.assertNotIn("WARN: Linter. Line 8: Unable to import 'mytest'", client.out)
 
     def reuse_test(self):
         client = TestClient()
@@ -179,6 +181,7 @@ def basic_install_test(self):
 
         client.save({CONANFILE: reuse}, clean_first=True)
         client.run("export . lasote/stable")
+        self.assertNotIn("Unable to import 'mytest'", client.out)
         client.run("install Consumer/0.1@lasote/stable --build")
         lines = [line.split(":")[1] for line in str(client.user_io.out).splitlines()
                  if line.startswith("Consumer/0.1@lasote/stable: Hello")]