Skip to content

Commit 0fd242b

Browse files
authored
fix issues with local-recipes-index in presence of workspace home_folder (#17883)
1 parent 6123543 commit 0fd242b

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

conan/api/conan_api.py

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class ConanAPI:
3232
not be created directly.
3333
"""
3434
def __init__(self, cache_folder=None):
35+
"""
36+
:param cache_folder: Conan cache/home folder. It will have less priority than the
37+
"home_folder" defined in a Workspace.
38+
"""
3539

3640
version = sys.version_info
3741
if version.major == 2 or version.minor < 6:

conan/internal/conan_app.py

+21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import os
22

3+
from conan.internal.api.local.editable import EditablePackages
34
from conan.internal.cache.cache import PkgCache
45
from conan.internal.cache.home_paths import HomePaths
6+
from conan.internal.model.conf import ConfDefinition
57
from conans.client.graph.proxy import ConanProxy
68
from conans.client.graph.python_requires import PyRequireLoader
79
from conans.client.graph.range_resolver import RangeResolver
@@ -69,3 +71,22 @@ def __init__(self, conan_api):
6971
conanfile_helpers = ConanFileHelpers(conan_api.remotes.requester, cmd_wrap, self.global_conf,
7072
self.cache, self.cache_folder)
7173
self.loader = ConanFileLoader(self.pyreq_loader, conanfile_helpers)
74+
75+
76+
class LocalRecipesIndexApp:
77+
"""
78+
Simplified one, without full API, for the LocalRecipesIndex. Only publicly used fields are:
79+
- cache
80+
- loader (for the export phase of local-recipes-index)
81+
The others are internally use by other collaborators
82+
"""
83+
def __init__(self, cache_folder):
84+
self.global_conf = ConfDefinition()
85+
self.cache = PkgCache(cache_folder, self.global_conf)
86+
self.remote_manager = RemoteManager(self.cache, auth_manager=None, home_folder=cache_folder)
87+
editable_packages = EditablePackages()
88+
self.proxy = ConanProxy(self, editable_packages)
89+
self.range_resolver = RangeResolver(self, self.global_conf, editable_packages)
90+
pyreq_loader = PyRequireLoader(self, self.global_conf)
91+
helpers = ConanFileHelpers(None, CmdWrapper(""), self.global_conf, self.cache, cache_folder)
92+
self.loader = ConanFileLoader(pyreq_loader, helpers)

conans/client/rest_client_local_recipe_index.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,9 @@ def __init__(self, remote, home_folder):
6565
local_recipes_index_path = os.path.join(local_recipes_index_path, ".conan")
6666
repo_folder = self._remote.url
6767

68-
from conan.internal.conan_app import ConanApp
69-
from conan.api.conan_api import ConanAPI
70-
conan_api = ConanAPI(local_recipes_index_path)
71-
self._app = ConanApp(conan_api)
72-
self._hook_manager = HookManager(HomePaths(conan_api.home_folder).hooks_path)
68+
from conan.internal.conan_app import LocalRecipesIndexApp
69+
self._app = LocalRecipesIndexApp(local_recipes_index_path)
70+
self._hook_manager = HookManager(HomePaths(local_recipes_index_path).hooks_path)
7371
self._layout = _LocalRecipesIndexLayout(repo_folder)
7472

7573
def call_method(self, method_name, *args, **kwargs):

test/integration/workspace/test_workspace.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from conan.test.utils.scm import create_local_git_repo
1010
from conan.test.utils.test_files import temp_folder
1111
from conan.test.utils.tools import TestClient
12-
from conans.util.files import save
12+
from conans.util.files import save, save_files
1313

1414
WorkspaceAPI.TEST_ENABLED = "will_break_next"
1515

@@ -499,7 +499,6 @@ def root_conanfile(self):
499499
"conanws.py": conanfilews})
500500
c.run("workspace add dep")
501501
c.run("workspace install -of=build")
502-
print(c.out)
503502
files = os.listdir(os.path.join(c.current_folder, "build"))
504503
assert "conandeps.props" in files
505504

@@ -524,3 +523,25 @@ def root_conanfile(self):
524523
c.run("workspace add dep")
525524
c.run("workspace install", assert_error=True)
526525
assert "ERROR: Conanfile in conanws.py shouldn't have 'requires'" in c.out
526+
527+
528+
def test_workspace_with_local_recipes_index():
529+
c3i_folder = temp_folder()
530+
recipes_folder = os.path.join(c3i_folder, "recipes")
531+
zlib_config = textwrap.dedent("""
532+
versions:
533+
"1.2.11":
534+
folder: all
535+
""")
536+
save_files(recipes_folder, {"zlib/config.yml": zlib_config,
537+
"zlib/all/conanfile.py": str(GenConanfile("zlib")),
538+
"zlib/all/conandata.yml": ""})
539+
540+
c = TestClient(light=True)
541+
c.save({"conanws.yml": 'home_folder: "deps"'})
542+
c.run(f'remote add local "{c3i_folder}"')
543+
544+
c.run("list zlib/1.2.11#* -r=local")
545+
assert "zlib/1.2.11" in c.out # It doesn't crash
546+
c.run("list zlib/1.2.11#*")
547+
assert "zlib/1.2.11" not in c.out

0 commit comments

Comments
 (0)