Skip to content

Commit

Permalink
Merge pull request #7 from mwouts/minor_fixes
Browse files Browse the repository at this point in the history
New release v0.2.3
  • Loading branch information
mwouts authored Jun 28, 2018
2 parents dcc67ae + 9f127a4 commit 80f0a39
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 14 deletions.
13 changes: 13 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ Release History
dev
+++

0.2.3 (2018-06-28)
+++++++++++++++++++

**Improvements**

- Screenshots in README

**BugFixes**

- rmarkdown exporter for nbconvert fixed on non-recent python
- Tests compatible with other revisions of nbformat >= 4.0
- Tests compatible with older pytest versions


0.2.2 (2018-06-28)
+++++++++++++++++++
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ pip install nbrmd
jupyter notebook
```

Now you will be able to open your `.md` and `.Rmd` notebooks directly in Jupyter:

Rmd notebook in jupyter | Rmd notebook as text
:--------------------------:|:-----------------------:
![](img/rmd_notebook.png) | ![](img/rmd_in_text_editor.png)


## Can I save my Jupyter notebook as both R markdown and ipynb ?

### Per-notebook configuration
Expand Down Expand Up @@ -105,9 +112,14 @@ nbrmd jupyter.ipynb -i # this creates a jupyter.Rmd file
nbrmd jupyter.Rmd -i # and this, a jupyter.ipynb file
```

Alternatively, the `nbrmd` package provides a `nbconvert` rmarkdown exporter that you can use with
```bash
nbconvert jupyter.ipynb --to rmarkdown
```

## And if I convert twice?

Round trip conversion of R markdown is identity.
Round trip conversion of Jupyter notebooks preserves the source.
Outputs are lost, however, like in any good [pre-commit hooks](https://gist.github.com/minrk/6176788).
Outputs are lost, however, like in any git pre-commit hook for notebooks.

Binary file added img/rmd_in_text_editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/rmd_notebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion nbrmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
update_rmd_and_ipynb, update_selected_formats

try:
from .nbconvert import RMarkdownExporter
from .rmarkdownexporter import RMarkdownExporter
except ImportError as e:
RMarkdownExporter = str(e)

Expand Down
6 changes: 4 additions & 2 deletions nbrmd/chunk_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def to_chunk_options(language, metadata):
co_name, 'TRUE' if co_value else 'FALSE')
elif isinstance(co_value, list):
options += ' {}={},'.format(
co_name, 'list({})'.format(
co_name, 'c({})'.format(
', '.join(['"{}"'.format(str(v)) for v in co_value])))
else:
options += ' {}={},'.format(co_name, str(co_value))
Expand Down Expand Up @@ -197,7 +197,9 @@ def to_metadata(options):
continue
if value.startswith('"') or value.startswith("'"):
continue
if value.startswith('list(') and value.endswith(')'):
if value.startswith('c(') and value.endswith(')'):
value = '[' + value[2:-1] + ']'
elif value.startswith('list(') and value.endswith(')'):
value = '[' + value[5:-1] + ']'
try:
metadata[m] = ast.literal_eval(value)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[aliases]
test=pytest
test=pytest
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='nbrmd',
version='0.2.2',
version='0.2.3',
author='Marc Wouts',
author_email='marc.wouts@gmail.com',
description='Jupyter from/to R markdown notebooks',
Expand All @@ -12,7 +12,8 @@
url='https://github.com/mwouts/nbrmd',
packages=find_packages(),
entry_points={'console_scripts': ['nbrmd = nbrmd.cli:main'],
'nbconvert.exporters': ['rmarkdown = nbrmd:RMarkdownExporter']},
'nbconvert.exporters':
['rmarkdown = nbrmd:RMarkdownExporter']},
tests_require=['pytest'],
license='MIT',
classifiers=('Development Status :: 3 - Alpha',
Expand Down
Empty file added tests/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion tests/test_chunk_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
('R', {'name': 'plot_1', 'hide_input': False})),
('python echo=if a==5 then TRUE else FALSE',
('python', {'echo': 'if a==5 then TRUE else FALSE'})),
('python noname, tags=list("a", "b", "c"), echo={sum(a+c(1,2))>1}',
('python noname, tags=c("a", "b", "c"), echo={sum(a+c(1,2))>1}',
('python', {'name': 'noname', 'tags': ['a', 'b', 'c'],
'echo': '{sum(a+c(1,2))>1}'}))
]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from shutil import copyfile
import nbrmd
from nbrmd.cli import convert, cli
from utils import list_all_notebooks, remove_outputs
from .utils import list_all_notebooks, remove_outputs


@pytest.mark.parametrize('nb_file',
Expand Down
3 changes: 2 additions & 1 deletion tests/test_contentsmanager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from nbrmd import RmdFileContentsManager, readf
from utils import list_all_notebooks, remove_outputs, remove_outputs_and_header
from .utils import list_all_notebooks, remove_outputs,\
remove_outputs_and_header
import os
import sys
import pytest
Expand Down
3 changes: 2 additions & 1 deletion tests/test_ipynb_to_rmd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import nbformat
import nbrmd
import pytest
from utils import list_all_notebooks, remove_outputs, remove_outputs_and_header
from .utils import list_all_notebooks, remove_outputs, \
remove_outputs_and_header


@pytest.mark.parametrize('nb_file', list_all_notebooks('.ipynb'))
Expand Down
3 changes: 2 additions & 1 deletion tests/test_jupyter_hook.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
import os
import nbrmd
from utils import list_all_notebooks, remove_outputs, remove_outputs_and_header
from .utils import list_all_notebooks, remove_outputs, \
remove_outputs_and_header


@pytest.mark.parametrize('nb_file', list_all_notebooks('.ipynb'))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_nbconvert.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nbrmd
import pytest
from utils import list_all_notebooks
from .utils import list_all_notebooks
import subprocess
import os

Expand Down
2 changes: 1 addition & 1 deletion tests/test_rmd_to_ipynb.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nbrmd
import pytest
import sys
from utils import list_all_notebooks
from .utils import list_all_notebooks


@pytest.mark.skipif(sys.version_info < (3, 6),
Expand Down
5 changes: 5 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def remove_outputs(nb):
cell.execution_count = None
if 'trusted' in cell['metadata']:
del cell['metadata']['trusted']

for k in ['nbformat', 'nbformat_minor']:
if k in nb:
del nb[k]

return nb


Expand Down

0 comments on commit 80f0a39

Please sign in to comment.