Running tasks without opened project, single template selection fixes
This commit is contained in:
+27
-11
@@ -1,11 +1,14 @@
|
|||||||
import sys
|
import sys
|
||||||
from itertools import tee
|
from itertools import tee
|
||||||
from typing import MutableSequence, MutableSet, Optional
|
from typing import TYPE_CHECKING, MutableSequence, MutableSet, Optional
|
||||||
|
|
||||||
from .project_graph import ProjectEdge, ProjectGraph
|
from .project_graph import ProjectEdge, ProjectGraph
|
||||||
from .shell import (abort, attention, failure, pretty_error, pretty_print,
|
from .shell import (abort, attention, failure, pretty_error, pretty_print,
|
||||||
pretty_warn, success)
|
pretty_warn, success)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .parser import NamedCallable
|
||||||
|
|
||||||
|
|
||||||
def show_help():
|
def show_help():
|
||||||
pretty_print("Usage: icmtoolchain [options] ... <task1> [arguments1] ...")
|
pretty_print("Usage: icmtoolchain [options] ... <task1> [arguments1] ...")
|
||||||
@@ -46,6 +49,19 @@ def resolve_circular_references(graph: ProjectGraph) -> bool:
|
|||||||
raise RuntimeCodeError(255, "Cannot build a project with unresolved dependencies!")
|
raise RuntimeCodeError(255, "Cannot build a project with unresolved dependencies!")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def execute_task(callable: 'NamedCallable') -> None:
|
||||||
|
try:
|
||||||
|
result = callable.callable()
|
||||||
|
if result != 0:
|
||||||
|
abort(f"Task {callable.name} failed with result {result}.", code=result)
|
||||||
|
except BaseException as err:
|
||||||
|
if isinstance(err, SystemExit):
|
||||||
|
raise err
|
||||||
|
from .utils import RuntimeCodeError
|
||||||
|
if isinstance(err, RuntimeCodeError):
|
||||||
|
abort(f"Task {callable.name} failed with error code #{err.code}: {err}")
|
||||||
|
abort(f"Task {callable.name} failed with unexpected error!", cause=err)
|
||||||
|
|
||||||
def run(argv: Optional[MutableSequence[str]] = None):
|
def run(argv: Optional[MutableSequence[str]] = None):
|
||||||
if not argv or len(argv) == 0:
|
if not argv or len(argv) == 0:
|
||||||
argv = sys.argv
|
argv = sys.argv
|
||||||
@@ -82,6 +98,7 @@ def run(argv: Optional[MutableSequence[str]] = None):
|
|||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
from . import GLOBALS
|
from . import GLOBALS
|
||||||
|
if GLOBALS.is_project_available():
|
||||||
graph = ProjectGraph(GLOBALS.MAKE_CONFIG)
|
graph = ProjectGraph(GLOBALS.MAKE_CONFIG)
|
||||||
graph.collect_dependencies(GLOBALS.MAKE_CONFIG)
|
graph.collect_dependencies(GLOBALS.MAKE_CONFIG)
|
||||||
unresolved_artifacts = graph.resolve_dependencies()
|
unresolved_artifacts = graph.resolve_dependencies()
|
||||||
@@ -100,17 +117,16 @@ def run(argv: Optional[MutableSequence[str]] = None):
|
|||||||
except StopIteration:
|
except StopIteration:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
execute_task(callable)
|
||||||
|
|
||||||
|
else:
|
||||||
|
while True:
|
||||||
try:
|
try:
|
||||||
result = callable.callable()
|
callable = next(targets)
|
||||||
if result != 0:
|
except StopIteration:
|
||||||
abort(f"Task {callable.name} failed with result {result}.", code=result)
|
break
|
||||||
except BaseException as err:
|
else:
|
||||||
if isinstance(err, SystemExit):
|
execute_task(callable)
|
||||||
raise err
|
|
||||||
from .utils import RuntimeCodeError
|
|
||||||
if isinstance(err, RuntimeCodeError):
|
|
||||||
abort(f"Task {callable.name} failed with error code #{err.code}: {err}")
|
|
||||||
abort(f"Task {callable.name} failed with unexpected error!", cause=err)
|
|
||||||
|
|
||||||
startup_millis = time() - startup_millis
|
startup_millis = time() - startup_millis
|
||||||
success(f"Tasks successfully completed in {startup_millis:.2f}s!")
|
success(f"Tasks successfully completed in {startup_millis:.2f}s!")
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ def new_project(template: Optional[str] = "../toolchain-mod") -> Optional[int]:
|
|||||||
|
|
||||||
default_name = GLOBALS.TOOLCHAIN_CONFIG.get_value("template.name")
|
default_name = GLOBALS.TOOLCHAIN_CONFIG.get_value("template.name")
|
||||||
create_review = Review(
|
create_review = Review(
|
||||||
template=create_template_chooser(),
|
template=lambda _: create_template_chooser(),
|
||||||
name=Input("Decide a name for your project:", on_input=update_project_name, default_text=default_name, hint="Template Mod"),
|
name=Input("Decide a name for your project:", on_input=update_project_name, default_text=default_name, hint="Template Mod"),
|
||||||
author=Input("Author who crafted this creation:", default_text=GLOBALS.TOOLCHAIN_CONFIG.get_value("template.author")),
|
author=Input("Author who crafted this creation:", default_text=GLOBALS.TOOLCHAIN_CONFIG.get_value("template.author")),
|
||||||
version=Input("What version a project starts from:", default_text=GLOBALS.TOOLCHAIN_CONFIG.get_value("template.version"), hint="1.0"),
|
version=Input("What version a project starts from:", default_text=GLOBALS.TOOLCHAIN_CONFIG.get_value("template.version"), hint="1.0"),
|
||||||
|
|||||||
Reference in New Issue
Block a user