Skip to content
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

Implement support for configuration via pyproject.toml #830

Merged
merged 1 commit into from
Aug 31, 2021

Conversation

birdcolour
Copy link
Contributor

Resolves #828.

It's slightly annoying that it's necessary to open the pyproject.toml document twice - first to check if it has a valid [tool.jupytext] table in find_jupytext_configuration_file, and then again to parse it properly in parse_jupytext_configuration_file, but I think that rewriting this code to enable a single read would be significantly more complicated, and a rather premature optimisation.

Happy to take comments - hopefully the documentation changes read clearly enough.

And once this is done, I'll open a PR here for you :)

Copy link
Owner

@mwouts mwouts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @birdcolour for your PR. I have reviewed it and it looks great - I only have a few remarks (which I can do as a follow-up if you prefer, you will let me know)

Comment on lines +324 to +329
import toml

with open(pyproject_path, "r") as stream:
doc = toml.loads(stream.read())
if doc.get("tool", {}).get("jupytext") is not None:
return pyproject_path
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you think we should have the same lines in get_config_file in the contents manager?

@@ -343,7 +355,12 @@ def parse_jupytext_configuration_file(jupytext_config_file, stream=None):
if jupytext_config_file.endswith((".toml", "jupytext")):
import toml

return toml.loads(stream)
doc = toml.loads(stream)
print(jupytext_config_file)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the print instruction?

@@ -477,6 +478,10 @@ def get_config_file(self, directory):
if self.file_exists(path):
return path

pyproject_path = directory + "/" + PYPROJECT_FILE
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the location where I think we should test whether or not there is a jupytext entry in the pyproject file.
(BTW the + "/" is correct, we could add a comment above: paths in Jupyter's contents manager always use the linux path separator, even on Windows)

@@ -81,6 +84,8 @@ or alternatively, using a dict to map the prefix path to the format name:
"notebooks/" = "ipynb"
"scripts/" = "py:percent"
```
Note that if you are using a `pyproject.toml` file with this dict format, you should make sure the table header is instead `[tool.jupytext.formats]`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for documenting this. By the way I was thinking that it would be helpful to give a small example pyproject.toml file, say e.g.

[tool.jupytext]
formats = "ipynb,py:percent"

Where do you think this example would be best located in the documentation? Maybe right after the sample jupytext.tom file with the same configuration?

@mwouts mwouts modified the milestone: 1.12.0 Jul 31, 2021
@mwouts mwouts merged commit bd776a5 into mwouts:master Aug 31, 2021
mwouts added a commit that referenced this pull request Aug 31, 2021
@mwouts mwouts mentioned this pull request Aug 31, 2021
mwouts added a commit that referenced this pull request Aug 31, 2021
* Follow-up on #830

* Update CHANGELOG.md

* In the contentsmanager we must use get() to load the pyproject.toml file
@mwouts
Copy link
Owner

mwouts commented Aug 31, 2021

Thank you @birdcolour for your PR, and sorry for taking so long to merge it! I plan to make a new version soon, meanwhile feel free to test the version on the master branch (pip install git+https://github.com/mwouts/jupytext.git). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PEP-518/pyproject.toml support
2 participants