-
Notifications
You must be signed in to change notification settings - Fork 392
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,9 @@ class JupytextConfigurationError(ValueError): | |
JUPYTEXT_CONFIG_FILES.extend( | ||
["." + filename for filename in JUPYTEXT_CONFIG_FILES] + [".jupytext.py"] | ||
) | ||
|
||
PYPROJECT_FILE = "pyproject.toml" | ||
|
||
JUPYTEXT_CEILING_DIRECTORIES = [ | ||
path | ||
for path in os.environ.get("JUPYTEXT_CEILING_DIRECTORIES", "").split(":") | ||
|
@@ -316,6 +319,15 @@ def find_jupytext_configuration_file(path, search_parent_dirs=True): | |
if os.path.isfile(full_path): | ||
return full_path | ||
|
||
pyproject_path = os.path.join(path, PYPROJECT_FILE) | ||
if os.path.isfile(pyproject_path): | ||
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 | ||
Comment on lines
+324
to
+329
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you think we should have the same lines in |
||
|
||
if not search_parent_dirs: | ||
return None | ||
|
||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove the |
||
if jupytext_config_file.endswith(PYPROJECT_FILE): | ||
return doc["tool"]["jupytext"] | ||
else: | ||
return doc | ||
|
||
if jupytext_config_file.endswith((".yml", ".yaml")): | ||
return yaml.safe_load(stream) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
from .config import ( | ||
JUPYTEXT_CONFIG_FILES, | ||
PYPROJECT_FILE, | ||
JupytextConfiguration, | ||
JupytextConfigurationError, | ||
find_global_jupytext_configuration_file, | ||
|
@@ -477,6 +478,10 @@ def get_config_file(self, directory): | |
if self.file_exists(path): | ||
return path | ||
|
||
pyproject_path = directory + "/" + PYPROJECT_FILE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if self.file_exists(pyproject_path): | ||
return pyproject_path | ||
|
||
if not directory: | ||
return None | ||
|
||
|
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.
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.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?