Skip to content

Commit

Permalink
fix set-kernel when extension is implicit
Browse files Browse the repository at this point in the history
Closes #326
  • Loading branch information
mwouts committed Sep 17, 2019
1 parent 818f7e1 commit 5c0ce2b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Release History
**BugFixes**

- Flag `--warn-only` catches every possible error (#263)
- Treat `.md` and `.markdown` files identically (#325)
- Make sure `--set-kernel` can be used with pipes (#326)

1.2.3 (2019-09-02)
++++++++++++++++++++++
Expand Down
3 changes: 1 addition & 2 deletions jupytext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ def jupytext_single_file(nb_file, args, log):
if args.update_metadata:
log("[jupytext] Updating notebook metadata with '{}'".format(json.dumps(args.update_metadata)))
# Are we updating a text file that has a metadata filter? #212
if fmt['extension'] != '.ipynb' and \
notebook.metadata.get('jupytext', {}).get('notebook_metadata_filter') == '-all':
if notebook.metadata.get('jupytext', {}).get('notebook_metadata_filter') == '-all':
notebook.metadata.get('jupytext', {}).pop('notebook_metadata_filter')
recursive_update(notebook.metadata, args.update_metadata)

Expand Down
17 changes: 16 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import time
import stat
from io import StringIO

try:
import unittest.mock as mock
Expand All @@ -16,7 +17,7 @@
from nbformat.v4.nbbase import new_notebook, new_markdown_cell, new_code_cell
from jupyter_client.kernelspec import find_kernel_specs, get_kernel_spec
from jupytext import __version__
from jupytext import read, write, writes
from jupytext import read, reads, write, writes
from jupytext.cli import parse_jupytext_args, jupytext, system, str2bool
from jupytext.compare import compare_notebooks
from jupytext.paired_paths import paired_paths, InconsistentPath
Expand Down Expand Up @@ -753,6 +754,20 @@ def test_cli_can_infer_jupytext_format_from_stdin(nb_file, tmpdir):
compare_notebooks(nb, nb2, 'Rmd')


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

with mock.patch('sys.stdin', StringIO(md)):
jupytext(['--to', 'ipynb', '--set-kernel', '-', '-'])

out, err = capsys.readouterr()
assert err == ''
nb = reads(out, 'ipynb')
assert 'kernelspec' in nb.metadata


@requires_jupytext_installed
def test_cli_expect_errors(tmp_ipynb):
with pytest.raises(ValueError):
Expand Down

0 comments on commit 5c0ce2b

Please sign in to comment.