Skip to content

Commit

Permalink
Fixes #31. Code cleanup: Simplified ways to log from commands executed
Browse files Browse the repository at this point in the history
- there should be no end-user change of behaviour in this change
  • Loading branch information
markfinal committed Dec 10, 2022
1 parent acbdc10 commit b2e2f7f
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 35 deletions.
5 changes: 2 additions & 3 deletions cruiz/commands/conaninvocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ class ConanInvocation(QtCore.QObject):
def __del__(self) -> None:
logger.debug("-=%d", id(self))

def __init__(self, log_details: LogDetails) -> None:
def __init__(self) -> None:
logger.debug("+=%d", id(self))
super().__init__() # note that parent is None
self._log_details = log_details
self._mp_context = multiprocessing.get_context("spawn")
self._process_queue = self._mp_context.Queue()
self._thread = QtCore.QThread()
Expand Down Expand Up @@ -119,7 +118,7 @@ def invoke(
self._queue_processor.critical_failure.connect(self._critical_failure)
with GeneralSettingsReader() as settings:
clear_panes = settings.clear_panes.resolve()
if clear_panes and isinstance(log_details, LogDetails):
if clear_panes:
log_details.output.clear()
if log_details.error:
log_details.error.clear()
Expand Down
25 changes: 12 additions & 13 deletions cruiz/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,19 @@ def _start_invocation(
PackageRevisionsParameters,
PackageBinaryParameters,
],
log_details: LogDetails,
command_toolbar: typing.Optional[QtWidgets.QWidget],
continuation: typing.Optional[typing.Callable[[typing.Any, typing.Any], None]],
enable_history: bool = True,
) -> None:
added_environment, removed_environment = get_conan_env(self.cache_name)
parameters.added_environment.update(added_environment)
parameters.removed_environment.extend(removed_environment)
instance = ConanInvocation(self._log_details)
instance = ConanInvocation()
instance.completed.connect(self._completed_invocation)
instance.finished.connect(self._finished_invocation)
if command_toolbar:
instance.finished.connect(command_toolbar.command_ended)
instance.invoke(parameters, log_details, continuation)
instance.invoke(parameters, self._log_details, continuation)
self._invocations.append(instance)
if self.command_history_widget is not None and enable_history:
# TODO: prefer adding to a model?
Expand All @@ -183,7 +182,6 @@ def _finished_invocation(self) -> None:
def conancommand(
self,
params: CommandParameters,
log_details: LogDetails,
command_toolbar: typing.Optional[QtWidgets.QWidget],
continuation: typing.Optional[
typing.Callable[[typing.Any, typing.Any], None]
Expand All @@ -193,12 +191,11 @@ def conancommand(
Run a conan command, with parameters as provided, and a continuation
if further processing is needed
"""
self._start_invocation(params, log_details, command_toolbar, continuation)
self._start_invocation(params, command_toolbar, continuation)

def cmakebuildcommand(
self,
params: CommandParameters,
log_details: LogDetails,
command_toolbar: typing.Optional[QtWidgets.QWidget],
continuation: typing.Optional[
typing.Callable[[typing.Any, typing.Any], None]
Expand All @@ -208,7 +205,10 @@ def cmakebuildcommand(
Invoke the CMake build tool on the build folder of the recipe
"""
self._start_invocation(
params, log_details, command_toolbar, continuation, enable_history=False
params,
command_toolbar,
continuation,
enable_history=False,
)

# pylint: disable=pointless-string-statement
Expand Down Expand Up @@ -295,7 +295,7 @@ def remove_all_packages(
"removeallpackages", cruiz.workers.removeallpackages.invoke
)
params.force = True
self._start_invocation(params, self._log_details, None, continuation)
self._start_invocation(params, None, continuation)

def remove_local_cache_locks(
self,
Expand All @@ -305,7 +305,7 @@ def remove_local_cache_locks(
Run 'conan remove --locks' to remove all lock files from the local cache
"""
params = CommandParameters("removelocks", cruiz.workers.removelocks.invoke)
self._start_invocation(params, self._log_details, None, continuation)
self._start_invocation(params, None, continuation)

def install_config(
self,
Expand All @@ -317,7 +317,7 @@ def install_config(
"""
Run 'conan config install <URI> [--args -b branch] [-s source] [-t target]'
"""
self._start_invocation(params, self._log_details, None, continuation)
self._start_invocation(params, None, continuation)

def remotes_sync(self, remotes: typing.List[ConanRemote]) -> None:
"""
Expand Down Expand Up @@ -373,13 +373,12 @@ def get_package_details(
PackageRevisionsParameters,
PackageBinaryParameters,
],
log_details: LogDetails,
continuation: typing.Optional[typing.Callable[[typing.Any, typing.Any], None]],
) -> None:
"""
Perform one of the actions to get package details from a remote.
"""
self._start_invocation(params, log_details, None, continuation)
self._start_invocation(params, None, continuation)

def get_package_directory(self, pkgdata: PackageNode) -> str:
"""
Expand Down Expand Up @@ -513,7 +512,7 @@ def run_any_command(
Run an arbitrary Conan command in the local cache.
"""

self._start_invocation(params, self._log_details, None, continuation)
self._start_invocation(params, None, continuation)

# TODO: remove editables
def get_editables_list(self) -> typing.Dict[str, str]:
Expand Down
1 change: 0 additions & 1 deletion cruiz/recipe/recipewidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,6 @@ def _generate_dependency_graph(
params.add_option(params.name, key, value) # type: ignore
self._dependency_generate_context.conancommand(
params,
self._dependency_generate_log,
None,
self._on_dependency_graph_generated,
)
Expand Down
15 changes: 2 additions & 13 deletions cruiz/recipe/toolbars/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,6 @@ def _conan_create_common(
self.command_started.emit()
recipe_widget.recipe.context.conancommand(
self._make_conan_create_params(recipe_attributes, args),
recipe_widget.log_details,
self,
)

Expand All @@ -590,7 +589,6 @@ def _conan_install_common(
self.command_started.emit()
recipe_widget.recipe.context.conancommand(
self._make_conan_install_params(recipe_attributes, args),
recipe_widget.log_details,
self,
)

Expand All @@ -609,7 +607,6 @@ def _conan_imports(self) -> None:
self.command_started.emit()
recipe_widget.recipe.context.conancommand(
self._make_conan_imports_params(recipe_attributes),
recipe_widget.log_details,
self,
)

Expand All @@ -622,7 +619,6 @@ def _conan_source(self) -> None:
self.command_started.emit()
recipe_widget.recipe.context.conancommand(
self._make_conan_source_params(recipe_attributes),
recipe_widget.log_details,
self,
)

Expand All @@ -635,7 +631,6 @@ def _conan_build(self) -> None:
self.command_started.emit()
recipe_widget.recipe.context.conancommand(
self._make_conan_build_params(recipe_attributes),
recipe_widget.log_details,
self,
)

Expand All @@ -648,7 +643,6 @@ def _conan_package(self) -> None:
self.command_started.emit()
recipe_widget.recipe.context.conancommand(
self._make_conan_package_params(recipe_attributes),
recipe_widget.log_details,
self,
)

Expand All @@ -661,7 +655,6 @@ def _conan_export_package(self) -> None:
self.command_started.emit()
recipe_widget.recipe.context.conancommand(
self._make_conan_export_package_params(recipe_attributes),
recipe_widget.log_details,
self,
)

Expand All @@ -674,7 +667,6 @@ def _conan_test(self) -> None:
self.command_started.emit()
recipe_widget.recipe.context.conancommand(
self._make_conan_test_package_params(recipe_attributes),
recipe_widget.log_details,
self,
)

Expand All @@ -692,7 +684,6 @@ def _conan_remove(self) -> None:
self.command_started.emit()
recipe_widget.recipe.context.conancommand(
self._make_conan_remove_package_params(recipe_attributes),
recipe_widget.log_details,
self,
)

Expand All @@ -702,7 +693,6 @@ def _cmake_build_common(
# TODO review
recipe_widget = self._recipe_widget
recipe = recipe_widget.recipe
log_details = recipe_widget.log_details
params = CommandParameters(
"cmakebuild", cruiz.workers.cmakebuildtool.invoke
) # TODO: verb is wrong
Expand All @@ -720,7 +710,7 @@ def _cmake_build_common(
if args:
params.arguments.extend(args)
self.command_started.emit()
recipe.context.cmakebuildcommand(params, log_details, self)
recipe.context.cmakebuildcommand(params, self)

def _cmake_build(self) -> None:
self._cmake_build_common()
Expand All @@ -732,7 +722,6 @@ def _cmake_remove_cache(self) -> None:
# TODO: review
recipe_widget = self._recipe_widget
recipe = recipe_widget.recipe
log_details = recipe_widget.log_details
params = CommandParameters(
"cmakeremovecache", cruiz.workers.deletecmakecache.invoke
) # TODO: verb is wrong
Expand All @@ -743,7 +732,7 @@ def _cmake_remove_cache(self) -> None:
build_folder = settings.local_workflow_build_folder.resolve()
params.build_folder = recipe_widget.resolve_expression(build_folder)
self.command_started.emit()
recipe.context.cmakebuildcommand(params, log_details, self)
recipe.context.cmakebuildcommand(params, self)

def _generate_command_tooltip(self, params: CommandParameters) -> str:
tooltip = StringIO()
Expand Down
2 changes: 1 addition & 1 deletion cruiz/remote_browser/pages/packagebinarypage.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def showEvent(self, event: QtGui.QShowEvent) -> None:
remote_name=self._ui.remote.currentText(),
where=self._artifact_folder,
)
self._context.get_package_details(params, self._log_details, self._complete)
self._context.get_package_details(params, self._complete)

def _complete(self, results: typing.Any, exception: typing.Any) -> None:
self._enable_progress(False)
Expand Down
2 changes: 1 addition & 1 deletion cruiz/remote_browser/pages/packageidpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def _compute(self) -> None:
reference=pkgref,
remote_name=self._ui.remote.currentText(),
)
self._context.get_package_details(params, self._log_details, self._complete)
self._context.get_package_details(params, self._complete)

def _on_restart(self) -> None:
self._filtering_model.invalidate()
Expand Down
2 changes: 1 addition & 1 deletion cruiz/remote_browser/pages/packagereferencepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def _search(self) -> None:
case_sensitive=True,
alias_aware=self._ui.alias_aware.isChecked(),
)
self._context.get_package_details(params, self._log_details, self._complete)
self._context.get_package_details(params, self._complete)

def _complete(self, results: typing.Any, exception: typing.Any) -> None:
self._enable_progress(False)
Expand Down
2 changes: 1 addition & 1 deletion cruiz/remote_browser/pages/packagerevisionpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _compute(self) -> None:
reference=pkgref,
remote_name=self._ui.remote.currentText(),
)
self._context.get_package_details(params, self._log_details, self._complete)
self._context.get_package_details(params, self._complete)

def _on_restart(self) -> None:
self._open_start()
Expand Down
2 changes: 1 addition & 1 deletion cruiz/remote_browser/pages/reciperevisionpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _compute(self) -> None:
reference=pkgref,
remote_name=self._ui.remote.currentText(),
)
self._context.get_package_details(params, self._log_details, self._complete)
self._context.get_package_details(params, self._complete)

def _on_copy_pkgref_to_clip(self) -> None:
QtWidgets.QApplication.clipboard().setText(self._ui.rrev_pkgref.text())

0 comments on commit b2e2f7f

Please sign in to comment.