Skip to content

Commit

Permalink
Add --update -u option to mxmake init.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens committed Feb 27, 2024
1 parent 91c553b commit 5962784
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 31 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

- Use `pathlib.Path` instead of `os.path`.

- Support `--update` flag in `mxmake init` command, updating the Makefile without prompting for settings.

## 1.0a3 (2024-02-06)

- Add `typecheck` target and use it for mypy instead of `check` target.
Expand Down
2 changes: 2 additions & 0 deletions docs/source/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,6 @@ Thus they are often prefixed.

Each setting provides a description and an optional default value.

To update the settings, run `mxmake init --update`.

For details read the chapter [on topics and it's domains](topics-and-domains).
87 changes: 56 additions & 31 deletions src/mxmake/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mxmake.templates import get_template_environment
from mxmake.templates import template
from mxmake.topics import collect_missing_dependencies
from mxmake.topics import Domain
from mxmake.topics import get_domain
from mxmake.topics import get_topic
from mxmake.topics import load_topics
Expand All @@ -17,6 +18,7 @@
import logging
import mxdev
import sys
import typing


logger = logging.getLogger("mxmake")
Expand Down Expand Up @@ -106,21 +108,25 @@ def init_command(args: argparse.Namespace):

# obtain topics to include
topics = load_topics()
topic_choice = inquirer.prompt(
[
inquirer.Checkbox(
"topic",
message="Include topics",
choices=[d.name for d in topics],
default=list(parser.topics),
)
]
)
if args.update:
print("Update Makefile without prompting for settings.")
topic_choice = {"topic": list(parser.topics)}
else:
topic_choice = inquirer.prompt(
[
inquirer.Checkbox(
"topic",
message="Include topics",
choices=[d.name for d in topics],
default=list(parser.topics),
)
]
)
if topic_choice is None:
return

# obtain domains to include
domains = []
domains: typing.List[Domain] = []
for topic_name in topic_choice["topic"]:
topic = get_topic(topic_name)
all_fqns = [domain.fqn for domain in topic.domains]
Expand All @@ -134,6 +140,13 @@ def init_command(args: argparse.Namespace):
# domain generated yet
else:
selected_fqns = [domain.fqn for domain in topic.domains]
if args.update:
print(
f"- update topic {topic_name} with domains "
f"{', '.join([fqdn.split(".")[1] for fqdn in selected_fqns])}."
)
domains.extend((get_domain(fqn) for fqn in selected_fqns))
continue
domains_choice = inquirer.prompt(
[
inquirer.Checkbox(
Expand Down Expand Up @@ -166,14 +179,17 @@ def init_command(args: argparse.Namespace):
if sfqn in parser.settings:
setting_default = parser.settings[sfqn]
domain_settings[sfqn] = setting_default
if args.update:
continue
settings_question.append(
inquirer.Text(sfqn, message=sfqn, default=setting_default)
)
print(f"Edit Settings for {domain.fqn}?")
yn = inquirer.text(message="y/N")
if yn in ["Y", "y"]:
domain_settings.update(inquirer.prompt(settings_question))
print("")
if not args.update:
print(f"Edit Settings for {domain.fqn}?")
yn = inquirer.text(message="y/N")
if yn in ["Y", "y"]:
domain_settings.update(inquirer.prompt(settings_question))
print("")

if domains:
# generate makefile
Expand All @@ -186,7 +202,7 @@ def init_command(args: argparse.Namespace):
print("Skip generation of Makefile, nothing selected")

# mx ini generation
if not (target_folder / "mx.ini").exists():
if not args.update and not (target_folder / "mx.ini").exists():
print("\n``mx.ini`` configuration file not exists. Create One?")
yn = inquirer.text(message="Y/n")
if yn not in ["n", "N"]:
Expand All @@ -195,27 +211,36 @@ def init_command(args: argparse.Namespace):
target_folder, domains, get_template_environment()
)
mx_ini_template.write()
elif args.update and not (target_folder / "mx.ini").exists():
print("No generation of mx configuration on update (file does not exist).")
else:
print("Skip generation of mx configuration file, file already exists")

# ci generation
print("\nDo you want to create CI related files?")
yn = inquirer.text(message="y/N")
if yn in ["y", "Y"]:
# ci_template
ci_choice = inquirer.prompt(
[
inquirer.Checkbox(
"ci", message="Generate CI files", choices=ci_template.templates
)
]
)
for template_name in ci_choice["ci"]:
factory = template.lookup(template_name)
factory(get_template_environment()).write()
if not args.update:
print("\nDo you want to create CI related files?")
yn = inquirer.text(message="y/N")
if yn in ["y", "Y"]:
# ci_template
ci_choice = inquirer.prompt(
[
inquirer.Checkbox(
"ci", message="Generate CI files", choices=ci_template.templates
)
]
)
for template_name in ci_choice["ci"]:
factory = template.lookup(template_name)
factory(get_template_environment()).write()


init_parser = command_parsers.add_parser("init", help="Initialize project")
init_parser.add_argument(
"-u",
"--update",
help="Update the Makefile without prompting for settings",
action="store_true",
)
init_parser.set_defaults(func=init_command)


Expand Down

0 comments on commit 5962784

Please sign in to comment.