From 2087c77cc159302e4713a14db23def5bd392466d Mon Sep 17 00:00:00 2001 From: memsharded Date: Thu, 17 Aug 2023 19:08:08 +0200 Subject: [PATCH 1/2] resolve version ranges for editables too --- conans/client/graph/range_resolver.py | 1 + .../editable/test_editable_ranges.py | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 conans/test/integration/editable/test_editable_ranges.py diff --git a/conans/client/graph/range_resolver.py b/conans/client/graph/range_resolver.py index 6c0ea17d33a..0d374fc928e 100644 --- a/conans/client/graph/range_resolver.py +++ b/conans/client/graph/range_resolver.py @@ -54,6 +54,7 @@ def _resolve_local(self, search_ref, version_range): # TODO: This is still necessary to filter user/channel, until search_recipes is fixed local_found = [ref for ref in local_found if ref.user == search_ref.user and ref.channel == search_ref.channel] + local_found.extend(self._cache.editable_packages.edited_refs) self._cached_cache[pattern] = local_found if local_found: return self._resolve_version(version_range, local_found, self._resolve_prereleases) diff --git a/conans/test/integration/editable/test_editable_ranges.py b/conans/test/integration/editable/test_editable_ranges.py new file mode 100644 index 00000000000..cdf77a6a14f --- /dev/null +++ b/conans/test/integration/editable/test_editable_ranges.py @@ -0,0 +1,27 @@ +from conans.test.assets.genconanfile import GenConanfile +from conans.test.utils.tools import TestClient + + +def test_editable_ranges(): + c = TestClient() + c.save({"dep/conanfile.py": GenConanfile("dep"), + "dep2/conanfile.py": GenConanfile("dep", "0.2"), + "app/conanfile.py": GenConanfile("app", "0.1").with_requires("dep/[>=0.1]")}) + c.run("editable add dep --version=0.1") + c.run("install app") + c.assert_listed_require({"dep/0.1": "Editable"}) + assert "dep/[>=0.1]: dep/0.1" in c.out + + # new version, uses new one + c.run("editable add dep2") + c.run("install app") + c.assert_listed_require({"dep/0.2": "Editable"}) + assert "dep/[>=0.1]: dep/0.2" in c.out + assert "dep/0.1" not in c.out + + # If a newer one is in cache, it resolves to cache + c.run("create dep --version=0.3") + c.run("install app") + c.assert_listed_require({"dep/0.3": "Cache"}) + assert "dep/[>=0.1]: dep/0.3" in c.out + assert "dep/0.1" not in c.out From 7047b9eb9849c4d8606d8818491190c3979fc83f Mon Sep 17 00:00:00 2001 From: memsharded Date: Thu, 17 Aug 2023 23:21:12 +0200 Subject: [PATCH 2/2] fix editable matches --- conans/client/graph/range_resolver.py | 4 +++- conans/test/integration/editable/test_editable_ranges.py | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/conans/client/graph/range_resolver.py b/conans/client/graph/range_resolver.py index 0d374fc928e..a4ac66eb99f 100644 --- a/conans/client/graph/range_resolver.py +++ b/conans/client/graph/range_resolver.py @@ -54,7 +54,9 @@ def _resolve_local(self, search_ref, version_range): # TODO: This is still necessary to filter user/channel, until search_recipes is fixed local_found = [ref for ref in local_found if ref.user == search_ref.user and ref.channel == search_ref.channel] - local_found.extend(self._cache.editable_packages.edited_refs) + local_found.extend(r for r in self._cache.editable_packages.edited_refs + if r.name == search_ref.name and r.user == search_ref.user + and r.channel == search_ref.channel) self._cached_cache[pattern] = local_found if local_found: return self._resolve_version(version_range, local_found, self._resolve_prereleases) diff --git a/conans/test/integration/editable/test_editable_ranges.py b/conans/test/integration/editable/test_editable_ranges.py index cdf77a6a14f..7b664ad96f3 100644 --- a/conans/test/integration/editable/test_editable_ranges.py +++ b/conans/test/integration/editable/test_editable_ranges.py @@ -6,8 +6,11 @@ def test_editable_ranges(): c = TestClient() c.save({"dep/conanfile.py": GenConanfile("dep"), "dep2/conanfile.py": GenConanfile("dep", "0.2"), + "other/conanfile.py": GenConanfile("other", "23.0"), # shouldn't be resolved! "app/conanfile.py": GenConanfile("app", "0.1").with_requires("dep/[>=0.1]")}) - c.run("editable add dep --version=0.1") + c.run("editable add other") # This shouldn't be used + c.run("editable add dep --version=0.1") # this should be used + c.run("editable add dep --version=2.0 --user=myuser --channel=mychannel") # This shouldn't be used c.run("install app") c.assert_listed_require({"dep/0.1": "Editable"}) assert "dep/[>=0.1]: dep/0.1" in c.out