Repository: conan-io/conan

Issue:
Use of python_requires with enabled short_paths fails
In Windows conan fails when a recipe uses `python_requires` and `short_paths = True` at the same time.

To reproduce the issue, it's enough to just add `short_paths = True` into the consumer conanfile of the `python_requires` example.

Conan will end with
```
ERROR: Error while trying to get recipe sources for pyreq/version@user/channel. No remote defined
```


Discussion:
Hi @kdsx,
I was able to reproduce the issue when using `export_sources` in the `python_requires`
While we have a look at it, did you try to set the `short_paths = True` in the python requires as well?

Thanks a lot for the feedback
Hi @czoido,
I've already tried it. Unfortunately with no effect. Conan fails with the same message.
Hi!

I haven't been able to reproduce it, please @czoido share a unit test that can reproduce it.

That error message typically appears when a package is downloaded from a remote, then the remote is removed (and the necessary sources aren't there), so when the package need the sources it fails. It is not that directly related to short_paths, but to the remote removal. So any help with more detailed steps to reproduce will help. Thanks!
In my case it happened for a package which exists only in the local cache and has never been to a remote server. Then for simplicity I've reproduced it on the mentioned conan example. In contrast to the example my package does not use `exports_sources`, only `exports` which appear in the local cache in the same directory as `conanfile.py`, thus it should not require any additional sources to download.

I use the latest conan version at the moment (1.18.5) on Windows 10. I doubt it's important, but I run conan from cygwin environment, however conan itself installed by `pip` into `venv` generated by a native (non-cygwin) version of Python 3.
I've looked into code a bit and found that when conan installs the dependencies (including pyreq) it calls `_build_package` and then `complete_recipe_sources` for every dependency and the package itself. In the very beginning it tries to find the sources folder and then retrieve it if it is not available. The problem is probably here:
```
sources_folder = cache.package_layout(ref, conanfile.short_paths).export_sources()
```
It requests the source folder for the package `ref` (which is `pyreq`), but provides `short_paths` flag for the package `conanfile` which is `consumer`. Since `pyreq` does not have `shot_paths` flag, its sources were exported to the normal location, but `sources_folder` here points to a short path which even does not exist.

What is interesting, when I specify `short_paths` for `pyreq` too, it still does not work! When I create `pyreq` package, its `complete_recipe_sources` gets `conanfile.short_paths == False` and sources are still exported to their normal (non-short) location. Furthermore its "short" folder is created, but contains only `real_path.txt` which points to "long" folder. Thus when `complete_recipe_sources` is called from `consumer` context for `pyreq` it still can't find the sources directory.
Thanks a lot for reporting the bug @kdsx 
I have just made a PR that should fix the problem :)
The fix in the PR helped me, thanks!
Merged! Will be in Conan 1.20

Resolving patch:
diff --git a/conans/client/installer.py b/conans/client/installer.py
--- a/conans/client/installer.py
+++ b/conans/client/installer.py
@@ -427,7 +427,7 @@ def _build_package(self, node, output, keep_build, remotes):
             assert python_require.ref.revision is not None, \
                 "Installer should receive python_require.ref always"
             complete_recipe_sources(self._remote_manager, self._cache,
-                                    conanfile, python_require.ref, remotes)
+                                    python_require.conanfile, python_require.ref, remotes)
 
         builder = _PackageBuilder(self._cache, output, self._hook_manager, self._remote_manager)
         pref = builder.build_package(node, keep_build, self._recorder, remotes)


Test patch:
diff --git a/conans/test/functional/python_requires/python_requires_test.py b/conans/test/functional/python_requires/python_requires_test.py
--- a/conans/test/functional/python_requires/python_requires_test.py
+++ b/conans/test/functional/python_requires/python_requires_test.py
@@ -576,6 +576,32 @@ class Lib(ConanFile):
         self.assertIn("Same python_requires with different versions not allowed for a conanfile",
                       t.out)
 
+    def short_paths_test(self):
+        # https://github.com/conan-io/conan/issues/5814
+        client = TestClient(default_server_user=True)
+        conanfile = textwrap.dedent("""
+        from conans import ConanFile
+        class MyConanfileBase(ConanFile):
+            exports = "*.txt"
+            exports_sources = "*.h"
+        """)
+        client.save({"conanfile.py": conanfile,
+                     "file.h": "header",
+                     "other.txt": "text"})
+        client.run("create . Base/1.2@lasote/testing")
+
+        reuse = textwrap.dedent("""
+        from conans import python_requires
+        base = python_requires("Base/1.2@lasote/testing")
+        class PkgTest(base.MyConanfileBase):
+            short_paths = True
+            name = "consumer"
+            version = "1.0.0"
+        """)
+        client.save({"conanfile.py": reuse}, clean_first=True)
+        client.run("create . lasote/testing")
+        self.assertIn("consumer/1.0.0@lasote/testing: Created package revision", client.out)
+
 
 class PythonRequiresNestedTest(unittest.TestCase):