Make suggested resume commands copy-pasteable even when they extend over multiple lines#4709
Conversation
Signed-off-by: David Stanley <david_stanley@mckinsey.com>
Signed-off-by: David Stanley <david_stanley@mckinsey.com>
Signed-off-by: David Stanley <david_stanley@mckinsey.com>
…ver multiple lines By logging without formatting (e.g. line breaks for text wrap, padding, etc) Signed-off-by: David Stanley <david_stanley@mckinsey.com>
a98b2f3 to
eb2d69d
Compare
|
Thanks for this PR @david-stanley-94 ! A couple of questions:
|
def _resolve_project_path(
path: str | None = None, local_namespace: dict[str, Any] | None = None
) -> Path:
"""
Resolve the project path to use with reload_kedro, updating or adding it
(in-place) to the local ipython Namespace (``local_namespace``) if necessary.
Arguments:
path: the path to use as a string object
local_namespace: Namespace with local variables of the scope where the line
magic is invoked in a dict.
"""
if path:
project_path = Path(path).expanduser().resolve()
else:
if (
local_namespace
and local_namespace.get("context")
and hasattr(local_namespace["context"], "project_path")
):
project_path = local_namespace["context"].project_path
else:
project_path = _find_kedro_project(Path.cwd())
if project_path:
logger.info(
"Resolved project path as: %s.\nTo set a different path, run "
"'%%reload_kedro <project_root>'",
project_path,
)
|
|
Is this a lot different from the suggestion in the docs https://docs.kedro.org/en/stable/logging/index.html#how-to-use-plain-console-logging ? |
That's a work around of sorts (for anyone working with medium to large sized pipelines), but I see the issue itself as being that kedro gives suggested console commands implicitly for users to copy paste, that are not directly copy pasteable when formatted using rich. One alternative is to move away from rich formatting, to another formatter that has more compatibility with copy pasting, but I understand from previous comments that is no easy task due to an indirect dependency on rich. So another alternative is to selectively change the formatting of elements intended to be copy pasteable, to use a plain text handler. |
|
I understand the problem here when I see there are option for soft-wrapping but it doesn't seem to be available for |
|
After running both the I feel like this is kind of a personal preference thing and I'm not sure this actually adds significant value that merits this being added to the Kedro core. With the |
|
Yeah the aim is to solve issues akin to that described in #3276 , as opposed to more generally changing how logging is done. Ideally the logging formatting/behaviour would stay exactly as it is, just that long resume commands are copy pasteable (as implicitly intended and is the case for short ones) and long filepaths are correctly clickable (as is the case for short ones). One use case would be running a large pipeline taking 30 mins to run, that breaks almost at the end. The user can copy paste out the resume command, and then fix the bug. Currently they will then have to spend some time (several minutes? I forget how long this has taken me before) fixing the broken command, or else rerun from the beginning (taking 30 mins). Ideally, they would just be able to copy paste straight back into the terminal without delay (a couple of seconds). |
|
I haven't said anything here because I haven't had time to properly review the changes but I think we should not underestimate the impact of Kedro logs not being easily copy-pasteable by default. It's something that bites me almost every week. |
|
Hi @david-stanley-94 , Thank you for the contribution. Apologies for the delayed response on this. Have you tried Rich Text and would it be helpful if we use it in areas where copy-pasting should be supported, instead of adding a new handler ? I tried using rich Text for the example screenshot and it outputs similar to what you have with the new handler -
Let me know what you think of this. Thank you |
|
Thanks for the suggestion, @ravi-kumar-pilla! Would need to test if that works as an alternative. I wanna say I tested this at the time and that it didn't, but tbh it's so long ago now I don't remember, and it seems I didn't document what things, other than a different logger, that I had tried (sorry about that). |

Description
Development notes
logging.pyframework/project/rich_logging.yml(where the rich handler is configured)runner/runner.py(where the rich handler is used)postfixvariable in the_suggest_resume_scenariomethod, inrunner/runner.py. The text preceding the suggested command is still to use the rich handler.On testing, gives the following output for arbitrary error raised in a node:
Developer Certificate of Origin
We need all contributions to comply with the Developer Certificate of Origin (DCO). All commits must be signed off by including a
Signed-off-byline in the commit message. See our wiki for guidance.If your PR is blocked due to unsigned commits, then you must follow the instructions under "Rebase the branch" on the GitHub Checks page for your PR. This will retroactively add the sign-off to all unsigned commits and allow the DCO check to pass.
Checklist
RELEASE.mdfile