Skip to content

Commit 56eb539

Browse files
committed
test build config
1 parent d42af8a commit 56eb539

File tree

11 files changed

+479
-139
lines changed

11 files changed

+479
-139
lines changed

idom/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1+
# pragma: no cover
12
from .cli import main
23

3-
if __name__ == "__main__": # pragma: no cover
4+
if __name__ == "__main__":
45
main()

idom/cli/commands.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import json
12
from pathlib import Path
3+
from typing import Optional
24

35
import typer
46

57
import idom
68
from idom.client import manage as manage_client
7-
from idom.client.build_config import find_build_config_item_in_python_source
9+
from idom.client.build_config import find_build_config_item_in_python_file
10+
11+
from . import settings
812

913

1014
main = typer.Typer()
@@ -13,20 +17,25 @@
1317

1418

1519
@main.command()
16-
def build(entrypoint: str) -> None:
20+
def build(
21+
entrypoint: Optional[str] = typer.Option(
22+
None,
23+
"--entrypoint",
24+
"-e",
25+
help="A python file containing a build config",
26+
)
27+
) -> None:
1728
"""Configure and build the client"""
18-
if entrypoint.endswith(".py"):
19-
config = find_build_config_item_in_python_source(
20-
"__main__", Path.cwd() / entrypoint
21-
)
22-
if config is None:
23-
typer.echo(f"No build config found in {entrypoint!r}")
24-
manage_client.build()
25-
else:
26-
manage_client.build([config])
29+
if entrypoint is None:
30+
manage_client.build()
31+
return None
32+
33+
config = find_build_config_item_in_python_file("__main__", Path.cwd() / entrypoint)
34+
if config is None:
35+
typer.echo(f"No build config found in {entrypoint!r}")
36+
manage_client.build()
2737
else:
28-
typer.echo(f"Expected a '.py' file extension, not {entrypoint!r}")
29-
raise typer.Exit(1)
38+
manage_client.build([config])
3039

3140

3241
@main.command()
@@ -36,12 +45,18 @@ def restore():
3645

3746

3847
@show.command()
39-
def config() -> None:
48+
def build_config() -> None:
4049
"""Show the state of IDOM's build config"""
41-
typer.echo(manage_client.BUILD_CONFIG_FILE.show())
50+
typer.echo(json.dumps(manage_client.build_config_file().to_dicts(), indent=2))
4251
return None
4352

4453

4554
@show.command()
4655
def version() -> None:
4756
typer.echo(idom.__version__)
57+
58+
59+
@show.command()
60+
def environment() -> None:
61+
for n in settings.NAMES:
62+
typer.echo(f"{n}={getattr(settings, n)}")

idom/cli/console.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1-
import os
21
from contextlib import contextmanager
32
from typing import Optional, Any, Iterator
43

54
import typer
65
import click_spinner
76

8-
9-
os.environ.setdefault("IDOM_CLI_SHOW_SPINNER", "1")
10-
os.environ.setdefault("IDOM_CLI_SHOW_OUTPUT", "1")
7+
from .settings import IDOM_CLI_SHOW_SPINNER, IDOM_CLI_SHOW_OUTPUT, IDOM_CLI_DEBUG
118

129

1310
def echo(message: str, message_color: Optional[str] = None, **kwargs: Any) -> None:
1411
if message_color is not None:
1512
message = typer.style(message, fg=getattr(typer.colors, message_color.upper()))
16-
if _show_output():
13+
if IDOM_CLI_SHOW_OUTPUT:
1714
typer.echo(message, **kwargs)
1815

1916

@@ -23,19 +20,16 @@ def spinner(message: str) -> Iterator[None]:
2320
message = message + " "
2421
echo(message, nl=False)
2522
try:
26-
with click_spinner.spinner(disable=not _show_spinner()):
23+
with click_spinner.spinner(
24+
disable=not (IDOM_CLI_SHOW_OUTPUT and IDOM_CLI_SHOW_SPINNER)
25+
):
2726
yield None
2827
except Exception as error:
2928
echo(typer.style("✖️", fg=typer.colors.RED))
3029
echo(str(error), message_color="red")
31-
raise typer.Exit(1)
30+
if IDOM_CLI_DEBUG:
31+
raise error
32+
else:
33+
raise typer.Exit(1)
3234
else:
3335
echo(typer.style("✔️", fg=typer.colors.GREEN))
34-
35-
36-
def _show_spinner() -> bool:
37-
return _show_output() and bool(int(os.environ["IDOM_CLI_SHOW_SPINNER"]))
38-
39-
40-
def _show_output() -> bool:
41-
return bool(int(os.environ["IDOM_CLI_SHOW_OUTPUT"]))

idom/cli/settings.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
from typing import List
3+
4+
NAMES: List[str] = []
5+
6+
IDOM_CLI_SHOW_SPINNER = True
7+
IDOM_CLI_SHOW_OUTPUT = True
8+
IDOM_CLI_DEBUG = False
9+
10+
11+
def _load_from_environ():
12+
gs = globals()
13+
for k, v in globals().items():
14+
if k.startswith("IDOM_"):
15+
if isinstance(v, bool):
16+
gs[k] = bool(int(os.environ.setdefault(k, str(int(v)))))
17+
else:
18+
gs[k] = os.environ.setdefault(k, v)
19+
NAMES.append(k)
20+
21+
22+
_load_from_environ()

0 commit comments

Comments
 (0)