-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(build): Move workflow config information into its own file (#…
- Loading branch information
Showing
8 changed files
with
133 additions
and
100 deletions.
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") |