-
Notifications
You must be signed in to change notification settings - Fork 76
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
autoloading_settings #726
autoloading_settings #726
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added some comments
src/tests/test_magic.py
Outdated
|
||
|
||
def test_loading_config(request, monkeypatch, ip, capsys): | ||
monkeypatch.chdir(request.fspath.dirname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use fixtures for changing directories like here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used tmp_empty
fixture for changing to an empty tmp directory.
From the acceptance criteria, we established to use the default value if an invalid configuration setting is provided, but if we think raising an error is more appropriate, I will make the change.
@neelasha23 For the bullet points 4, 5, and 6, do you mean check the |
You can add a function to perform basic validations on the
|
Added the validations in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the HTML table to show the changed settings is a nice touch, good job!
my feedback:
an empty pyproject.toml gives a long traceback with this error: KeyError: "'tool' not found from pyproject.toml. Please check the following section names: ." fix: an empty pyproject.toml should not give any errors.
also, if the pyproject has content but the "tool" section doesn't exist the same error is shown. but it shouldn't. if the "tool" section is missing, nothing should happen (do not load anything, just ignore the pyproject.toml)
if the "tool" section exists but an inner "jupysql" section doesn't I get: KeyError: "'jupysql' not found from pyproject.toml. Please check the following section names: 'pkgmt'." This shouldn't happen as adding the configuration via a pyproject.toml is optional.
if "SqlMagic" doesn't exist, I get: KeyError: "'SqlMagic' not found from pyproject.toml. Please check the following section names: 'x'." but this shouldn't happen (it should ignore the pyproject.toml it since there is no SqlMagic configuration to apply)
When loading a valid config I see "'x' is an invalid configuration. Please review our configuration guideline: https://jupysql.ploomber.io/en/latest/api/configuration.html#options. however, the link is not clickable, please add it as an HTML link so people can click on them
when passing an invalid type, I see: "'a' is an invalid value for 'autopandas'. Please use <class 'bool'> value instead.". no need to show "<class 'bool'", you can get the type name with __name__
, example: bool.__name__
so the error shows "'a' is an invalid value for 'autopandas'. Please use a bool value instead.".
When I pass "autopandas = True", I get "ValueError: Invalid value 'True' in 'autopandas = True'. Valid boolean values: true, false". The error messag is fine but you should raise a custom error (https://github.com/ploomber/jupysql/blob/master/src/sql/exceptions.py). create a ConfigurationError and raise that one. this will allow us to hide the traceback, which is too verbose
When loading the pyproject.toml, I get "Found pyproject.toml from '/Users/eduardo/Desktop/testing-autoloadsettings'", it'd be better to show it relative to the current directory. you can use pathlib.Path to convert that absolute path into a relative one
please fix and add test cases for all of these scenarios
noqa added update test to check configurations update based on the first comments lint get_default_configs doc rephrase draft autoloading error fixed lint fix ci changing toml into optional update util.py link fix fix test functions and rename ci escape added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! nice work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like an invalid TOML is still a problem:
[tool.jupysql.SqlMagic]
autopandas = False
displaylimit = 2
when I create something like this along with a notebook with a %load_ext sql
cell, and then start JupyterLab, it breaks it.
Instead, I'd expect JupyterLab to work normally and %load_ext sql
to output a message saying the TOML is invalid.
@bbeat2782 try with JupyterLab instead of VSCode, as they behave differently. In my case, when I start JupyterLab in the folder that has the notebook and the TOML, it breaks and I'm unable to open any files, plus, the jupyter console shows the TOML error. |
I think I replicated the error. I will work on it. |
I tried creating a new branch from the master and only added
to the toml file, and it still shows the TOML error. And I'm unable to open any files. Looking at the error log, I think it's because of how the jupyter lab package handles the TOML file parse error, not because of when we call |
can you share the full traceback? i doubt JupyterLab is breaking because of the pyproject.toml, it might be that you have jupytext installed, check this: mwouts/jupytext#1103 |
Yes, it's coming from the jupytext. This is the traceback I get when I run Server error: Traceback (most recent call last): File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/toml/decoder.py", line 511, in loads ret = decoder.load_line(line, currentlevel, multikey, File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/toml/decoder.py", line 778, in load_line value, vtype = self.load_value(pair[1], strictly_valid) File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/toml/decoder.py", line 820, in load_value raise ValueError("Only all lowercase booleans allowed") ValueError: Only all lowercase booleans allowed During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/tornado/web.py", line 1786, in _execute result = await result File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/tornado/gen.py", line 234, in wrapper yielded = ctx_run(next, result) File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/notebook/services/contents/handlers.py", line 118, in get model = yield maybe_future(self.contents_manager.get( File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 199, in get return self.super.get(path, content, type, format) File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/notebook/services/contents/filemanager.py", line 448, in get model = self._dir_model(path, content=content) File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/notebook/services/contents/filemanager.py", line 343, in _dir_model self.get(path=f'{path}/{name}', content=False) File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 201, in get config = self.get_config(path, use_cache=content is False) File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 571, in get_config config_file = self.get_config_file(parent_dir) File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/jupytext/contentsmanager.py", line 518, in get_config_file doc = toml.loads(model["content"]) File "/Users/sanggyuan/miniconda3/envs/jupysql/lib/python3.10/site-packages/toml/decoder.py", line 514, in loads raise TomlDecodeError(str(err), original, pos) toml.decoder.TomlDecodeError: Only all lowercase booleans allowed (line 2 column 1 char 24) |
the traceback is a bit hard to read but yeah it's coming from jupytext. uninstall jupytext it and it will be fixed, then you can test if some changes to the PR are needed |
@bbeat2782 please fix merge conflicts and request a review when ready |
to reflect ip.run_cell raising exception immediately
great work @bbeat2782! |
Describe your changes
pyproject.toml
file. This includes looking up in parent directories.pyproject.toml
displays loaded settings and changes configuration settings.difflib
is unable to find the closest match, it displays a message with a link to the docspyproject.toml
Issue number
Closes #689
Checklist before requesting a review
pkgmt format
📚 Documentation preview 📚: https://jupysql--726.org.readthedocs.build/en/726/