Skip to content

Commit

Permalink
Use copier to generate project config file
Browse files Browse the repository at this point in the history
  • Loading branch information
kalondar committed Dec 7, 2021
1 parent 02b1f9c commit bae8637
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 30 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from setuptools.command.install import install


__version__ = "1.1.35"
__version__ = "1.1.36"

with open("README.md", "r") as fh:
long_description = fh.read()
Expand Down
3 changes: 0 additions & 3 deletions streamingcli/project/jupyter/jupyter_project_factory.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pathlib
import click
import copier
from streamingcli.project.local_project_config import LocalProjectConfigFactory
from streamingcli.project.project_type import ProjectType


JUPYTER_TEMPLATE_PROJECT = "[email protected]:getindata/streaming-labs/flink-sandbox-jupyter.git"
Expand All @@ -21,4 +19,3 @@ def create(project_name: str):
raise click.ClickException("Project directory already exists!")

copier.copy(src_path=JUPYTER_TEMPLATE_PROJECT, dst_path=project_path)
LocalProjectConfigFactory.generate_initial_project_config(project_name, ProjectType.JUPYTER)
25 changes: 3 additions & 22 deletions streamingcli/project/local_project_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
from dataclasses import asdict, dataclass, field
from enum import Enum
from typing import Any, Optional, Type
from typing import Any, Type

import click
from marshmallow_dataclass import class_schema
Expand All @@ -15,7 +14,6 @@ class LocalProjectConfig:
project_name: str
project_version: str
project_type: ProjectType = field(metadata={"by_value": True})
project_configmap_name: Optional[str] = field(default=None)
dependencies: list = field(default_factory=lambda: [])

def add_dependency(self, dependency_path):
Expand All @@ -33,31 +31,14 @@ def convert_value(obj):


class LocalProjectConfigFactory:
DEFAULT_PROJECT_VERSION = "v1.0"

@staticmethod
def generate_initial_project_config(project_name: str, project_type: ProjectType):
configmap_name = LocalProjectConfigFactory.format_project_configmap_name(project_name)
config = LocalProjectConfig(project_name=project_name,
project_version=LocalProjectConfigFactory.DEFAULT_PROJECT_VERSION,
project_type=project_type,
project_configmap_name=configmap_name)
LocalProjectConfigIO.save_project_config(config)

@staticmethod
def format_project_configmap_name(project_name: str):
formatted_project_name = project_name.replace("_", "-")
return f"{formatted_project_name}-configmap"

@staticmethod
def from_yaml_object(config_yaml) -> LocalProjectConfig:
project_name = config_yaml["project_name"]
project_version = config_yaml["project_version"]
project_configmap_name = config_yaml["project_configmap_name"]
project_type = config_yaml["project_type"]

return LocalProjectConfig(project_name=project_name, project_version=project_version,
project_configmap_name=project_configmap_name,
return LocalProjectConfig(project_name=project_name,
project_version=project_version,
project_type=project_type)


Expand Down
9 changes: 5 additions & 4 deletions streamingcli/project/python/python_project_factory.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pathlib
import click
import copier
from streamingcli.project.local_project_config import LocalProjectConfigFactory
from streamingcli.project.project_type import ProjectType


PYTHON_TEMPLATE_PROJECT = "[email protected]:getindata/streaming-labs/flink-sandbox-python.git"
Expand All @@ -20,5 +18,8 @@ def create(project_name: str):
if PythonProjectFactory.check_if_directory_exists(project_path=project_path):
raise click.ClickException("Project directory already exists!")

copier.copy(src_path=PYTHON_TEMPLATE_PROJECT, dst_path=project_path)
LocalProjectConfigFactory.generate_initial_project_config(project_name, ProjectType.PYTHON)
template_data = {
"project_name": project_name
}

copier.copy(src_path=PYTHON_TEMPLATE_PROJECT, dst_path=project_path, data=template_data)

0 comments on commit bae8637

Please sign in to comment.