Skip to content

Commit

Permalink
Merge pull request #82 from minos-framework/0.2.0
Browse files Browse the repository at this point in the history
0.2.0
  • Loading branch information
andrea-mucci authored Feb 17, 2022
2 parents 1dc71f2 + 4d5deee commit beca6ff
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 104 deletions.
7 changes: 7 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,10 @@

* 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.
* `init` command is no longer supported.
6 changes: 5 additions & 1 deletion minos/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
__author__ = "Minos Framework Devs"
__email__ = "[email protected]"
__version__ = "0.1.3"
__version__ = "0.2.0"

import sys

from .api import (
app,
Expand All @@ -25,3 +27,5 @@
Form,
Question,
)

sys.dont_write_bytecode = True
11 changes: 9 additions & 2 deletions minos/cli/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import typer

from .. import (
__version__,
)
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")


@app.command()
def version():
"""CLI's version"""
console.print(f"Minos CLI {__version__}")


@app.callback()
def callback():
"""Minos CLI."""
Expand Down
40 changes: 0 additions & 40 deletions minos/cli/api/init.py

This file was deleted.

13 changes: 11 additions & 2 deletions minos/cli/api/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
from ..consoles import (
console,
)
from ..pathlib import (
get_microservices_directory,
)
from ..templating import (
TemplateFetcher,
TemplateProcessor,
Expand All @@ -27,13 +30,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 using 'minos new project'")
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()


Expand Down
2 changes: 1 addition & 1 deletion minos/cli/api/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 16 additions & 6 deletions minos/cli/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Path,
)

MINOS_PROJECT_FILENAME = ".minos-project.yaml"
MINOS_MICROSERVICE_FILENAME = ".minos-microservice.yaml"
MICROSERVICES_DIRECTORY = "microservices"


def get_project_target_directory(path: Path) -> Path:
"""Get the target directory for a project.
Expand All @@ -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.")

Expand All @@ -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():
if (current / MINOS_MICROSERVICE_FILENAME).exists():
return current

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_FILENAME).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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
51 changes: 0 additions & 51 deletions tests/test_cli/test_api/test_init.py

This file was deleted.

20 changes: 20 additions & 0 deletions tests/test_cli/test_api/test_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()
25 changes: 25 additions & 0 deletions tests/test_cli/test_api/test_version.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit beca6ff

Please sign in to comment.