Skip to content

Commit

Permalink
freeze_metadata sets a filter only if none exists #124
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Nov 12, 2018
1 parent 529a32d commit d70beac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions jupytext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ def cli_jupytext(args=None):
help='Preserve outputs of .ipynb destination '
'(when file exists and inputs match)')
parser.add_argument('--freeze-metadata', action='store_true',
help='Filter notebook and cell metadata that are not in the text notebook. '
'Use this to avoid creating a YAML header when editing text files.')
help='Set a metadata filter (unless one exists already) '
'equal to the current metadata of the notebook. Use this '
'to avoid creating a YAML header when editing text files.')
test = parser.add_mutually_exclusive_group()
test.add_argument('--test', dest='test', action='store_true',
help='Test that notebook is stable under '
Expand Down
2 changes: 1 addition & 1 deletion jupytext/jupytext.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def reads(self, s, **_):
raise Exception('Blocked at lines ' + '\n'.join(lines[:6]))
lines = lines[pos:]

if self.freeze_metadata:
if self.freeze_metadata and 'metadata_filter' not in metadata.get('jupytext', {}):
metadata.setdefault('jupytext', {})['metadata_filter'] = {
'notebook': {'additional': list(metadata.keys()), 'excluded': 'all'},
'cells': {'additional': list(cell_metadata), 'excluded': 'all'}}
Expand Down

0 comments on commit d70beac

Please sign in to comment.