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: Initialize a project from non-cookiecutter github repo or zip file #1595

Merged
merged 1 commit into from
Nov 25, 2019

Conversation

sanathkr
Copy link
Contributor

Issue #, if available:

Description of changes:

Checklist:

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

@@ -2,25 +2,4 @@
Helper functions for temporary files
"""
import os
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved these to osutils.py to consolidate all OS related helpers. This is not required for this PR, but I thought it might be a good cleanup to do while I am here

@@ -33,13 +37,13 @@ def test_init_command_passes_and_dir_created(self):
raise

self.assertEqual(process.returncode, 0)
self.assertTrue(os.path.isdir(temp + "/sam-app"))
self.assertTrue(Path(temp, "sam-app").is_dir())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored to remove hardcoded / while I am here

@c2tarun c2tarun self-assigned this Nov 25, 2019
try:
# Let's try to copy the directory metadata from source to destination
shutil.copystat(source, destination)
except OSError 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.

this seems broad to be just windows errors, can we get more granular?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is not even my code. it's copy pasted ;)

if name in ignored_names:
continue

new_source = os.path.join(source, name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I see some parts of the code changing to use pathlib, do we need to do the same here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

eventually. I don't want to change much now


@parameterized.expand([(None,), ("project_name",)])
def test_arbitrary_project(self, project_name):
with tempfile.TemporaryDirectory() as temp:
Copy link
Contributor

Choose a reason for hiding this comment

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

are there any gotchas with temporary directories on windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it didn't break before ;) so no

try:
os.remove(path)
except OSError:
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

This will fail if it throws IsADirectoryError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's only used in a test. I think we should clean this up later.


# NOTE: Py3.8 or higher has a ``dir_exist_ok=True`` parameter to provide this functionality.
# This method can be removed if we stop supporting Py37
def copytree(source, destination, ignore=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is well documented 😉 others are not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because this was copied from lambda-builders :)

Comment on lines +54 to +63
if repository.is_zip_file(location):
LOG.debug("%s location is a zip file", location)
download_fn = functools.partial(
repository.unzip, zip_uri=location, is_url=repository.is_repo_url(location), no_input=no_input
)

# Else, treat it as a git/hg/ssh URL and try to clone
elif repository.is_repo_url(location):
LOG.debug("%s location is a source control repository", location)
download_fn = functools.partial(repository.clone, repo_url=location, no_input=no_input)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, if cookiecutter supports zip and git both, then why do we need two if conditions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because cookiecutter's internal code verifies the presence of cookiecutter.json. we don't want that

Copy link
Contributor

@sriram-mv sriram-mv left a comment

Choose a reason for hiding this comment

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

Apart from my questions, this looks good.

@sanathkr sanathkr merged commit 00345ed into aws:develop Nov 25, 2019
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.

3 participants