Skip to content

Commit 322e3ed

Browse files
committed
Check use_binary_from_path in ensure_bicep_installation
1 parent 46fc028 commit 322e3ed

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/azure-cli/azure/cli/command_modules/resource/_bicep.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ def run_bicep_command(cli_ctx, args, auto_install=True, custom_env=None):
108108

109109

110110
def ensure_bicep_installation(cli_ctx, release_tag=None, target_platform=None, stdout=True):
111+
if _use_binary_from_path(cli_ctx):
112+
from shutil import which
113+
114+
if which("bicep") is None:
115+
raise ValidationError(
116+
'Could not find the "bicep" executable on PATH. To install Bicep via Azure CLI, set the "bicep.use_binary_from_path" configuration to False and run "az bicep install".' # pylint: disable=line-too-long
117+
)
118+
119+
return
120+
111121
system = platform.system()
112122
machine = platform.machine()
113123
installation_path = _get_bicep_installation_path(system)

src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ def test_ensure_bicep_installation_skip_download_if_installed_version_matches_re
163163
ensure_bicep_installation(self.cli_ctx, release_tag="v0.1.0")
164164

165165
dirname_mock.assert_not_called()
166+
167+
@mock.patch("azure.cli.command_modules.resource._bicep._get_bicep_installation_path")
168+
@mock.patch("shutil.which")
169+
def test_ensure_bicep_installation_skip_download_if_use_binary_from_path_is_true(
170+
self, which_stub, _get_bicep_installation_path_mock
171+
):
172+
which_stub.return_value = True
173+
self.cli_ctx.config.set_value("bicep", "use_binary_from_path", "true")
174+
175+
ensure_bicep_installation(self.cli_ctx, release_tag="v0.1.0")
176+
177+
_get_bicep_installation_path_mock.assert_not_called()
166178

167179
def test_validate_target_scope_raise_error_if_target_scope_does_not_match_deployment_scope(self):
168180
with self.assertRaisesRegex(

0 commit comments

Comments
 (0)