Skip to content

Commit

Permalink
Merge pull request #443 from dgraeber/feature/cdkv2-module-init
Browse files Browse the repository at this point in the history
adding support for cdkv2 prototype in init of modules
  • Loading branch information
dgraeber authored Oct 25, 2023
2 parents 510c08b + df36fde commit 9cc7705
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a Ch
### New

### Changes
- adding support for module-type spec on init of new module `seedfarmer init module -mt cdkv2`

### Fixes

Expand Down
11 changes: 10 additions & 1 deletion seedfarmer/cli_groups/_init_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def init_project(template_url: str) -> None:
default=None,
)
@click.option("--module-name", "-m", type=str, help="The module name", required=True)
@click.option(
"--module-type",
"-mt",
type=str,
help="The type of module code deployed...only 'cdkv2' is accepted if used here",
required=False,
default=None,
)
@click.option(
"--template-url",
"-t",
Expand All @@ -63,13 +71,14 @@ def init_project(template_url: str) -> None:
required=False,
)
@click.option("--debug/--no-debug", default=False, help="Enable detail logging", show_default=True)
def init_module(group_name: str, module_name: str, template_url: str, debug: bool) -> None:
def init_module(group_name: str, module_name: str, module_type: str, template_url: str, debug: bool) -> None:
if debug:
enable_debug(format=DEBUG_LOGGING_FORMAT)
_logger.debug("Initializing module %s", module_name)

minit.create_module_dir(
group_name=group_name,
module_name=module_name,
module_type=module_type,
template_url=template_url,
)
12 changes: 9 additions & 3 deletions seedfarmer/mgmt/module_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,22 @@
_logger: logging.Logger = logging.getLogger(__name__)


def create_module_dir(module_name: str, group_name: Optional[str], template_url: Optional[str]) -> None:
def create_module_dir(
module_name: str, group_name: Optional[str], module_type: Optional[str], template_url: Optional[str]
) -> None:
"""Initializes a directory for a new module.
Creates a new directory that contains files that will aid in setting up a development environment
Parameters
----------
group_name : str
group_name : Optional[str],
Nmae of the group where the module will reside. If group is a nested dir, use `/` as a delimiter
module_name : str
Name of the module. The initialization will include project files pulled from the template_url
module_type: Optional[str]
They type of code the module deploys with, adding more boilerplate code
-- only cdkv2 is supported here
template_url : Optional[List[str]]
A URL, for example a Github repo, that is or contains templating for the initialization
"""
Expand All @@ -53,7 +58,8 @@ def create_module_dir(module_name: str, group_name: Optional[str], template_url:
if os.path.exists(module_path):
raise seedfarmer.errors.InvalidPathError(f"The module {module_name} already exists under {output_dir}.")

checkout_branch = "init-module" if template_url == "https://github.com/awslabs/seed-farmer.git" else None
if template_url == "https://github.com/awslabs/seed-farmer.git":
checkout_branch = "init-module-cdkv2" if module_type == "cdkv2" else "init-module"

_logger.info("New module will be created in the following dir: %s", output_dir)
cookiecutter(
Expand Down
25 changes: 23 additions & 2 deletions test/unit-test/test_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,33 @@ def test_module_init():
import seedfarmer.mgmt.module_init as mi

mi.create_module_dir(
module_name="mytestmodule", group_name="mygroup", template_url="https://github.com/awslabs/seed-farmer.git"
module_name="mytestmodule", group_name="mygroup", module_type=None, template_url="https://github.com/awslabs/seed-farmer.git"
)

with pytest.raises(Exception) as e:
mi.create_module_dir(
module_name="mytestmodule", group_name="mygroup", template_url="https://github.com/awslabs/seed-farmer.git"
module_name="mytestmodule", group_name="mygroup", module_type=None, template_url="https://github.com/awslabs/seed-farmer.git"
)

assert "module mytestmodule already exists" in str(e)

shutil.rmtree(setup_mod_dir)

@pytest.mark.mgmt
def test_module_init_cdkv2():
setup_mod_dir = os.path.join(pathlib.Path(os.getcwd()), "modules")

if os.path.isdir(setup_mod_dir):
shutil.rmtree(setup_mod_dir)
import seedfarmer.mgmt.module_init as mi

mi.create_module_dir(
module_name="mytestmodule", group_name="mygroup", module_type="cdkv2", template_url="https://github.com/awslabs/seed-farmer.git"
)

with pytest.raises(Exception) as e:
mi.create_module_dir(
module_name="mytestmodule", group_name="mygroup", module_type="cdkv2", template_url="https://github.com/awslabs/seed-farmer.git"
)

assert "module mytestmodule already exists" in str(e)
Expand Down

0 comments on commit 9cc7705

Please sign in to comment.