Skip to content

Commit 340bbb7

Browse files
committed
new approach with consistent trait
1 parent a9d8018 commit 340bbb7

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

conan/internal/model/requires.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class Requirement:
99
"""
1010
def __init__(self, ref, *, headers=None, libs=None, build=False, run=None, visible=None,
1111
transitive_headers=None, transitive_libs=None, test=None, package_id_mode=None,
12-
force=None, override=None, direct=None, options=None, no_skip=False):
12+
force=None, override=None, direct=None, options=None, no_skip=False,
13+
consistent=None):
1314
# * prevents the usage of more positional parameters, always ref + **kwargs
1415
# By default this is a generic library requirement
1516
self.ref = ref
@@ -26,6 +27,7 @@ def __init__(self, ref, *, headers=None, libs=None, build=False, run=None, visib
2627
self._force = force
2728
self._override = override
2829
self._direct = direct
30+
self._consistent = consistent
2931
self.options = options
3032
# Meta and auxiliary information
3133
# The "defining_require" is the require that defines the current value. If this require is
@@ -102,6 +104,15 @@ def direct(self):
102104
def direct(self, value):
103105
self._direct = value
104106

107+
@property
108+
def consistent(self):
109+
default_consistent = self.visible or self.test
110+
return self._default_if_none(self._consistent, default_consistent)
111+
112+
@consistent.setter
113+
def consistent(self, value):
114+
self._consistent = value
115+
105116
@property
106117
def build(self):
107118
return self._build
@@ -229,8 +240,7 @@ def __eq__(self, other):
229240
(self.headers and other.headers) or
230241
(self.libs and other.libs) or
231242
(self.run and other.run) or
232-
(self.test and other.test) or
233-
(self.visible or other.visible) or # THIS IS AN OR!!
243+
(self.consistent and other.consistent) or
234244
(self.ref == other.ref and self.options == other.options)))
235245

236246
def aggregate(self, other):
@@ -350,6 +360,8 @@ def transform_downstream(self, pkg_type, require, dep_pkg_type):
350360
# if required.run is not None:
351361
# downstream_require.run = required.run
352362

363+
downstream_require.consistent = require.consistent and self.consistent
364+
353365
if self.test:
354366
downstream_require.test = True
355367

test/integration/graph/conflict_diamond_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,12 @@ def test_visible_order_issue():
399399
.with_requires("lib_a/[>=1]"),
400400
"libc/conanfile.py": GenConanfile("lib_c", "1.0").with_package_type("shared-library")
401401
.with_requirement("lib_b/1.0",
402-
visible=False)
402+
visible=False, consistent=True)
403403
.with_requirement("lib_a/1.1"),
404404
"libc2/conanfile.py": GenConanfile("lib_c", "1.0").with_package_type("shared-library")
405405
.with_requirement("lib_a/1.1")
406406
.with_requirement("lib_b/1.0",
407-
visible=False),
407+
visible=False, consistent=True),
408408
})
409409
c.run("export liba --version=1.0")
410410
c.run("export liba --version=1.1")
@@ -428,12 +428,12 @@ def test_visible_order_full_diamond_issue():
428428
.with_requires("lib_a/1.1"),
429429
"libc/conanfile.py": GenConanfile("lib_c", "1.0").with_package_type("shared-library")
430430
.with_requirement("lib_b/1.0",
431-
visible=False)
431+
visible=False, consistent=True)
432432
.with_requirement("lib_d/1.0"),
433433
"libc2/conanfile.py": GenConanfile("lib_c", "1.0").with_package_type("shared-library")
434434
.with_requirement("lib_d/1.0")
435435
.with_requirement("lib_b/1.0",
436-
visible=False),
436+
visible=False, consistent=True),
437437
})
438438
c.run("export liba --version=1.0")
439439
c.run("export liba --version=1.1")

test/integration/graph/ux/loop_detection_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ def generate(self):
8181
"app/conanfile.py": conanfile})
8282

8383
c.run("create cmake")
84-
c.run("install app", assert_error=True)
85-
# It doesn't hang, and it sees correctly the duplicated dependency
86-
assert "Duplicated requirement: cmake/3.31.6" in c.out
84+
c.run("install app")
85+
# It doesn't hang, and it sees correctly just 1 dependency
86+
assert "conanfile.py (test/1.0): NUM DEPS: 1" in c.out

0 commit comments

Comments
 (0)