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

[Bugfix] Option --require-override is not working for conanfile.txt #10013

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion conans/client/graph/graph_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def _load_root_consumer(self, path, graph_lock, profile, ref, require_overrides)
ref.user, ref.channel, validate=False)
root_node = Node(ref, conanfile, context=CONTEXT_HOST, recipe=RECIPE_CONSUMER, path=path)
else:
conanfile = self._loader.load_conanfile_txt(path, profile, ref=ref)
conanfile = self._loader.load_conanfile_txt(path, profile, ref=ref,
require_overrides=require_overrides)
root_node = Node(None, conanfile, context=CONTEXT_HOST, recipe=RECIPE_CONSUMER,
path=path)

Expand Down
8 changes: 7 additions & 1 deletion conans/client/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,20 @@ def load_conanfile(self, conanfile_path, profile, ref, lock_python_requires=None
except Exception as e: # re-raise with file name
raise ConanException("%s: %s" % (conanfile_path, str(e)))

def load_conanfile_txt(self, conan_txt_path, profile_host, ref=None):
def load_conanfile_txt(self, conan_txt_path, profile_host, ref=None, require_overrides=None):
if not os.path.exists(conan_txt_path):
raise NotFoundException("Conanfile not found!")

contents = load(conan_txt_path)
path, basename = os.path.split(conan_txt_path)
display_name = "%s (%s)" % (basename, ref) if ref and ref.name else basename
conanfile = self._parse_conan_txt(contents, path, display_name, profile_host)

if require_overrides is not None:
for req_override in require_overrides:
req_override = ConanFileReference.loads(req_override)
conanfile.requires.override(req_override)

return conanfile

def _parse_conan_txt(self, contents, path, display_name, profile):
Expand Down
11 changes: 11 additions & 0 deletions conans/test/integration/command/install/install_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ def test_install_cli_override(self, client):
client.run("install . --require-override=zlib/2.0")
assert "zlib/2.0: Already installed" in client.out

def test_install_cli_override_in_conanfile_txt(self, client):
client.save({"conanfile.py": GenConanfile()})
client.run("create . zlib/1.0@")
client.run("create . zlib/2.0@")
client.save({"conanfile.txt": textwrap.dedent("""\
[requires]
zlib/1.0
""")}, clean_first=True)
client.run("install . --require-override=zlib/2.0")
assert "zlib/2.0: Already installed" in client.out

def test_install_ref_cli_override(self, client):
client.save({"conanfile.py": GenConanfile()})
client.run("create . zlib/1.0@")
Expand Down