-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
refactor(build): Move workflow config information into its own file #1001
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
""" | ||
Contains Builder Workflow Configs for different Runtimes | ||
""" | ||
|
||
from collections import namedtuple | ||
|
||
|
||
CONFIG = namedtuple('Capability', ["language", "dependency_manager", "application_framework", "manifest_name"]) | ||
|
||
PYTHON_PIP_CONFIG = CONFIG( | ||
language="python", | ||
dependency_manager="pip", | ||
application_framework=None, | ||
manifest_name="requirements.txt") | ||
|
||
NODEJS_NPM_CONFIG = CONFIG( | ||
language="nodejs", | ||
dependency_manager="npm", | ||
application_framework=None, | ||
manifest_name="package.json") | ||
|
||
RUBY_BUNDLER_CONFIG = CONFIG( | ||
language="ruby", | ||
dependency_manager="bundler", | ||
application_framework=None, | ||
manifest_name="Gemfile") | ||
|
||
|
||
class UnsupportedRuntimeException(Exception): | ||
pass | ||
|
||
|
||
def get_workflow_config(runtime): | ||
""" | ||
Get a workflow config that corresponds to the runtime provided | ||
|
||
Parameters | ||
---------- | ||
runtime str | ||
The runtime of the config | ||
|
||
Returns | ||
------- | ||
namedtuple(Capability) | ||
namedtuple that represents the Builder Workflow Config | ||
""" | ||
|
||
workflow_config_by_runtime = { | ||
"python2.7": PYTHON_PIP_CONFIG, | ||
"python3.6": PYTHON_PIP_CONFIG, | ||
"python3.7": PYTHON_PIP_CONFIG, | ||
"nodejs4.3": NODEJS_NPM_CONFIG, | ||
"nodejs6.10": NODEJS_NPM_CONFIG, | ||
"nodejs8.10": NODEJS_NPM_CONFIG, | ||
"ruby2.5": RUBY_BUNDLER_CONFIG | ||
} | ||
|
||
try: | ||
return workflow_config_by_runtime[runtime] | ||
except KeyError: | ||
raise UnsupportedRuntimeException("'{}' runtime is not supported".format(runtime)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from unittest import TestCase | ||
from parameterized import parameterized | ||
|
||
from samcli.lib.build.workflow_config import get_workflow_config, UnsupportedRuntimeException | ||
|
||
|
||
class Test_get_workflow_config(TestCase): | ||
|
||
@parameterized.expand([ | ||
("python2.7", ), | ||
("python3.6", ) | ||
]) | ||
def test_must_work_for_python(self, runtime): | ||
|
||
result = get_workflow_config(runtime) | ||
self.assertEquals(result.language, "python") | ||
self.assertEquals(result.dependency_manager, "pip") | ||
self.assertEquals(result.application_framework, None) | ||
self.assertEquals(result.manifest_name, "requirements.txt") | ||
|
||
@parameterized.expand([ | ||
("nodejs4.3", ), | ||
("nodejs6.10", ), | ||
("nodejs8.10", ), | ||
]) | ||
def test_must_work_for_nodejs(self, runtime): | ||
|
||
result = get_workflow_config(runtime) | ||
self.assertEquals(result.language, "nodejs") | ||
self.assertEquals(result.dependency_manager, "npm") | ||
self.assertEquals(result.application_framework, None) | ||
self.assertEquals(result.manifest_name, "package.json") | ||
|
||
@parameterized.expand([ | ||
("ruby2.5", ) | ||
]) | ||
def test_must_work_for_ruby(self, runtime): | ||
result = get_workflow_config(runtime) | ||
self.assertEquals(result.language, "ruby") | ||
self.assertEquals(result.dependency_manager, "bundler") | ||
self.assertEquals(result.application_framework, None) | ||
self.assertEquals(result.manifest_name, "Gemfile") | ||
|
||
def test_must_raise_for_unsupported_runtimes(self): | ||
|
||
runtime = "foobar" | ||
|
||
with self.assertRaises(UnsupportedRuntimeException) as ctx: | ||
get_workflow_config(runtime) | ||
|
||
self.assertEquals(str(ctx.exception), | ||
"'foobar' runtime is not supported") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 💃