Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issues with local-recipes-index in presence of workspace home_folder #17883

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions conan/api/conan_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class ConanAPI:
not be created directly.
"""
def __init__(self, cache_folder=None):
"""
:param cache_folder: Conan cache/home folder. It will have less priority than the
"home_folder" defined in a Workspace.
"""

version = sys.version_info
if version.major == 2 or version.minor < 6:
Expand Down
21 changes: 21 additions & 0 deletions conan/internal/conan_app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os

from conan.internal.api.local.editable import EditablePackages
from conan.internal.cache.cache import PkgCache
from conan.internal.cache.home_paths import HomePaths
from conan.internal.model.conf import ConfDefinition
from conans.client.graph.proxy import ConanProxy
from conans.client.graph.python_requires import PyRequireLoader
from conans.client.graph.range_resolver import RangeResolver
Expand Down Expand Up @@ -69,3 +71,22 @@ def __init__(self, conan_api):
conanfile_helpers = ConanFileHelpers(conan_api.remotes.requester, cmd_wrap, self.global_conf,
self.cache, self.cache_folder)
self.loader = ConanFileLoader(self.pyreq_loader, conanfile_helpers)


class LocalRecipesIndexApp:
"""
Simplified one, without full API, for the LocalRecipesIndex. Only publicly used fields are:
- cache
- loader (for the export phase of local-recipes-index)
The others are internally use by other collaborators
"""
def __init__(self, cache_folder):
self.global_conf = ConfDefinition()
self.cache = PkgCache(cache_folder, self.global_conf)
self.remote_manager = RemoteManager(self.cache, auth_manager=None, home_folder=cache_folder)
editable_packages = EditablePackages()
self.proxy = ConanProxy(self, editable_packages)
self.range_resolver = RangeResolver(self, self.global_conf, editable_packages)
pyreq_loader = PyRequireLoader(self, self.global_conf)
helpers = ConanFileHelpers(None, CmdWrapper(""), self.global_conf, self.cache, cache_folder)
self.loader = ConanFileLoader(pyreq_loader, helpers)
8 changes: 3 additions & 5 deletions conans/client/rest_client_local_recipe_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ def __init__(self, remote, home_folder):
local_recipes_index_path = os.path.join(local_recipes_index_path, ".conan")
repo_folder = self._remote.url

from conan.internal.conan_app import ConanApp
from conan.api.conan_api import ConanAPI
conan_api = ConanAPI(local_recipes_index_path)
self._app = ConanApp(conan_api)
self._hook_manager = HookManager(HomePaths(conan_api.home_folder).hooks_path)
from conan.internal.conan_app import LocalRecipesIndexApp
self._app = LocalRecipesIndexApp(local_recipes_index_path)
self._hook_manager = HookManager(HomePaths(local_recipes_index_path).hooks_path)
self._layout = _LocalRecipesIndexLayout(repo_folder)

def call_method(self, method_name, *args, **kwargs):
Expand Down
25 changes: 23 additions & 2 deletions test/integration/workspace/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from conan.test.utils.scm import create_local_git_repo
from conan.test.utils.test_files import temp_folder
from conan.test.utils.tools import TestClient
from conans.util.files import save
from conans.util.files import save, save_files

WorkspaceAPI.TEST_ENABLED = "will_break_next"

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

Expand All @@ -524,3 +523,25 @@ def root_conanfile(self):
c.run("workspace add dep")
c.run("workspace install", assert_error=True)
assert "ERROR: Conanfile in conanws.py shouldn't have 'requires'" in c.out


def test_workspace_with_local_recipes_index():
c3i_folder = temp_folder()
recipes_folder = os.path.join(c3i_folder, "recipes")
zlib_config = textwrap.dedent("""
versions:
"1.2.11":
folder: all
""")
save_files(recipes_folder, {"zlib/config.yml": zlib_config,
"zlib/all/conanfile.py": str(GenConanfile("zlib")),
"zlib/all/conandata.yml": ""})

c = TestClient(light=True)
c.save({"conanws.yml": 'home_folder: "deps"'})
c.run(f'remote add local "{c3i_folder}"')

c.run("list zlib/1.2.11#* -r=local")
assert "zlib/1.2.11" in c.out # It doesn't crash
c.run("list zlib/1.2.11#*")
assert "zlib/1.2.11" not in c.out