Skip to content

Commit

Permalink
Added verbosity logging
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt committed Jun 20, 2022
1 parent 78507e9 commit 2081e30
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 9 deletions.
15 changes: 8 additions & 7 deletions cookie_composer/cli.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
"""Command line setup."""
from typing import Optional

import logging
from pathlib import Path

import click_log
import rich_click as click

from cookie_composer.commands.add import add_cmd
from cookie_composer.commands.create import create_cmd
from cookie_composer.exceptions import GitError

logger = logging.getLogger(__name__)
click_log.basic_config(logger)


@click.group()
def cli():
Expand All @@ -17,6 +22,7 @@ def cli():


@cli.command()
@click_log.simple_verbosity_option(logger)
@click.argument("path_or_url", type=str, required=True)
@click.argument(
"output_dir",
Expand All @@ -25,17 +31,12 @@ def cli():
type=click.Path(exists=True, dir_okay=True, file_okay=False, resolve_path=True),
)
def create(path_or_url: str, output_dir: Optional[Path]):
"""
Create a project from a template or configuration.
Args:
path_or_url: The path or URL to the template or composition file
output_dir: Where to write the output
"""
"""Create a project from a template or configuration."""
create_cmd(path_or_url, output_dir)


@cli.command()
@click_log.simple_verbosity_option(logger)
@click.option("--no-input", is_flag=True)
@click.argument("path_or_url", type=str, required=True)
@click.argument(
Expand Down
7 changes: 6 additions & 1 deletion cookie_composer/commands/add.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""The implementation of the add command."""
from typing import Optional

import logging
from pathlib import Path

from cookie_composer.composition import (
Expand All @@ -21,6 +22,8 @@
from cookie_composer.layers import render_layers
from cookie_composer.utils import get_context_for_layer, get_template_name

logger = logging.getLogger(__name__)


def add_cmd(
path_or_url: str,
Expand All @@ -40,7 +43,7 @@ def add_cmd(
GitError: If the destination_dir is not a git repository
ValueError: If there is not a .composition.yaml file in the destination directory
"""
destination_dir = destination_dir or Path(".")
destination_dir = Path(destination_dir).resolve() or Path().cwd().resolve()
output_dir = destination_dir.parent

# Read the project composition file
Expand All @@ -53,9 +56,11 @@ def add_cmd(
# Read the additional composition
if is_composition_file(path_or_url):
addl_composition = read_composition(path_or_url)
logger.info(f"Adding composition {path_or_url} to {output_dir}.")
else:
tmpl = LayerConfig(template=path_or_url)
addl_composition = Composition(layers=[tmpl])
logger.info(f"Adding template {path_or_url} to {output_dir}.")

# Get the merged context for all layers
initial_context = get_context_for_layer(proj_composition)
Expand Down
7 changes: 6 additions & 1 deletion cookie_composer/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import Optional

import logging
from pathlib import Path

from cookie_composer.composition import (
Expand All @@ -14,6 +15,8 @@
)
from cookie_composer.layers import render_layers

logger = logging.getLogger(__name__)


def create_cmd(
path_or_url: str,
Expand All @@ -31,12 +34,14 @@ def create_cmd(
Returns:
The path to the generated project.
"""
output_dir = output_dir or Path(".")
output_dir = Path(output_dir).resolve() or Path().cwd().resolve()
if is_composition_file(path_or_url):
composition = read_composition(path_or_url)
logger.info(f"Rendering composition {path_or_url} to {output_dir}.")
else:
tmpl = LayerConfig(template=path_or_url)
composition = Composition(layers=[tmpl], destination=output_dir)
logger.info(f"Rendering template {path_or_url} to {output_dir}.")
rendered_layers = render_layers(composition.layers, output_dir, no_input=no_input)
rendered_composition = RenderedComposition(
layers=rendered_layers,
Expand Down
1 change: 1 addition & 0 deletions cookie_composer/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def write_rendered_composition(composition: RenderedComposition):
layers.append(rendered_layer.layer)

composition_file = composition.render_dir / composition.rendered_name / ".composition.yaml"
logger.debug(f"Writing rendered composition to {composition_file}")
write_composition(layers, composition_file)


Expand Down
3 changes: 3 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ click==8.1.3
# -r docs.txt
# -r test.txt
# black
# click-log
# pip-tools
# rich-click
# sphinx-click
# typer
# vendoring
click-log==0.4.0
# via -r test.txt
commonmark==0.9.1
# via
# -r test.txt
Expand Down
1 change: 1 addition & 0 deletions requirements/prod.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-r cookiecutter.txt

aiohttp
click-log
fsspec
gitpython
pydantic
Expand Down
3 changes: 3 additions & 0 deletions requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ charset-normalizer==2.0.12
click==8.1.3
# via
# -r cookiecutter.txt
# click-log
# rich-click
click-log==0.4.0
# via -r prod.in
commonmark==0.9.1
# via rich
frozenlist==1.3.0
Expand Down
3 changes: 3 additions & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ click==8.1.3
# via
# -r prod.txt
# black
# click-log
# rich-click
click-log==0.4.0
# via -r prod.txt
commonmark==0.9.1
# via
# -r prod.txt
Expand Down

0 comments on commit 2081e30

Please sign in to comment.