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
9 changes: 8 additions & 1 deletion samcli/commands/_utils/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ class ExperimentalFlag:
"experimentalTerraformSupport", EXPERIMENTAL_ENV_VAR_PREFIX + "TERRAFORM_SUPPORT"
)
}
RustCargoLambda = ExperimentalEntry("experimentalCargoLambda", EXPERIMENTAL_ENV_VAR_PREFIX + "RUST_CARGO_LAMBDA")
# CargoLambda is no longer experimental - always enabled
CargoLambda = ExperimentalEntry(
"experimentalCargoLambda", EXPERIMENTAL_ENV_VAR_PREFIX + "CARGO_LAMBDA", persistent=True
)


def is_experimental_enabled(config_entry: ExperimentalEntry) -> bool:
"""Whether a given experimental flag is enabled or not.
If experimentalAll is set to True, then it will always return True.
If the config_entry has persistent=True, it will always return True.

Parameters
----------
Expand All @@ -71,6 +75,9 @@ def is_experimental_enabled(config_entry: ExperimentalEntry) -> bool:
bool
Whether the experimental flag is enabled or not.
"""
# Persistent flags are always enabled (graduated from experimental)
if config_entry.persistent:
return True
gc = GlobalConfig()
enabled = gc.get_value(config_entry, default=False, value_type=bool, is_flag=True)
if not enabled:
Expand Down
21 changes: 0 additions & 21 deletions samcli/commands/build/build_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import click

from samcli.commands._utils.constants import DEFAULT_BUILD_DIR
from samcli.commands._utils.experimental import ExperimentalFlag, prompt_experimental
from samcli.commands._utils.template import (
get_template_data,
move_template,
Expand Down Expand Up @@ -281,7 +280,6 @@ def run(self) -> None:
)

self._check_exclude_warning()
self._check_rust_cargo_experimental_flag()

for f in self.get_resources_to_build().functions:
EventTracker.track_event(EventName.BUILD_FUNCTION_RUNTIME.value, f.runtime)
Expand Down Expand Up @@ -696,25 +694,6 @@ def _check_exclude_warning(self) -> None:
if self._resource_identifier in excludes:
LOG.warning(self._EXCLUDE_WARNING_MESSAGE)

def _check_rust_cargo_experimental_flag(self) -> None:
"""
Prints warning message and confirms if user wants to use beta feature
"""
WARNING_MESSAGE = (
'Build method "rust-cargolambda" is a beta feature.\n'
"Please confirm if you would like to proceed\n"
'You can also enable this beta feature with "sam build --beta-features".'
)
resources_to_build = self.get_resources_to_build()
is_building_rust = False
for function in resources_to_build.functions:
if function.metadata and function.metadata.get("BuildMethod", "") == "rust-cargolambda":
is_building_rust = True
break

if is_building_rust:
prompt_experimental(ExperimentalFlag.RustCargoLambda, WARNING_MESSAGE)

@property
def build_in_source(self) -> Optional[bool]:
return self._build_in_source
2 changes: 1 addition & 1 deletion tests/integration/buildcmd/build_integ_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ def _test_with_rust_cargo_lambda(
overrides = self.get_override(runtime, code_uri, architecture, handler)
if binary:
overrides["Binary"] = binary
cmdlist = self.get_command_list(use_container=use_container, parameter_overrides=overrides, beta_features=True)
cmdlist = self.get_command_list(use_container=use_container, parameter_overrides=overrides)

newenv = os.environ.copy()
if build_mode:
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/commands/_utils/test_experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,33 @@ def tearDown(self):

def test_is_experimental_enabled(self):
config_entry = MagicMock()
config_entry.persistent = False
self.gc_mock.return_value.get_value.side_effect = [False, True]
result = is_experimental_enabled(config_entry)
self.assertTrue(result)

def test_is_experimental_enabled_all(self):
config_entry = MagicMock()
config_entry.persistent = False
self.gc_mock.return_value.get_value.side_effect = [True, False]
result = is_experimental_enabled(config_entry)
self.assertTrue(result)

def test_is_experimental_enabled_false(self):
config_entry = MagicMock()
config_entry.persistent = False
self.gc_mock.return_value.get_value.side_effect = [False, False]
result = is_experimental_enabled(config_entry)
self.assertFalse(result)

def test_is_experimental_enabled_persistent(self):
config_entry = MagicMock()
config_entry.persistent = True
result = is_experimental_enabled(config_entry)
self.assertTrue(result)
# GlobalConfig should not be called for persistent flags
self.gc_mock.return_value.get_value.assert_not_called()

def test_set_experimental(self):
config_entry = MagicMock()
set_experimental(config_entry, False)
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/commands/buildcmd/test_build_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,14 +1254,12 @@ def test_must_catch_function_not_found_exception(
@patch("samcli.commands.build.build_context.BuildContext._is_sam_template")
@patch("samcli.commands.build.build_context.BuildContext.get_resources_to_build")
@patch("samcli.commands.build.build_context.BuildContext._check_exclude_warning")
@patch("samcli.commands.build.build_context.BuildContext._check_rust_cargo_experimental_flag")
@patch("samcli.lib.build.app_builder.ApplicationBuilder.build")
@patch("samcli.lib.telemetry.event.EventTracker.track_event")
def test_build_in_source_event_sent(
self,
mock_track_event,
mock_builder,
mock_rust,
mock_warning,
mock_get_resources,
mock_is_sam_template,
Expand Down
Loading