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

Change How App Templates Are Updated for sam init #1678

Merged
merged 17 commits into from
Dec 20, 2019

Conversation

awood45
Copy link
Member

@awood45 awood45 commented Dec 17, 2019

This was initially triggered by a need to support silent updates for the IDEs using --no-interactive as an option for init. To properly handle that, while still handling cases where a user might have issues copying the new init templates down for some reason (internet connections, possibly file permissions), this PR now changes our general approach for copying app templates.

Now, we use a sort of state machine logic - we use a temp directory to stage the git clone of the app templates repo, deleting and copying over the new repo as appropriate to the AWS SAM shared directory. If the clone fails, no change is made and the existing app templates copy is preserved.

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

Possible challenge - no escape hatch to NOT update if not desired. Could
be worth a larger refactor.
@awood45
Copy link
Member Author

awood45 commented Dec 17, 2019

Hold on this PR, going for a deeper approach.

Unit and integ tests still need to be updated, but this change allows us
to drop the prompt to update app templates, and will safely handle edge
cases that previously required us to prompt on, for example, updated.
Separates into two logical submethods. Still need to completely overhaul
init unit and integ tests as a result of the change to the user flow.
Also, black formatting updates.
New tests cover most of this ground, and integ tests definitely
do. Removing tests with side effects.
Too long for linter
@awood45 awood45 changed the title By Default Update Templates in No-Interactive Init Change How App Templates Are Updated for sam init Dec 19, 2019
)
# Now we need to delete the old repo and move this one.
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: can we move this try except block which is inside another try except block to another method, helps with readability.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in new version.

click.echo("WARN: Could not clone app template repo.")

def _clone_new_app_templates(self, shared_dir, expected_path):
with osutils.mkdir_temp(ignore_errors=True) as tempdir:
Copy link
Contributor

Choose a reason for hiding this comment

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

if we are using ignore_errors, i also suggest we add a callback for onerror to log a debug message.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in latest change

self.clone_attempted = True

def _template_directory_exists(self, expected_path):
path = Path(expected_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit/non-blocking: I notice we are using both pathlib and os.path, is it possible to standardize on one or other.

@awood45 awood45 merged commit 23d2449 into aws:develop Dec 20, 2019
@awood45 awood45 deleted the update-in-non-interactive-init branch December 20, 2019 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants