-
Notifications
You must be signed in to change notification settings - Fork 905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make rich
traceback and REPL handling more configurable
#1728
Comments
I'm really excited for this, it would make things a lot more configurable :) We also have had reports that the logging mode on databricks is unpleasant, so maybe we should have a fallback to no rich logging too. |
Agree that it would be nice to make the rich settings more configurable, but I don't think pyproject.toml would be the right place for this. I have some ideas for how to do it - will post more later. |
pyproject.toml
to configure rich
rich
setup more configurable
rich
setup more configurablerich
traceback and REPL handling more configurable
Currently the rich setup does three slightly different things (see
Since the logging handler is already configurable on the project-side, the question of configuring the setup concerns the latter two points. Possibly in future we'll want some way for people to customise other things (e.g. turn on/off rich progress bar, change theme more easily), but let's leave that aside for now. I think there are three possible places where this sort of thing could be configured. 1. settings.pyThis is the only way that works currently. You can put your own calls to
Or effectively uninstall the rich traceback/REPL handling altogether:
2. HooksArguably setting the traceback handling would be best done through a hook in the first place. However, if a hook that does rich traceback handling is enabled by default, we'd have to think about the best way to implement that (i.e. how to register a built-in hook, how a user would disable or change hook from settings.py). Another possible use case for built-in hook might be #1563 (Maybe in future 3. logging.ymlNot currently possible but this would be a sensible place to put configuration for other rich things. e.g.
When you configure Python logging with Notes
|
Also I should say that I don't think this is urgent since I don't think it's going to be a common request, and solution 1 is a reasonable workaround. Maybe as we continue integrating rich further there will be more call for it though. |
Agree with many of the points. In short, I am in favor of solution 1. I tend to think of
One of the values that kedro is to get the best practice right out of the box, so most users shouldn't have to touch these configurations at all. If Rich Logging doesn't work well on Databricks(I think it's because of the coloring?). If colored logs is impossible on Databricks, I am in favor go all the way to disable CC @AntonyMilneQB |
Thanks for the comments @noklam. Completely agree that we should try to make it so that people don't have to touch any settings at all by default, although in the databricks case I would point out:
And just for reference (to explain more why, as you point out, |
For me the Is there a workaround for my case to revert the installation of |
@pstanisl Can you explain it a little bit more? How would it behave differently without |
In the image below, you can see the difference. In the first cell, the Databricks properly catch the exception and highlight the error cell, i.e., stop the execution of the notebook if required. After installing So imagine, I have a Kedro project deployed as a Databricks job by dbx. I orchestrate it from Azure Data Factory. Suppose there is any issue in the Kedro pipeline. In that case, the job will end up successfully, and Azure Data Factory will continue with the following steps because no error is returned from Databricks. |
@pstanisl The lost of color log is definitely not ideal, but I think it is still a proper |
@noklam The color is not a problem at all. The problem is running following cells, see video below Zaznam.obrazovky.2022-08-03.v.14.44.57.movSame for Kedro project and orchecstration. |
I have the impression that PyCharm is also confused by the rich backtrace. |
@mjmare Sorry that this is no the smoothest experience, we shoule have highlights this. In Pycharm you need to set emulate terminal and it would become a clickable traceback again. |
Unfortunately that does not work. Enabling the "emulate terminal in output console" option (which I have disabled by default) does nothing for me except make the mess colourful.
in settings.py. |
@AntonyMilneQB and @noklam for Jupyter/Databricks notebook workaround #1 does not work because What is working is to save ip = get_ipython()
ip__showtraceback = ip._showtraceback
from kedro.framework.startup import bootstrap_project
ip._showtraceback = ip__showtraceback It will revert |
@mjmare This works for me, I am not sure if the version of PyCharm matters. OS: MacOS Settings for PyCharm |
@pstanisl thank you very much for this very clear explanation and the workaround. I definitely understand why this would be a problem. It only seems to happen on Databricks (not plain Jupyter), so must be something to do with how they wrap the default IPython exception handling 😬 We could try to ask rich to fix this but it might be a tall order unfortunately. I had also figured out that reverting |
Hi @noklam, I'm using PyCharm: on OSX. I use ZSH as my shell. As soon as I turn on emulate terminal option, everything turns into a mess. |
@pstanisl please could you try this out in Databricks for me? 🙂
This should undo all of the modifications rich makes to the tracebacks. The problem might be that it replaces the Ultimately, though, I think we will probably just have to turn off rich traceback handling in databricks (or add something to rich that does that). |
@mjmare Would you be able to drop a gif or a screenshot how does it looks like with emulated mode? |
Thanks for checking @pstanisl. Last try - I think the correct equivalent on Databricks would actually be this:
|
@AntonyMilneQB same result (original formatting of the error but still ignoring it), but with the message after importing /databricks/python_shell/scripts/PythonShell.py:46: ImportWarning: PythonShell.py is a launch script, which shall not be imported directly. You might want to import PythonShellImpl instead. Call stack:
File "/databricks/python_shell/scripts/PythonShell.py", line 29, in <module>
launch_process()
File "/databricks/python_shell/scripts/PythonShellImpl.py", line 1233, in launch_process
shell.executor.run()
File "/databricks/python_shell/scripts/PythonShellImpl.py", line 268, in run
self.shell.shell.run_cell(command_id, cmd, store_history=True)
File "/databricks/python_shell/scripts/PythonShellImpl.py", line 756, in run_cell
super(IPythonShell, self).run_cell(raw_cell, store_history, silent, shell_futures)
File "/databricks/python/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2894, in run_cell
result = self._run_cell(
File "/databricks/python/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2940, in _run_cell
return runner(coro)
File "/databricks/python/lib/python3.8/site-packages/IPython/core/async_helpers.py", line 68, in _pseudo_sync_runner
coro.send(None)
File "/databricks/python/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3165, in run_cell_async
has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
File "/databricks/python/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3357, in run_ast_nodes
if (await self.run_code(code, result, async_=asy)):
File "/databricks/python/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<command-3483914239647235>", line 1, in <module>
from PythonShell import InteractiveShell
File "/databricks/python_shell/dbruntime/PythonPackageImportsInstrumentation/__init__.py", line 167, in import_patch
original_result = python_builtin_import(name, globals, locals, fromlist, level)
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/databricks/python_shell/scripts/PythonShell.py", line 42, in <module>
traceback.print_stack(file=call_stack)
warnings.warn( with from PythonShellImpl import InteractiveShell
ip._showtraceback = InteractiveShell()._showtraceback
ip.showtraceback = InteractiveShell().showtraceback
ip.showsyntaxerror = InteractiveShell().showsyntaxerror the same behavior (original formatting of the error but still ignoring it) without warning. |
Thanks very much for all your testing @pstanisl, much appreciated. Thanks also for raising the issue on the rich repo - I was just about to do so and saw that you had already! Textualize/rich#2455 I've created a draft PR for kedro which would disable rich traceback handling on databricks so you don't need to do so yourself: #1769. Hopefully this gets fixed on the rich side so we don't need to merge it, but if they can't fix it then this should do it. |
We have the thumbs up in principle to adding/improving an |
I've expressed this before, but I personally like the approach libraries like Typer take in enabling |
Adding here that we're facing the exact same problem as @pstanisl, if it helps in any way with raising the priority. The issue is currently blocking us from detecting errors in kedro pipelines executed on Databricks:
|
One possibly related point - by default, logging goes into stderr, for some reason RichHandler changes that. To enforce this behaviour you have to do: RichHandler(console=Console(stderr=True)) |
Just for the record, I think there's going to be much less call for making the rich settings configurable following the changes made in Kedro 0.18.3. I'm leaving this discussion open because I think it's something we should still think about and I'm interested in hearing if users continue to ask for such a feature, but I don't think it's at all urgent at the moment. We should deal with this as part of Logging improvements part 2 which I'll develop further in #1461 or a new issue in due course. Given the other things that might need to be changed there for Kedro 0.19, I think ultimately the right setup here might be different from all three options I outlined above and instead rely on hooks. |
Superseded by #2206. |
Is it worth to add a section to
pyproject.toml
to configure settings forrich
, e.g.[tool.kedro.rich]
? Would this allow users to for example changeshow_locals
to be set toTrue
? (See #1712 for why we set it toFalse
)The text was updated successfully, but these errors were encountered: