Skip to content

Commit

Permalink
feat: Specify multiple or no package directories via CLI options for …
Browse files Browse the repository at this point in the history
…`monas init` (#15)

* Add ability to specify multiple or no package dirs for 'monas init'

* Remove unnecessary stdout in test_init

* Add import for annotations from __future__ in commands/init.py
  • Loading branch information
HuM4NoiD committed Oct 18, 2023
1 parent 1b9b0f6 commit a504c05
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
28 changes: 26 additions & 2 deletions src/monas/commands/init.py
@@ -1,3 +1,5 @@
from __future__ import annotations

import textwrap
from pathlib import Path

Expand All @@ -18,13 +20,35 @@
help="The Python version to use",
)
@click.option("-v", "--version", default="0.0.0", help="The version of the monorepo")
def init(*, version: str, python_version: str) -> None:
@click.option(
"-d",
"--default-package-dir",
multiple=True,
default=["packages"],
help="Default Package Directories to be created",
)
@click.option(
"-n",
"--no-package-dir",
is_flag=True,
default=False,
help="If specified, no package directories will be created",
)
def init(
*,
version: str,
python_version: str,
default_package_dir: list[str],
no_package_dir: bool,
) -> None:
"""Initialize the monas tool.
Args:
path: The path to the `pyproject.toml` file.
"""
default_package_dirs = ["packages"]
default_package_dirs = list(default_package_dir)
if no_package_dir:
default_package_dirs.clear()
mono_settings = {
"packages": [f"{pb}/*" for pb in default_package_dirs],
"version": version,
Expand Down
4 changes: 2 additions & 2 deletions src/monas/project.py
Expand Up @@ -3,7 +3,7 @@
import textwrap
from pathlib import Path
from shlex import join as sh_join
from typing import Optional, Type, cast
from typing import Type, cast

import tomlkit
from packaging.utils import canonicalize_name
Expand Down Expand Up @@ -179,7 +179,7 @@ def get_local_dependencies(
if pkg_name not in dependency_names:
continue
if pkg_name == self.canonical_name:
raise ValueError(f'{self.name} cannot have a dependency on itself')
raise ValueError(f"{self.name} cannot have a dependency on itself")
if pkg_name in [ld.canonical_name for ld in local_dependencies]:
continue
local_dependencies = [pkg, *local_dependencies]
Expand Down
31 changes: 31 additions & 0 deletions tests/cli/test_init.py
Expand Up @@ -22,3 +22,34 @@ def test_init_with_given_python_version(cli_run, tmp_path):
python-version = "3.9"
"""
)


def test_init_with_no_package_directories(cli_run, tmp_path):
cli_run(["init", "-n", "-p", "3.9"], cwd=tmp_path)
assert (
tmp_path.joinpath("pyproject.toml").read_text()
== """\
[tool.monas]
packages = []
version = "0.0.0"
python-version = "3.9"
"""
)


def test_init_with_selected_package_directories(cli_run, tmp_path):
cli_run(["init", "-p", "3.9", "-d", "packages1", "-d", "packages2"], cwd=tmp_path)
print("CLI TEST_RAN")
assert (
tmp_path.joinpath("pyproject.toml").read_text()
== """\
[tool.monas]
packages = ["packages1/*", "packages2/*"]
version = "0.0.0"
python-version = "3.9"
"""
)
import os

assert os.path.exists(os.path.join(tmp_path, "packages1"))
assert os.path.exists(os.path.join(tmp_path, "packages2"))

0 comments on commit a504c05

Please sign in to comment.