Skip to content

Commit beca6ff

Browse files
authored
Merge pull request #82 from minos-framework/0.2.0
0.2.0
2 parents 1dc71f2 + 4d5deee commit beca6ff

File tree

11 files changed

+95
-104
lines changed

11 files changed

+95
-104
lines changed

HISTORY.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@
3232

3333
* Deploy command is no longer supported.
3434
* Quickstart updated for better user experience.
35+
36+
## 0.2.0 (2022-02-16)
37+
38+
* Microservices are now created within `microservices` directory.
39+
* `version` commands added.
40+
* Minos CLI no longer generates `__pycache__` archives.
41+
* `init` command is no longer supported.

minos/cli/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
__author__ = "Minos Framework Devs"
22
__email__ = "[email protected]"
3-
__version__ = "0.1.3"
3+
__version__ = "0.2.0"
4+
5+
import sys
46

57
from .api import (
68
app,
@@ -25,3 +27,5 @@
2527
Form,
2628
Question,
2729
)
30+
31+
sys.dont_write_bytecode = True

minos/cli/api/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import typer
22

3+
from .. import (
4+
__version__,
5+
)
36
from ..consoles import (
47
console,
58
)
6-
from .init import app as init_app
79
from .new import app as new_app
810
from .set import app as set_app
911
from .utils import app as utils_app
1012

1113
app = typer.Typer(add_completion=False)
12-
app.add_typer(init_app, name="init")
1314
app.add_typer(new_app, name="new")
1415
app.add_typer(utils_app, name="utils")
1516
app.add_typer(set_app, name="set")
1617

1718

19+
@app.command()
20+
def version():
21+
"""CLI's version"""
22+
console.print(f"Minos CLI {__version__}")
23+
24+
1825
@app.callback()
1926
def callback():
2027
"""Minos CLI."""

minos/cli/api/init.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

minos/cli/api/new.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from ..consoles import (
88
console,
99
)
10+
from ..pathlib import (
11+
get_microservices_directory,
12+
)
1013
from ..templating import (
1114
TemplateFetcher,
1215
TemplateProcessor,
@@ -27,13 +30,19 @@ def new_project(path: Path) -> None:
2730

2831

2932
@app.command("microservice")
30-
def new_microservice(path: Path) -> None:
33+
def new_microservice(name: str) -> None:
3134
"""Initialize a microservice on the given directory."""
3235

3336
console.print(":wrench: Creating new Microservice...\n")
3437

38+
try:
39+
microservice_path = get_microservices_directory(Path.cwd()) / name
40+
except ValueError:
41+
console.print("No Minos project found. Consider using 'minos new project'")
42+
raise typer.Exit(code=1)
43+
3544
fetcher = TemplateFetcher.from_name("microservice-init")
36-
processor = TemplateProcessor.from_fetcher(fetcher, path.absolute(), defaults={"name": path.name})
45+
processor = TemplateProcessor.from_fetcher(fetcher, microservice_path, defaults={"name": name})
3746
processor.render()
3847

3948

minos/cli/api/set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def set_service(service: str, backend: str) -> None:
4949
try:
5050
project_path = get_project_target_directory(Path.cwd())
5151
except ValueError:
52-
console.print("No Minos project found. Consider 'minos project init'")
52+
console.print("No Minos project found. Consider 'minos new project'")
5353
raise typer.Exit(code=1)
5454

5555
config_path = project_path / ".minos-project.yaml"

minos/cli/pathlib.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Path,
33
)
44

5+
MINOS_PROJECT_FILENAME = ".minos-project.yaml"
6+
MINOS_MICROSERVICE_FILENAME = ".minos-microservice.yaml"
7+
MICROSERVICES_DIRECTORY = "microservices"
8+
59

610
def get_project_target_directory(path: Path) -> Path:
711
"""Get the target directory for a project.
@@ -10,9 +14,10 @@ def get_project_target_directory(path: Path) -> Path:
1014
"""
1115
current = path
1216
while current != current.parent:
13-
if (current / ".minos-project.yaml").exists():
17+
if (current / MINOS_PROJECT_FILENAME).exists():
1418
return current
15-
current = current.parent
19+
else:
20+
current = current.parent
1621

1722
raise ValueError(f"Unable to find the target directory from {path} origin.")
1823

@@ -26,13 +31,18 @@ def get_microservice_target_directory(path: Path, name: str) -> Path:
2631
"""
2732
current = path
2833
while current != current.parent:
29-
if (current / ".minos-microservice.yaml").exists():
34+
if (current / MINOS_MICROSERVICE_FILENAME).exists():
3035
return current
3136

32-
if (current / ".minos-project.yaml").exists():
33-
target = current / "microservices" / name
34-
if (target / ".minos-microservice.yaml").exists():
37+
if (current / MINOS_PROJECT_FILENAME).exists():
38+
target = current / MICROSERVICES_DIRECTORY / name
39+
if (target / MINOS_MICROSERVICE_FILENAME).exists():
3540
return target
3641
current = current.parent
3742

3843
raise ValueError(f"Unable to find the target directory for {name} from {path} origin.")
44+
45+
46+
def get_microservices_directory(path: Path) -> Path:
47+
project_directory = get_project_target_directory(path)
48+
return project_directory / MICROSERVICES_DIRECTORY

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "minos-cli"
3-
version = "0.1.3"
3+
version = "0.2.0"
44
description = "Command Line Interface for the Minos framework"
55
readme = "README.md"
66
repository = "https://github.com/minos-framework/minos-cli"

tests/test_cli/test_api/test_init.py

Lines changed: 0 additions & 51 deletions
This file was deleted.

tests/test_cli/test_api/test_new.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121

2222

2323
class TestNew(unittest.TestCase):
24+
def setUp(self) -> None:
25+
self.minos_project_file = Path.cwd() / ".minos-project.yaml"
26+
self.minos_project_file.touch()
27+
28+
def tearDown(self) -> None:
29+
if self.minos_project_file.exists():
30+
self.minos_project_file.unlink()
31+
2432
def test_main(self):
2533
self.assertEqual(__main__.main, main)
2634

@@ -44,6 +52,18 @@ def test_new_microservice(self) -> None:
4452

4553
self.assertEqual(1, mock.call_count)
4654

55+
def test_new_microservice_no_project_file(self) -> None:
56+
self.minos_project_file.unlink()
57+
58+
with TemporaryDirectory() as tmp_dir_name:
59+
path = Path(tmp_dir_name) / "product"
60+
with patch("minos.cli.TemplateProcessor.render") as mock:
61+
result = CliRunner().invoke(app, ["new", "microservice", str(path)])
62+
63+
self.assertEqual(1, result.exit_code)
64+
65+
self.assertEqual(0, mock.call_count)
66+
4767

4868
if __name__ == "__main__":
4969
unittest.main()

0 commit comments

Comments
 (0)