Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,17 @@ def run_bicep_command(cli_ctx, args, auto_install=True, custom_env=None):


def ensure_bicep_installation(cli_ctx, release_tag=None, target_platform=None, stdout=True):
if _use_binary_from_path(cli_ctx):
if _use_binary_from_path(cli_ctx) and release_tag is None:
# Only use the Bicep executable from PATH when no specific version is requested.
from shutil import which

if which("bicep") is None:
raise ValidationError(
'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
)

_logger.debug("Using Bicep CLI from PATH.")

return

system = platform.system()
Expand All @@ -131,11 +134,13 @@ def ensure_bicep_installation(cli_ctx, release_tag=None, target_platform=None, s

if os.path.isfile(installation_path):
if not release_tag:
print(f"Bicep CLI is already installed at '{installation_path}'. Skipping installation as no specific version was requested.") # pylint: disable=line-too-long
return

installed_version = _get_bicep_installed_version(installation_path)
target_version = _extract_version(release_tag)
if installed_version and target_version and installed_version == target_version:
print(f"Bicep CLI {installed_version} is already installed at '{installation_path}'.")
return

installation_dir = os.path.dirname(installation_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_use_bicep_cli_from_path_false_after_install(
response.read.return_value = b"test"
urlopen_stub.return_value = response

user_binary_from_path_stub.return_value = False
user_binary_from_path_stub.return_value = True
get_use_binary_from_path_config_stub.return_value = "if_found_in_ci"

# Act
Expand Down Expand Up @@ -206,13 +206,13 @@ def test_ensure_bicep_installation_skip_download_if_installed_version_matches_re
@mock.patch("azure.cli.command_modules.resource._bicep.get_use_binary_from_path_config")
@mock.patch("azure.cli.command_modules.resource._bicep._get_bicep_installation_path")
@mock.patch("shutil.which")
def test_ensure_bicep_installation_skip_download_if_use_binary_from_path_is_true(
def test_ensure_bicep_installation_skip_download_if_use_binary_from_path_is_true_and_no_version_is_specified(
self, which_stub, _get_bicep_installation_path_mock, get_use_binary_from_path_config_stub
):
which_stub.return_value = True
get_use_binary_from_path_config_stub.return_value = "true"

ensure_bicep_installation(self.cli_ctx, release_tag="v0.1.0")
ensure_bicep_installation(self.cli_ctx, release_tag=None)

_get_bicep_installation_path_mock.assert_not_called()

Expand Down
Loading