Repository: conan-io/conan

Issue:
[python_requires] objects are overwritten when using multiple python_requires calls in one recipe
To help us debug your issue please explain:

- [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.


conan version: 1.7.4
os: Windows 7
Python 3.6.5

We are using multiple python_requires calls in our recipes. It seems that a second python_requires call overwrites objects of the previous python_requires call.
Given the following two python modules:
![module1](https://user-images.githubusercontent.com/39289804/46060018-17c37f80-c151-11e8-845a-efbcd70c4b24.png)
![module2](https://user-images.githubusercontent.com/39289804/46060021-1d20ca00-c151-11e8-88af-ec511cd13fbc.png)

If I import both modules via the python_reuqires I would expect the follwing behavior:
![expectedbehavior](https://user-images.githubusercontent.com/39289804/46060099-5f4a0b80-c151-11e8-87a1-e1e86e78326f.png)

But the behavior is the following:
![currentbehavior1](https://user-images.githubusercontent.com/39289804/46060227-ff079980-c151-11e8-93d7-694e4e5ca4b4.png)
So the second python_requires overwrites the function and the variable from the first python_requires:
![currentbehavior](https://user-images.githubusercontent.com/39289804/46060234-05961100-c152-11e8-9927-56fa4c179c2e.png)


This seems a bit confusing to us. 
Can you please have a look at this? 

Thanks!








Discussion:
I think we have the same problem here.
We want to define a list of packages in a Python module which we want to import into our recipe via 'python_requires'. The Python module defines a global variable called 'packages'.
It works as long as we only import one module, but as soon as we import a second one with the same variable 'packages' defined, the variable of the first module gets overwritten.
Maybe you can distinguish the modules internally by giving each one internally a different hash?
I think it can be improved by assigning a different name to each loaded module, almost the same behavior implemented for the plugins functionality [in these lines](https://github.com/conan-io/conan/blob/fccb7c1a6ce65849a151ec57f44d1f3990cad600/conans/client/plugin_manager.py#L98).

Thanks for reporting.

Let's try to fix it for 1.8

Resolving patch:
diff --git a/conans/client/graph/python_requires.py b/conans/client/graph/python_requires.py
--- a/conans/client/graph/python_requires.py
+++ b/conans/client/graph/python_requires.py
@@ -37,7 +37,7 @@ def __call__(self, require):
             self._references.append(reference)
             try:
                 sys.path.append(os.path.dirname(path))
-                module = imp.load_source("python_require", path)
+                module = imp.load_source(str(r), path)
             finally:
                 sys.path.pop()
             self._modules[require] = module, reference


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
@@ -174,6 +174,45 @@ class MyConanfileBase(source.SourceBuild, package.PackageInfo):
         self.assertIn("Pkg/0.1@lasote/testing: My cool package!", client.out)
         self.assertIn("Pkg/0.1@lasote/testing: My cool package_info!", client.out)
 
+    def multiple_requires_error_test(self):
+        client = TestClient()
+        conanfile = """from conans import ConanFile
+myvar = 123
+def myfunct():
+    return 123
+class Pkg(ConanFile):
+    pass
+"""
+        client.save({"conanfile.py": conanfile})
+        client.run("export . Pkg1/1.0@user/channel")
+
+        conanfile = """from conans import ConanFile
+myvar = 234
+def myfunct():
+    return 234
+class Pkg(ConanFile):
+    pass
+"""
+        client.save({"conanfile.py": conanfile})
+        client.run("export . Pkg2/1.0@user/channel")
+
+        conanfile = """from conans import ConanFile, python_requires
+pkg1 = python_requires("Pkg1/1.0@user/channel")
+pkg2 = python_requires("Pkg2/1.0@user/channel")
+class MyConanfileBase(ConanFile):
+    def build(self):
+        self.output.info("PKG1 : %s" % pkg1.myvar)
+        self.output.info("PKG2 : %s" % pkg2.myvar)
+        self.output.info("PKG1F : %s" % pkg1.myfunct())
+        self.output.info("PKG2F : %s" % pkg2.myfunct())
+"""
+        client.save({"conanfile.py": conanfile})
+        client.run("create . Consumer/0.1@lasote/testing")
+        self.assertIn("Consumer/0.1@lasote/testing: PKG1 : 123", client.out)
+        self.assertIn("Consumer/0.1@lasote/testing: PKG2 : 234", client.out)
+        self.assertIn("Consumer/0.1@lasote/testing: PKG1F : 123", client.out)
+        self.assertIn("Consumer/0.1@lasote/testing: PKG2F : 234", client.out)
+
     def local_import_test(self):
         client = TestClient(servers={"default": TestServer()},
                             users={"default": [("lasote", "mypass")]})