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

feat: SAM Init interactive flow redesign #3410

Merged
merged 13 commits into from
Dec 18, 2021
Merged

Conversation

jonife
Copy link
Contributor

@jonife jonife commented Oct 26, 2021

Which issue(s) does this change fix?

Why is this change necessary?

Improve the user experience on the sam init interactive experience. Today we "hide" the types of app we support through a layer of questions (custom or pre made examples, Package type for lambda, what runtime, then show apps). While this works, we are moving to the idea of surfacing what examples we have first.

The new flow is something like:

custom or pre-made ---> here are the types of examples we have ----> from that list here are the package types ---> from that here are the runtimes.

How does it address the issue?

Improve the user experience on the sam init interactive experience

What side effects does this change have?

Changed the entire cli interactive flow

Checklist

  • Write unit tests
  • Write/update integration tests
  • make pr passes

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@mndeveci mndeveci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left small comments for now but I want to test this locally and give more detailed feedback later.

runtime = _get_runtime(runtime)
dependency_manager = _get_dependency_manager(dependency_manager, runtime)
templates = InitTemplates()
filter_value = runtime if runtime else base_image
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 comments;

  1. Let's rename the filter_value to something more meaningful
  2. What happens if runtime and base_image is None?

Comment on lines 209 to 210
except KeyError as ex:
raise InvalidInitOptionException(f"Lambda Runtime {runtime} is not supported for {use_case} examples.") from ex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use exception driven development. This could easily change with another missing key on another dict. Please be explicit about which line can throw this.


try:
dependency_manager_options = package_types_options[package_type]
except KeyError as ex:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto. Please explicitly check the invalid case rather than raising an exception on KeyError

choice = click.prompt("Runtime", type=click.Choice(choices), show_choices=False)
runtime = INIT_RUNTIMES[int(choice) - 1] # zero index
return runtime
def _generate_default_hello_world_application(use_case, package_type, runtime, dependency_manager, pt_explicit):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add documentation for these new methods?

@jonife jonife marked this pull request as ready for review November 30, 2021 17:53
@jonife jonife requested review from mndeveci and hawflau November 30, 2021 17:53
def get_template_value(value, template):
if value not in template:
raise InvalidInitTemplateError(
f"Template is missing the value for {value} in manifest file. Please raise a a github issue."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is it possible to include the url to raise an issue?

return (runtime, package_type, dependency_manager, pt_explicit)


def _get_app_template_properties(preprocessed_options, use_case, base_image, template_properties):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some nice documentation for some of the methods, but some are missing. Can we add documentation for the ones that is not obvious what they are doing?

Comment on lines 241 to 243
(app_template and app_template != template["appTemplate"])
or (package_type and package_type != template["packageType"])
or (dependency_manager and dependency_manager != template["dependencyManager"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(app_template and app_template != template["appTemplate"])
or (package_type and package_type != template["packageType"])
or (dependency_manager and dependency_manager != template["dependencyManager"])
(app_template and app_template != template.get("appTemplate"))
or (package_type and package_type != template.get("packageType"))
or (dependency_manager and dependency_manager != template.get("dependencyManager"))

qingchm and others added 2 commits December 17, 2021 15:07
* (fix) stop resolve relative paths for function imageUri

* fix unit testing
@mndeveci mndeveci merged commit 4d250ce into aws:develop Dec 18, 2021
moelasmar added a commit to moelasmar/aws-sam-cli that referenced this pull request Dec 22, 2021
* SAM INIT Update

* resolved conflict

* test added and updated

* block default prompt when Image packageType is provide and skip use case prompt when --app-template is provided

* update default hello world prompt

* filtering updates

* added typing

* Fixing failed canaries (aws#3532)

* (fix) stop resolving relative paths for Function image URI (aws#3531)

* (fix) stop resolve relative paths for function imageUri

* fix unit testing

* update template_does_not_meet_filter_criteria use <dict>.get

Co-authored-by: Mehmet Nuri Deveci <[email protected]>
Co-authored-by: Qingchuan Ma <[email protected]>
Co-authored-by: Mohamed Elasmar <[email protected]>
mndeveci added a commit to mndeveci/aws-sam-cli that referenced this pull request Apr 5, 2022
* SAM INIT Update

* resolved conflict

* test added and updated

* block default prompt when Image packageType is provide and skip use case prompt when --app-template is provided

* update default hello world prompt

* filtering updates

* added typing

* Fixing failed canaries (aws#3532)

* (fix) stop resolving relative paths for Function image URI (aws#3531)

* (fix) stop resolve relative paths for function imageUri

* fix unit testing

* update template_does_not_meet_filter_criteria use <dict>.get

Co-authored-by: Mehmet Nuri Deveci <[email protected]>
Co-authored-by: Qingchuan Ma <[email protected]>
Co-authored-by: Mohamed Elasmar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants