Skip to content

Commit

Permalink
Merge pull request #27 from mxstack/update
Browse files Browse the repository at this point in the history
Add mxmake update command.
rnixx authored Feb 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 6ec8bbf + 6ffda8f commit 692562f
Showing 5 changed files with 83 additions and 41 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -36,6 +36,8 @@

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

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

- Use importlib.metadata to load entrypoints.

## 1.0a3 (2024-02-06)
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -233,15 +233,15 @@ MXENV_TARGET:=$(SENTINEL_FOLDER)/mxenv.sentinel
$(MXENV_TARGET): $(SENTINEL)
ifeq ("$(VENV_ENABLED)", "true")
ifeq ("$(VENV_CREATE)", "true")
ifeq ("$(PYTHON_PACKAGE_INSTALLER)$(MXENV_UV_GLOBAL)", "uvtrue")
ifeq ("$(PYTHON_PACKAGE_INSTALLER)$(MXENV_UV_GLOBAL)","uvtrue")
@echo "Setup Python Virtual Environment using package 'uv' at '$(VENV_FOLDER)'"
@uv venv -p $(PRIMARY_PYTHON) --seed $(VENV_FOLDER)
else
@echo "Setup Python Virtual Environment using module 'venv' at '$(VENV_FOLDER)'"
@$(PRIMARY_PYTHON) -m venv $(VENV_FOLDER)
@$(MXENV_PYTHON) -m ensurepip -U
endif
ifeq ("$(PYTHON_PACKAGE_INSTALLER)$(MXENV_UV_GLOBAL)", "uvfalse")
ifeq ("$(PYTHON_PACKAGE_INSTALLER)$(MXENV_UV_GLOBAL)","uvfalse")
@echo "Install uv"
@$(MXENV_PYTHON) -m pip install uv
endif
2 changes: 2 additions & 0 deletions docs/source/getting-started.md
Original file line number Diff line number Diff line change
@@ -61,4 +61,6 @@ Thus they are often prefixed.

Each setting provides a description and an optional default value.

To update the Makefile without beeing prompted interactive, run `mxmake update`.

For details read the chapter [on topics and it's domains](topics-and-domains).
109 changes: 72 additions & 37 deletions src/mxmake/main.py
Original file line number Diff line number Diff line change
@@ -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
@@ -17,6 +18,7 @@
import logging
import mxdev
import sys
import typing


logger = logging.getLogger("mxmake")
@@ -89,15 +91,11 @@ def list_command(args: argparse.Namespace):


##############################################################################
# init
# init/update
##############################################################################


def init_command(args: argparse.Namespace):
print("\n#######################")
print("# mxmake initialization")
print("#######################\n")

def create_config(prompt: bool):
# obtain target folder
target_folder = Path.cwd()

@@ -106,21 +104,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 not prompt:
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]
@@ -134,6 +136,13 @@ def init_command(args: argparse.Namespace):
# domain generated yet
else:
selected_fqns = [domain.fqn for domain in topic.domains]
if not prompt:
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(
@@ -166,14 +175,17 @@ def init_command(args: argparse.Namespace):
if sfqn in parser.settings:
setting_default = parser.settings[sfqn]
domain_settings[sfqn] = setting_default
if not prompt:
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 prompt:
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
@@ -186,7 +198,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 prompt 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"]:
@@ -195,30 +207,53 @@ def init_command(args: argparse.Namespace):
target_folder, domains, get_template_environment()
)
mx_ini_template.write()
elif not prompt 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 prompt:
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()


def init_command(args: argparse.Namespace):
print("\n#######################")
print("# mxmake initialization")
print("#######################\n")

create_config(prompt=True)


init_parser = command_parsers.add_parser("init", help="Initialize project")
init_parser.set_defaults(func=init_command)


def update_command(args: argparse.Namespace):
print("\n###############")
print("# mxmake update")
print("###############\n")

create_config(prompt=False)


update_parser = command_parsers.add_parser("update", help="Update makefile")
update_parser.set_defaults(func=update_command)


##############################################################################
# main
##############################################################################
7 changes: 5 additions & 2 deletions src/mxmake/topics.py
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ def write_to(self, fd: typing.TextIO):
fd.write(line)


@dataclass
@dataclass(unsafe_hash=True)
class Topic:
name: str
directory: Path
@@ -181,7 +181,10 @@ def load_topics() -> typing.List[Topic]:
if "mxmake.topics" not in eps:
return []
topics_eps = eps["mxmake.topics"] # type: ignore
return [ep.load() for ep in topics_eps] # type: ignore
# XXX: for some reasons entry points are loaded twice. not sure if this
# is a glitch when installing with uv or something related to
# importlib.metadata.entry_points
return list(set([ep.load() for ep in topics_eps])) # type: ignore


def get_topic(name: str) -> Topic:

0 comments on commit 692562f

Please sign in to comment.