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

Add in operator support for ConanFile's self.dependencies #15221

Merged
merged 2 commits into from
Dec 7, 2023
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
11 changes: 11 additions & 0 deletions conans/model/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ def items(self):
def values(self):
return self._data.values()

def __contains__(self, item):
try:
self.get(item)
return True
except KeyError:
return False
except ConanException:
# ConanException is raised when there are more than one matching the filters
# so it's definitely in the dict
return True


class ConanFileDependencies(UserRequirementsDict):

Expand Down
21 changes: 21 additions & 0 deletions conans/test/integration/graph/test_dependencies_visit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ def generate(self):
self.output.info("DefPRefBuild: {}!!!".format(dep.pref.repr_notime()))
for r, d in self.dependencies.build.items():
self.output.info("DIRECTBUILD {}: {}".format(r.direct, d))

if "openssl" in self.dependencies:
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
self.output.info("OpenSSL found in deps")

if "cmake" in self.dependencies:
self.output.info("cmake found in default deps")

if "cmake" in self.dependencies.build:
self.output.info("cmake found in deps.build")

if "badlib" in self.dependencies:
self.output.info("badlib found in deps")
""")
client.save({"conanfile.py": conanfile})

Expand All @@ -48,6 +60,12 @@ def generate(self):
assert "conanfile.py: DIRECTBUILD True: cmake/0.1" in client.out
assert "conanfile.py: DIRECTBUILD False: openssl/0.2" in client.out

assert "OpenSSL found in deps" in client.out
assert "badlib found in deps" not in client.out

assert "cmake found in default deps" not in client.out
assert "cmake found in deps.build" in client.out


def test_dependencies_visit_settings_options():
client = TestClient()
Expand Down Expand Up @@ -89,6 +107,9 @@ def generate(self):
'- cmake/0.2, Traits: build=True, headers=False, libs=False, run=False, visible=False'
),
('self.dependencies["missing"]', True, "'missing' not found in the dependency set"),
('self.output.info("Missing in deps: " + str("missing" in self.dependencies))', False, "Missing in deps: False"),
('self.output.info("Zlib in deps: " + str("zlib" in self.dependencies))', False, "Zlib in deps: True"),
('self.output.info("Zlib in deps.build: " + str("zlib" in self.dependencies.build))', False, "Zlib in deps.build: True"),
]


Expand Down