From b1d247da58f903fb8d2d1e6431fd4c28940b74a8 Mon Sep 17 00:00:00 2001 From: albamig Date: Mon, 14 Feb 2022 17:02:21 +0100 Subject: [PATCH 01/11] - Version added. issue #72 --- minos/cli/api/__init__.py | 9 +++++++++ tests/test_cli/test_api/test_version.py | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/test_cli/test_api/test_version.py diff --git a/minos/cli/api/__init__.py b/minos/cli/api/__init__.py index b15b1fc..c3930d9 100644 --- a/minos/cli/api/__init__.py +++ b/minos/cli/api/__init__.py @@ -1,5 +1,8 @@ import typer +from .. import ( + __version__, +) from ..consoles import ( console, ) @@ -17,6 +20,12 @@ app.add_typer(set_app, name="set") +@app.command() +def version(): + """CLI's version""" + console.print(f"Minos CLI {__version__}") + + @app.callback() def callback(): """Minos CLI.""" diff --git a/tests/test_cli/test_api/test_version.py b/tests/test_cli/test_api/test_version.py new file mode 100644 index 0000000..c0d4629 --- /dev/null +++ b/tests/test_cli/test_api/test_version.py @@ -0,0 +1,25 @@ +import unittest + +from typer.testing import ( + CliRunner, +) + +from minos.cli import ( + __main__, + __version__, + app, + main, +) + + +class TestVersion(unittest.TestCase): + def test_main(self): + self.assertEqual(__main__.main, main) + + def test_version(self) -> None: + result = CliRunner().invoke(app, ["version"]) + self.assertIn(__version__, result.output) + + +if __name__ == "__main__": + unittest.main() From 1e6fc0f4ada4bd3c1d05821ec09ec3d01e7d7ca0 Mon Sep 17 00:00:00 2001 From: albamig Date: Mon, 14 Feb 2022 18:32:49 +0100 Subject: [PATCH 02/11] - Avoid __pycache__ generation. issue #75 --- minos/cli/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/minos/cli/__init__.py b/minos/cli/__init__.py index bbbf3cc..5766249 100644 --- a/minos/cli/__init__.py +++ b/minos/cli/__init__.py @@ -2,6 +2,8 @@ __email__ = "hey@minos.run" __version__ = "0.1.3" +import sys + from .api import ( app, main, @@ -25,3 +27,5 @@ Form, Question, ) + +sys.dont_write_bytecode = True From eebe63b523e45237b59b6d86d9f96d75a4f68780 Mon Sep 17 00:00:00 2001 From: albamig Date: Tue, 15 Feb 2022 13:26:17 +0100 Subject: [PATCH 03/11] - Working. issue #73 --- minos/cli/api/new.py | 11 ++++++++-- minos/cli/pathlib.py | 24 +++++++++++++++------ tests/test_cli/test_api/.minos-project.yaml | 0 3 files changed, 26 insertions(+), 9 deletions(-) create mode 100644 tests/test_cli/test_api/.minos-project.yaml diff --git a/minos/cli/api/new.py b/minos/cli/api/new.py index 125a0c8..afe3511 100644 --- a/minos/cli/api/new.py +++ b/minos/cli/api/new.py @@ -7,6 +7,7 @@ from ..consoles import ( console, ) +from ..pathlib import get_microservices_directory from ..templating import ( TemplateFetcher, TemplateProcessor, @@ -27,13 +28,19 @@ def new_project(path: Path) -> None: @app.command("microservice") -def new_microservice(path: Path) -> None: +def new_microservice(name: str) -> None: """Initialize a microservice on the given directory.""" console.print(":wrench: Creating new Microservice...\n") + try: + microservice_path = get_microservices_directory(Path.cwd()) / name + except ValueError: + console.print("No Minos project found. Consider 'minos project init'") + raise typer.Exit(code=1) + fetcher = TemplateFetcher.from_name("microservice-init") - processor = TemplateProcessor.from_fetcher(fetcher, path.absolute(), defaults={"name": path.name}) + processor = TemplateProcessor.from_fetcher(fetcher, microservice_path, defaults={"name": name}) processor.render() diff --git a/minos/cli/pathlib.py b/minos/cli/pathlib.py index 58e011a..51a4666 100644 --- a/minos/cli/pathlib.py +++ b/minos/cli/pathlib.py @@ -2,6 +2,10 @@ Path, ) +MINOS_PROJECT_FILENAME = ".minos-project.yaml" +MINOS_MICROSERVICE_FILE = ".minos-microservice.yaml" +MICROSERVICES_DIRECTORY = "microservices" + def get_project_target_directory(path: Path) -> Path: """Get the target directory for a project. @@ -10,9 +14,10 @@ def get_project_target_directory(path: Path) -> Path: """ current = path while current != current.parent: - if (current / ".minos-project.yaml").exists(): + if (current / MINOS_PROJECT_FILENAME).exists(): return current - current = current.parent + else: + current = current.parent raise ValueError(f"Unable to find the target directory from {path} origin.") @@ -26,13 +31,18 @@ def get_microservice_target_directory(path: Path, name: str) -> Path: """ current = path while current != current.parent: - if (current / ".minos-microservice.yaml").exists(): - return current + if (current / MINOS_PROJECT_FILENAME).exists(): + return current / "microservices" - if (current / ".minos-project.yaml").exists(): - target = current / "microservices" / name - if (target / ".minos-microservice.yaml").exists(): + if (current / MINOS_PROJECT_FILENAME).exists(): + target = current / MICROSERVICES_DIRECTORY / name + if (target / MINOS_MICROSERVICE_FILE).exists(): return target current = current.parent raise ValueError(f"Unable to find the target directory for {name} from {path} origin.") + + +def get_microservices_directory(path: Path) -> Path: + project_directory = get_project_target_directory(path) + return project_directory / MICROSERVICES_DIRECTORY diff --git a/tests/test_cli/test_api/.minos-project.yaml b/tests/test_cli/test_api/.minos-project.yaml new file mode 100644 index 0000000..e69de29 From 5292b0950d655898b9b9dcd101dabf284ad99936 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 15 Feb 2022 12:27:35 +0000 Subject: [PATCH 04/11] Restyled by black --- minos/cli/api/new.py | 8 ++------ minos/cli/pathlib.py | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/minos/cli/api/new.py b/minos/cli/api/new.py index afe3511..88b05fe 100644 --- a/minos/cli/api/new.py +++ b/minos/cli/api/new.py @@ -1,12 +1,8 @@ -from pathlib import ( - Path, -) +from pathlib import Path import typer -from ..consoles import ( - console, -) +from ..consoles import console from ..pathlib import get_microservices_directory from ..templating import ( TemplateFetcher, diff --git a/minos/cli/pathlib.py b/minos/cli/pathlib.py index 51a4666..376b368 100644 --- a/minos/cli/pathlib.py +++ b/minos/cli/pathlib.py @@ -1,6 +1,4 @@ -from pathlib import ( - Path, -) +from pathlib import Path MINOS_PROJECT_FILENAME = ".minos-project.yaml" MINOS_MICROSERVICE_FILE = ".minos-microservice.yaml" From b3392e1873d2ce74c6eeac8cb02f937289bdc1f9 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 15 Feb 2022 12:27:40 +0000 Subject: [PATCH 05/11] Restyled by isort --- minos/cli/api/new.py | 12 +++++++++--- minos/cli/pathlib.py | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/minos/cli/api/new.py b/minos/cli/api/new.py index 88b05fe..ba894d2 100644 --- a/minos/cli/api/new.py +++ b/minos/cli/api/new.py @@ -1,9 +1,15 @@ -from pathlib import Path +from pathlib import ( + Path, +) import typer -from ..consoles import console -from ..pathlib import get_microservices_directory +from ..consoles import ( + console, +) +from ..pathlib import ( + get_microservices_directory, +) from ..templating import ( TemplateFetcher, TemplateProcessor, diff --git a/minos/cli/pathlib.py b/minos/cli/pathlib.py index 376b368..51a4666 100644 --- a/minos/cli/pathlib.py +++ b/minos/cli/pathlib.py @@ -1,4 +1,6 @@ -from pathlib import Path +from pathlib import ( + Path, +) MINOS_PROJECT_FILENAME = ".minos-project.yaml" MINOS_MICROSERVICE_FILE = ".minos-microservice.yaml" From f6a7ced1fe9fea93cb1dc445bd98113131720fde Mon Sep 17 00:00:00 2001 From: albamig Date: Tue, 15 Feb 2022 16:51:55 +0100 Subject: [PATCH 06/11] - Fixed tests. issue #73 --- minos/cli/pathlib.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/minos/cli/pathlib.py b/minos/cli/pathlib.py index 51a4666..4144fa5 100644 --- a/minos/cli/pathlib.py +++ b/minos/cli/pathlib.py @@ -3,7 +3,7 @@ ) MINOS_PROJECT_FILENAME = ".minos-project.yaml" -MINOS_MICROSERVICE_FILE = ".minos-microservice.yaml" +MINOS_MICROSERVICE_FILENAME = ".minos-microservice.yaml" MICROSERVICES_DIRECTORY = "microservices" @@ -31,12 +31,12 @@ def get_microservice_target_directory(path: Path, name: str) -> Path: """ current = path while current != current.parent: - if (current / MINOS_PROJECT_FILENAME).exists(): - return current / "microservices" + if (current / MINOS_MICROSERVICE_FILENAME).exists(): + return current if (current / MINOS_PROJECT_FILENAME).exists(): target = current / MICROSERVICES_DIRECTORY / name - if (target / MINOS_MICROSERVICE_FILE).exists(): + if (target / MINOS_MICROSERVICE_FILENAME).exists(): return target current = current.parent From eb17d06ed0aada7aa352fcd1a4ddf8aa06ac8e5b Mon Sep 17 00:00:00 2001 From: albamig Date: Wed, 16 Feb 2022 13:18:28 +0100 Subject: [PATCH 07/11] - Project file created dynamically. - Test for no project file. issue #73 --- tests/test_cli/test_api/.minos-project.yaml | 0 tests/test_cli/test_api/test_new.py | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+) delete mode 100644 tests/test_cli/test_api/.minos-project.yaml diff --git a/tests/test_cli/test_api/.minos-project.yaml b/tests/test_cli/test_api/.minos-project.yaml deleted file mode 100644 index e69de29..0000000 diff --git a/tests/test_cli/test_api/test_new.py b/tests/test_cli/test_api/test_new.py index ae74b20..66918ef 100644 --- a/tests/test_cli/test_api/test_new.py +++ b/tests/test_cli/test_api/test_new.py @@ -21,6 +21,14 @@ class TestNew(unittest.TestCase): + def setUp(self) -> None: + self.minos_project_file = Path.cwd() / ".minos-project.yaml" + self.minos_project_file.touch() + + def tearDown(self) -> None: + if self.minos_project_file.exists(): + self.minos_project_file.unlink() + def test_main(self): self.assertEqual(__main__.main, main) @@ -44,6 +52,18 @@ def test_new_microservice(self) -> None: self.assertEqual(1, mock.call_count) + def test_new_microservice_no_project_file(self) -> None: + self.minos_project_file.unlink() + + with TemporaryDirectory() as tmp_dir_name: + path = Path(tmp_dir_name) / "product" + with patch("minos.cli.TemplateProcessor.render") as mock: + result = CliRunner().invoke(app, ["new", "microservice", str(path)]) + + self.assertEqual(1, result.exit_code) + + self.assertEqual(0, mock.call_count) + if __name__ == "__main__": unittest.main() From 2f215bc4e2ceb589781faf6313b8c7c2cedad789 Mon Sep 17 00:00:00 2001 From: albamig Date: Wed, 16 Feb 2022 15:02:40 +0100 Subject: [PATCH 08/11] New version issue #? --- HISTORY.md | 6 ++++++ minos/cli/__init__.py | 2 +- pyproject.toml | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 287d46d..8417632 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -32,3 +32,9 @@ * Deploy command is no longer supported. * Quickstart updated for better user experience. + +## 0.2.0 (2022-02-16) + +* Microservices are now created within `microservices` directory. +* `version` commands added. +* Minos CLI no longer generates `__pycache__` archives. diff --git a/minos/cli/__init__.py b/minos/cli/__init__.py index 5766249..befcd44 100644 --- a/minos/cli/__init__.py +++ b/minos/cli/__init__.py @@ -1,6 +1,6 @@ __author__ = "Minos Framework Devs" __email__ = "hey@minos.run" -__version__ = "0.1.3" +__version__ = "0.2.0" import sys diff --git a/pyproject.toml b/pyproject.toml index 2e4fa9e..e0fcbe0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "minos-cli" -version = "0.1.3" +version = "0.2.0" description = "Command Line Interface for the Minos framework" readme = "README.md" repository = "https://github.com/minos-framework/minos-cli" From 7acb1eaf7e1b277ca51e7d7f676afd2ec43ac563 Mon Sep 17 00:00:00 2001 From: albamig Date: Wed, 16 Feb 2022 15:10:05 +0100 Subject: [PATCH 09/11] - Deleted `init` command. issue #81 --- minos/cli/api/__init__.py | 2 -- minos/cli/api/init.py | 40 ---------------------- tests/test_cli/test_api/test_init.py | 51 ---------------------------- 3 files changed, 93 deletions(-) delete mode 100644 minos/cli/api/init.py delete mode 100644 tests/test_cli/test_api/test_init.py diff --git a/minos/cli/api/__init__.py b/minos/cli/api/__init__.py index d356dd7..ea99f4b 100644 --- a/minos/cli/api/__init__.py +++ b/minos/cli/api/__init__.py @@ -6,13 +6,11 @@ from ..consoles import ( console, ) -from .init import app as init_app from .new import app as new_app from .set import app as set_app from .utils import app as utils_app app = typer.Typer(add_completion=False) -app.add_typer(init_app, name="init") app.add_typer(new_app, name="new") app.add_typer(utils_app, name="utils") app.add_typer(set_app, name="set") diff --git a/minos/cli/api/init.py b/minos/cli/api/init.py deleted file mode 100644 index d4ea668..0000000 --- a/minos/cli/api/init.py +++ /dev/null @@ -1,40 +0,0 @@ -from pathlib import ( - Path, -) - -import typer - -from ..consoles import ( - console, -) -from ..templating import ( - TemplateFetcher, - TemplateProcessor, -) - -app = typer.Typer(add_completion=False) - - -@app.command("project") -def init_project() -> None: - """Initialize a project on the current working directory.""" - - console.print(":wrench: Initializing new Project...\n") - fetcher = TemplateFetcher.from_name("project-init") - processor = TemplateProcessor.from_fetcher(fetcher, Path.cwd(), defaults={"project_name": Path.cwd().name}) - processor.render() - - -@app.command("microservice") -def init_microservice() -> None: - """Initialize a microservice on the current working directory.""" - - console.print(":wrench: Initializing new Microservice...\n") - fetcher = TemplateFetcher.from_name("microservice-init") - processor = TemplateProcessor.from_fetcher(fetcher, Path.cwd(), defaults={"name": Path.cwd().name}) - processor.render() - - -@app.callback() -def callback(): - """Initializes a new project or microservice in the current path""" diff --git a/tests/test_cli/test_api/test_init.py b/tests/test_cli/test_api/test_init.py deleted file mode 100644 index 40f9289..0000000 --- a/tests/test_cli/test_api/test_init.py +++ /dev/null @@ -1,51 +0,0 @@ -import unittest -from pathlib import ( - Path, -) -from tempfile import ( - TemporaryDirectory, -) -from unittest.mock import ( - patch, -) - -from typer.testing import ( - CliRunner, -) - -from minos.cli import ( - __main__, - app, - main, -) - - -class TestInit(unittest.TestCase): - def test_main(self): - self.assertEqual(__main__.main, main) - - def test_init_project(self) -> None: - with TemporaryDirectory() as tmp_dir_name: - path = Path(tmp_dir_name) / "ecommerce" - with patch("pathlib.Path.cwd", return_value=path): - with patch("minos.cli.TemplateProcessor.render") as mock: - result = CliRunner().invoke(app, ["init", "project"]) - - self.assertEqual(0, result.exit_code) - - self.assertEqual(1, mock.call_count) - - def test_init_microservice(self) -> None: - with TemporaryDirectory() as tmp_dir_name: - path = Path(tmp_dir_name) / "product" - with patch("pathlib.Path.cwd", return_value=path): - with patch("minos.cli.TemplateProcessor.render") as mock: - result = CliRunner().invoke(app, ["init", "microservice"]) - - self.assertEqual(0, result.exit_code) - - self.assertEqual(1, mock.call_count) - - -if __name__ == "__main__": - unittest.main() From 2bbc5004190e1755c14db21c8e0e8c27ca669a7b Mon Sep 17 00:00:00 2001 From: albamig Date: Wed, 16 Feb 2022 15:13:00 +0100 Subject: [PATCH 10/11] - Updated HISTORY.md issue #? --- HISTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.md b/HISTORY.md index 8417632..7985e20 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -38,3 +38,4 @@ * Microservices are now created within `microservices` directory. * `version` commands added. * Minos CLI no longer generates `__pycache__` archives. +* `init` command is no longer supported. From 4d5deee2ccff6fde503d731e9b7d645c7f6e7454 Mon Sep 17 00:00:00 2001 From: albamig Date: Wed, 16 Feb 2022 15:14:38 +0100 Subject: [PATCH 11/11] - Updated error message with valid command. issue #? --- minos/cli/api/new.py | 2 +- minos/cli/api/set.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/minos/cli/api/new.py b/minos/cli/api/new.py index ba894d2..e758b94 100644 --- a/minos/cli/api/new.py +++ b/minos/cli/api/new.py @@ -38,7 +38,7 @@ def new_microservice(name: str) -> None: try: microservice_path = get_microservices_directory(Path.cwd()) / name except ValueError: - console.print("No Minos project found. Consider 'minos project init'") + console.print("No Minos project found. Consider using 'minos new project'") raise typer.Exit(code=1) fetcher = TemplateFetcher.from_name("microservice-init") diff --git a/minos/cli/api/set.py b/minos/cli/api/set.py index 2d2efaf..7512bcb 100644 --- a/minos/cli/api/set.py +++ b/minos/cli/api/set.py @@ -49,7 +49,7 @@ def set_service(service: str, backend: str) -> None: try: project_path = get_project_target_directory(Path.cwd()) except ValueError: - console.print("No Minos project found. Consider 'minos project init'") + console.print("No Minos project found. Consider 'minos new project'") raise typer.Exit(code=1) config_path = project_path / ".minos-project.yaml"