Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Specifying multiple or no package directories for monas init #15

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/monas/commands/init.py
Original file line number Diff line number Diff line change
@@ -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],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing import: from __future__ import annotations

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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"))