Skip to content

Commit

Permalink
Precommit autoupdate (#913)
Browse files Browse the repository at this point in the history
* pre-commit autoupdate

* pre-commit run --all

* Update CHANGELOG.md
  • Loading branch information
mwouts authored Feb 4, 2022
1 parent 97c74b0 commit a1795e0
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 63 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exclude: >
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.1.0
hooks:
- id: check-json
- id: check-yaml
Expand All @@ -32,19 +32,19 @@ repos:
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.1
rev: 3.9.2
hooks:
- id: flake8

- repo: https://github.com/PyCQA/isort
rev: 5.8.0
rev: 5.10.1
hooks:
# isort needs the 'black' profile when used in combination with black
# See https://github.com/PyCQA/isort/issues/1518
- id: isort
args: ["--profile", "black"]

- repo: https://github.com/psf/black
rev: 21.4b2
rev: 22.1.0
hooks:
- id: black
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Jupytext ChangeLog
**Added**
- Added Haskell as supported language ([#909](https://github.com/mwouts/jupytext/issues/909)) - thanks to [codeweber](https://github.com/codeweber) for this contribution

**Changed**
- We have updated the pre-commit hooks and in particular we switched to the first stable version of `black==22.1.0`.


1.13.6 (2022-01-11)
-------------------
Expand Down
24 changes: 11 additions & 13 deletions jupytext/contentsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,9 @@ def save_one_file(path, fmt):
return write_pair(path, jupytext_formats, save_one_file)

except Exception as e:
self.log.error(
u"Error while saving file: %s %s", path, e, exc_info=True
)
self.log.error("Error while saving file: %s %s", path, e, exc_info=True)
raise HTTPError(
500, u"Unexpected error while saving file: %s %s" % (path, e)
500, "Unexpected error while saving file: %s %s" % (path, e)
)

def get(
Expand Down Expand Up @@ -223,7 +221,7 @@ def get(
)
except Exception as err:
self.log.error(
u"Error while reading file: %s %s", path, err, exc_info=True
"Error while reading file: %s %s", path, err, exc_info=True
)
raise HTTPError(500, str(err))

Expand Down Expand Up @@ -263,7 +261,7 @@ def get(
self.update_paired_notebooks(path, formats)
except InconsistentPath as err:
self.log.error(
u"Unable to read paired notebook: %s %s",
"Unable to read paired notebook: %s %s",
path,
err,
exc_info=True,
Expand Down Expand Up @@ -292,12 +290,12 @@ def read_one_file(alt_path, alt_fmt):
if alt_path == path:
return model["content"]
if alt_path.endswith(".ipynb"):
self.log.info(u"Reading OUTPUTS from {}".format(alt_path))
self.log.info("Reading OUTPUTS from {}".format(alt_path))
return self.super.get(
alt_path, content=True, type="notebook", format=format
)["content"]

self.log.info(u"Reading SOURCE from {}".format(alt_path))
self.log.info("Reading SOURCE from {}".format(alt_path))
text = self.super.get(
alt_path, content=True, type="file", format=format
)["content"]
Expand Down Expand Up @@ -372,7 +370,7 @@ def read_one_file(alt_path, alt_fmt):
raise
except Exception as err:
self.log.error(
u"Error while reading file: %s %s", path, err, exc_info=True
"Error while reading file: %s %s", path, err, exc_info=True
)
raise HTTPError(500, str(err))

Expand Down Expand Up @@ -403,7 +401,7 @@ def new_untitled(self, path="", type="", ext=""):
untitled = self.untitled_notebook
config = self.get_config(path)
name = self.increment_notebook_filename(config, untitled + ext, path)
path = u"{0}/{1}".format(path, name)
path = "{0}/{1}".format(path, name)

model = {"type": "notebook"}
if format_name:
Expand All @@ -429,7 +427,7 @@ def increment_notebook_filename(self, config, filename, path=""):
basename_i = basename + insert_i
name = basename_i + ext
if not any(
self.exists(u"{}/{}{}".format(path, basename_i, nb_ext))
self.exists("{}/{}{}".format(path, basename_i, nb_ext))
for nb_ext in config.notebook_extensions
):
break
Expand Down Expand Up @@ -470,7 +468,7 @@ def rename_file(self, old_path, new_path):
raise
except Exception as err:
self.log.error(
u"Error while renaming file from %s to %s: %s",
"Error while renaming file from %s to %s: %s",
old_path,
new_path,
err,
Expand Down Expand Up @@ -553,7 +551,7 @@ def get_config(self, path, use_cache=False):
self.cached_config.path = parent_dir
except JupytextConfigurationError as err:
self.log.error(
u"Error while reading config file: %s %s",
"Error while reading config file: %s %s",
config_file,
err,
exc_info=True,
Expand Down
14 changes: 5 additions & 9 deletions jupytext/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,15 +693,11 @@ def short_form_one_format(jupytext_format):
fmt = jupytext_format["prefix"] + "/" + fmt

if jupytext_format.get("format_name"):
if (
jupytext_format["extension"]
not in [
".md",
".markdown",
".Rmd",
]
or jupytext_format["format_name"] in ["pandoc", MYST_FORMAT_NAME]
):
if jupytext_format["extension"] not in [
".md",
".markdown",
".Rmd",
] or jupytext_format["format_name"] in ["pandoc", MYST_FORMAT_NAME]:
fmt = fmt + ":" + jupytext_format["format_name"]

return fmt
Expand Down
5 changes: 2 additions & 3 deletions jupytext/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,10 @@ def set_main_and_cell_language(metadata, cells, ext, custom_cell_magics):
if "magic_args" in cell["metadata"]:
magic_args = cell["metadata"].pop("magic_args")
cell["source"] = (
u"{}{} {}\n".format(magic, language, magic_args)
+ cell["source"]
"{}{} {}\n".format(magic, language, magic_args) + cell["source"]
)
else:
cell["source"] = u"{}{}\n".format(magic, language) + cell["source"]
cell["source"] = "{}{}\n".format(magic, language) + cell["source"]


def cell_language(source, default_language, custom_cell_magics):
Expand Down
24 changes: 12 additions & 12 deletions jupytext/paired_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def base_path(main_path, fmt, formats=None):

if ext != fmt["extension"]:
raise InconsistentPath(
u"Notebook path '{}' was expected to have extension '{}'".format(
"Notebook path '{}' was expected to have extension '{}'".format(
main_path, fmt["extension"]
)
)
Expand Down Expand Up @@ -81,7 +81,7 @@ def base_path(main_path, fmt, formats=None):
if suffix:
if not base.endswith(suffix):
raise InconsistentPath(
u"Notebook name '{}' was expected to end with suffix '{}'".format(
"Notebook name '{}' was expected to end with suffix '{}'".format(
base, suffix
)
)
Expand Down Expand Up @@ -109,7 +109,7 @@ def base_path(main_path, fmt, formats=None):
if prefix_file_name:
if not notebook_file_name.startswith(prefix_file_name):
raise InconsistentPath(
u"Notebook name '{}' was expected to start with prefix '{}'".format(
"Notebook name '{}' was expected to start with prefix '{}'".format(
notebook_file_name, prefix_file_name
)
)
Expand All @@ -124,7 +124,7 @@ def base_path(main_path, fmt, formats=None):
if expected_folder == "..":
if not actual_folders:
raise InconsistentPath(
u"Notebook directory '{}' does not match prefix '{}'".format(
"Notebook directory '{}' does not match prefix '{}'".format(
notebook_dir, prefix_dir
)
)
Expand All @@ -137,7 +137,7 @@ def base_path(main_path, fmt, formats=None):

if actual_folder != expected_folder:
raise InconsistentPath(
u"Notebook directory '{}' does not match prefix '{}'".format(
"Notebook directory '{}' does not match prefix '{}'".format(
notebook_dir, prefix_dir
)
)
Expand All @@ -148,7 +148,7 @@ def base_path(main_path, fmt, formats=None):
long_notebook_dir = sep + notebook_dir + sep
if long_prefix_root not in long_notebook_dir:
raise InconsistentPath(
u"Notebook directory '{}' does not match prefix root '{}'".format(
"Notebook directory '{}' does not match prefix root '{}'".format(
notebook_dir, prefix_root
)
)
Expand Down Expand Up @@ -190,8 +190,8 @@ def full_path(base, fmt):

if (prefix_root != "") != ("//" in base):
raise InconsistentPath(
u"Notebook base name '{}' is not compatible with fmt={}. Make sure you use prefix roots "
u"in either none, or all of the paired formats".format(
"Notebook base name '{}' is not compatible with fmt={}. Make sure you use prefix roots "
"in either none, or all of the paired formats".format(
base, short_form_one_format(fmt)
)
)
Expand Down Expand Up @@ -237,7 +237,7 @@ def find_base_path_and_format(main_path, formats):
continue

raise InconsistentPath(
u"Path '{}' matches none of the export formats. "
"Path '{}' matches none of the export formats. "
"Please make sure that jupytext.formats covers the current file "
"(e.g. add '{}' to the export formats)".format(
main_path, os.path.splitext(main_path)[1][1:]
Expand All @@ -258,8 +258,8 @@ def paired_paths(main_path, fmt, formats):

if main_path not in paths:
raise InconsistentPath(
u"Paired paths '{}' do not include the current notebook path '{}'. "
u"Current format is '{}', and paired formats are '{}'.".format(
"Paired paths '{}' do not include the current notebook path '{}'. "
"Current format is '{}', and paired formats are '{}'.".format(
"','".join(paths),
main_path,
short_form_one_format(fmt),
Expand All @@ -269,7 +269,7 @@ def paired_paths(main_path, fmt, formats):

if len(paths) > len(set(paths)):
raise InconsistentPath(
u"Duplicate paired paths for this notebook. Please fix jupytext.formats."
"Duplicate paired paths for this notebook. Please fix jupytext.formats."
)

return list(zip(paths, formats))
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ def test_cli_can_infer_jupytext_format_from_stdin(nb_file, tmpdir, cwd_tmpdir):


def test_set_kernel_works_with_pipes_326(capsys):
md = u"""```python
md = """```python
1 + 1
```"""

Expand All @@ -690,7 +690,7 @@ def test_set_kernel_works_with_pipes_326(capsys):
@skip_on_windows
@pytest.mark.filterwarnings("ignore")
def test_utf8_out_331(capsys, caplog):
py = u"from IPython.core.display import HTML; HTML(u'\xd7')"
py = "from IPython.core.display import HTML; HTML(u'\xd7')"

with mock.patch("sys.stdin", StringIO(py)):
jupytext(["--to", "ipynb", "--execute", "-"])
Expand All @@ -701,7 +701,7 @@ def test_utf8_out_331(capsys, caplog):
nb = reads(out, "ipynb")
assert len(nb.cells) == 1
print(nb.cells[0].outputs)
assert nb.cells[0].outputs[0]["data"]["text/html"] == u"\xd7"
assert nb.cells[0].outputs[0]["data"]["text/html"] == "\xd7"


@requires_jupytext_installed
Expand Down
24 changes: 12 additions & 12 deletions tests/test_contentsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,12 @@ def test_load_save_rename_nbpy_default_config(nb_file, tmpdir):

@pytest.mark.parametrize("nb_file", list_notebooks("ipynb_py"))
def test_load_save_rename_non_ascii_path(nb_file, tmpdir):
tmp_ipynb = u"notebôk.ipynb"
tmp_nbpy = u"notebôk.nb.py"
tmp_ipynb = "notebôk.ipynb"
tmp_nbpy = "notebôk.nb.py"

cm = jupytext.TextFileContentsManager()
cm.formats = "ipynb,.nb.py"
tmpdir = u"" + str(tmpdir)
tmpdir = "" + str(tmpdir)
cm.root_dir = tmpdir

# open ipynb, save nb.py, reopen
Expand All @@ -444,20 +444,20 @@ def test_load_save_rename_non_ascii_path(nb_file, tmpdir):
cm.save(model=notebook_model(nb), path=tmp_ipynb)

# rename notebôk.nb.py to nêw.nb.py
cm.rename(tmp_nbpy, u"nêw.nb.py")
cm.rename(tmp_nbpy, "nêw.nb.py")
assert not os.path.isfile(os.path.join(tmpdir, tmp_ipynb))
assert not os.path.isfile(os.path.join(tmpdir, tmp_nbpy))

assert os.path.isfile(os.path.join(tmpdir, u"nêw.ipynb"))
assert os.path.isfile(os.path.join(tmpdir, u"nêw.nb.py"))
assert os.path.isfile(os.path.join(tmpdir, "nêw.ipynb"))
assert os.path.isfile(os.path.join(tmpdir, "nêw.nb.py"))

# rename nêw.ipynb to notebôk.ipynb
cm.rename(u"nêw.ipynb", tmp_ipynb)
cm.rename("nêw.ipynb", tmp_ipynb)
assert os.path.isfile(os.path.join(tmpdir, tmp_ipynb))
assert os.path.isfile(os.path.join(tmpdir, tmp_nbpy))

assert not os.path.isfile(os.path.join(tmpdir, u"nêw.ipynb"))
assert not os.path.isfile(os.path.join(tmpdir, u"nêw.nb.py"))
assert not os.path.isfile(os.path.join(tmpdir, "nêw.ipynb"))
assert not os.path.isfile(os.path.join(tmpdir, "nêw.nb.py"))


@pytest.mark.parametrize("nb_file", list_notebooks("ipynb_py")[:1])
Expand Down Expand Up @@ -843,8 +843,8 @@ def test_pair_notebook_with_dot(nb_file, tmpdir):
@pytest.mark.parametrize("nb_file", list_notebooks("ipynb_py")[:1])
def test_preferred_format_allows_to_read_others_format(nb_file, tmpdir):
# 1. write py ipynb
tmp_ipynb = u"notebook.ipynb"
tmp_nbpy = u"notebook.py"
tmp_ipynb = "notebook.ipynb"
tmp_nbpy = "notebook.py"

cm = jupytext.TextFileContentsManager()
cm.preferred_jupytext_formats_save = "py:light"
Expand Down Expand Up @@ -884,7 +884,7 @@ def test_preferred_format_allows_to_read_others_format(nb_file, tmpdir):


def test_preferred_formats_read_auto(tmpdir):
tmp_py = u"notebook.py"
tmp_py = "notebook.py"
with open(str(tmpdir.join(tmp_py)), "w") as script:
script.write(
"""# cell one
Expand Down
4 changes: 2 additions & 2 deletions tests/test_read_simple_R.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_read_less_simple_file(
@pytest.mark.parametrize("ext", [".r", ".R"])
def test_no_space_after_code(
ext,
rnb=u"""# -*- coding: utf-8 -*-
rnb="""# -*- coding: utf-8 -*-
#' Markdown cell
f <- function(x)
Expand All @@ -131,7 +131,7 @@ def test_no_space_after_code(
}"""
)
assert nb.cells[2].cell_type == "markdown"
assert nb.cells[2].source == u"And a new cell, and non ascii contênt"
assert nb.cells[2].source == "And a new cell, and non ascii contênt"

rnb2 = jupytext.writes(nb, ext)
compare(rnb2, rnb)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_read_simple_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def test_read_multiline_comment(


def test_no_space_after_code(
pynb=u"""# -*- coding: utf-8 -*-
pynb="""# -*- coding: utf-8 -*-
# Markdown cell
def f(x):
Expand All @@ -634,7 +634,7 @@ def f(x):
assert nb.cells[1].cell_type == "code"
assert nb.cells[1].source == "def f(x):\n return x+1"
assert nb.cells[2].cell_type == "markdown"
assert nb.cells[2].source == u"And a new cell, and non ascii contênt"
assert nb.cells[2].source == "And a new cell, and non ascii contênt"

pynb2 = jupytext.writes(nb, "py")
compare(pynb2, pynb)
Expand Down
Loading

0 comments on commit a1795e0

Please sign in to comment.