repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
mwouts/jupytext
jupytext/jupytext.py
TextNotebookConverter.reads
def reads(self, s, **_): """Read a notebook represented as text""" if self.fmt.get('format_name') == 'pandoc': return md_to_notebook(s) lines = s.splitlines() cells = [] metadata, jupyter_md, header_cell, pos = header_to_metadata_and_cell(lines, ...
python
def reads(self, s, **_): """Read a notebook represented as text""" if self.fmt.get('format_name') == 'pandoc': return md_to_notebook(s) lines = s.splitlines() cells = [] metadata, jupyter_md, header_cell, pos = header_to_metadata_and_cell(lines, ...
[ "def", "reads", "(", "self", ",", "s", ",", "*", "*", "_", ")", ":", "if", "self", ".", "fmt", ".", "get", "(", "'format_name'", ")", "==", "'pandoc'", ":", "return", "md_to_notebook", "(", "s", ")", "lines", "=", "s", ".", "splitlines", "(", ")"...
Read a notebook represented as text
[ "Read", "a", "notebook", "represented", "as", "text" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/jupytext.py#L45-L90
train
mwouts/jupytext
jupytext/jupytext.py
TextNotebookConverter.writes
def writes(self, nb, metadata=None, **kwargs): """Return the text representation of the notebook""" if self.fmt.get('format_name') == 'pandoc': metadata = insert_jupytext_info_and_filter_metadata(metadata, self.ext, self.implementation) cells = [] for cell in nb.cell...
python
def writes(self, nb, metadata=None, **kwargs): """Return the text representation of the notebook""" if self.fmt.get('format_name') == 'pandoc': metadata = insert_jupytext_info_and_filter_metadata(metadata, self.ext, self.implementation) cells = [] for cell in nb.cell...
[ "def", "writes", "(", "self", ",", "nb", ",", "metadata", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "fmt", ".", "get", "(", "'format_name'", ")", "==", "'pandoc'", ":", "metadata", "=", "insert_jupytext_info_and_filter_metadata", ...
Return the text representation of the notebook
[ "Return", "the", "text", "representation", "of", "the", "notebook" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/jupytext.py#L92-L178
train
mwouts/jupytext
jupytext/header.py
uncomment_line
def uncomment_line(line, prefix): """Remove prefix (and space) from line""" if not prefix: return line if line.startswith(prefix + ' '): return line[len(prefix) + 1:] if line.startswith(prefix): return line[len(prefix):] return line
python
def uncomment_line(line, prefix): """Remove prefix (and space) from line""" if not prefix: return line if line.startswith(prefix + ' '): return line[len(prefix) + 1:] if line.startswith(prefix): return line[len(prefix):] return line
[ "def", "uncomment_line", "(", "line", ",", "prefix", ")", ":", "if", "not", "prefix", ":", "return", "line", "if", "line", ".", "startswith", "(", "prefix", "+", "' '", ")", ":", "return", "line", "[", "len", "(", "prefix", ")", "+", "1", ":", "]",...
Remove prefix (and space) from line
[ "Remove", "prefix", "(", "and", "space", ")", "from", "line" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/header.py#L40-L48
train
mwouts/jupytext
jupytext/header.py
encoding_and_executable
def encoding_and_executable(notebook, metadata, ext): """Return encoding and executable lines for a notebook, if applicable""" lines = [] comment = _SCRIPT_EXTENSIONS.get(ext, {}).get('comment') jupytext_metadata = metadata.get('jupytext', {}) if ext not in ['.Rmd', '.md'] and 'executable' in jupyt...
python
def encoding_and_executable(notebook, metadata, ext): """Return encoding and executable lines for a notebook, if applicable""" lines = [] comment = _SCRIPT_EXTENSIONS.get(ext, {}).get('comment') jupytext_metadata = metadata.get('jupytext', {}) if ext not in ['.Rmd', '.md'] and 'executable' in jupyt...
[ "def", "encoding_and_executable", "(", "notebook", ",", "metadata", ",", "ext", ")", ":", "lines", "=", "[", "]", "comment", "=", "_SCRIPT_EXTENSIONS", ".", "get", "(", "ext", ",", "{", "}", ")", ".", "get", "(", "'comment'", ")", "jupytext_metadata", "=...
Return encoding and executable lines for a notebook, if applicable
[ "Return", "encoding", "and", "executable", "lines", "for", "a", "notebook", "if", "applicable" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/header.py#L51-L70
train
mwouts/jupytext
jupytext/header.py
insert_jupytext_info_and_filter_metadata
def insert_jupytext_info_and_filter_metadata(metadata, ext, text_format): """Update the notebook metadata to include Jupytext information, and filter the notebook metadata according to the default or user filter""" if insert_or_test_version_number(): metadata.setdefault('jupytext', {})['text_represe...
python
def insert_jupytext_info_and_filter_metadata(metadata, ext, text_format): """Update the notebook metadata to include Jupytext information, and filter the notebook metadata according to the default or user filter""" if insert_or_test_version_number(): metadata.setdefault('jupytext', {})['text_represe...
[ "def", "insert_jupytext_info_and_filter_metadata", "(", "metadata", ",", "ext", ",", "text_format", ")", ":", "if", "insert_or_test_version_number", "(", ")", ":", "metadata", ".", "setdefault", "(", "'jupytext'", ",", "{", "}", ")", "[", "'text_representation'", ...
Update the notebook metadata to include Jupytext information, and filter the notebook metadata according to the default or user filter
[ "Update", "the", "notebook", "metadata", "to", "include", "Jupytext", "information", "and", "filter", "the", "notebook", "metadata", "according", "to", "the", "default", "or", "user", "filter" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/header.py#L73-L87
train
mwouts/jupytext
jupytext/header.py
metadata_and_cell_to_header
def metadata_and_cell_to_header(notebook, metadata, text_format, ext): """ Return the text header corresponding to a notebook, and remove the first cell of the notebook if it contained the header """ header = [] lines_to_next_cell = None if notebook.cells: cell = notebook.cells[0] ...
python
def metadata_and_cell_to_header(notebook, metadata, text_format, ext): """ Return the text header corresponding to a notebook, and remove the first cell of the notebook if it contained the header """ header = [] lines_to_next_cell = None if notebook.cells: cell = notebook.cells[0] ...
[ "def", "metadata_and_cell_to_header", "(", "notebook", ",", "metadata", ",", "text_format", ",", "ext", ")", ":", "header", "=", "[", "]", "lines_to_next_cell", "=", "None", "if", "notebook", ".", "cells", ":", "cell", "=", "notebook", ".", "cells", "[", "...
Return the text header corresponding to a notebook, and remove the first cell of the notebook if it contained the header
[ "Return", "the", "text", "header", "corresponding", "to", "a", "notebook", "and", "remove", "the", "first", "cell", "of", "the", "notebook", "if", "it", "contained", "the", "header" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/header.py#L90-L118
train
mwouts/jupytext
jupytext/header.py
header_to_metadata_and_cell
def header_to_metadata_and_cell(lines, header_prefix, ext=None): """ Return the metadata, a boolean to indicate if a jupyter section was found, the first cell of notebook if some metadata is found outside of the jupyter section, and next loc in text """ header = [] jupyter = [] injupyter =...
python
def header_to_metadata_and_cell(lines, header_prefix, ext=None): """ Return the metadata, a boolean to indicate if a jupyter section was found, the first cell of notebook if some metadata is found outside of the jupyter section, and next loc in text """ header = [] jupyter = [] injupyter =...
[ "def", "header_to_metadata_and_cell", "(", "lines", ",", "header_prefix", ",", "ext", "=", "None", ")", ":", "header", "=", "[", "]", "jupyter", "=", "[", "]", "injupyter", "=", "False", "ended", "=", "False", "metadata", "=", "{", "}", "start", "=", "...
Return the metadata, a boolean to indicate if a jupyter section was found, the first cell of notebook if some metadata is found outside of the jupyter section, and next loc in text
[ "Return", "the", "metadata", "a", "boolean", "to", "indicate", "if", "a", "jupyter", "section", "was", "found", "the", "first", "cell", "of", "notebook", "if", "some", "metadata", "is", "found", "outside", "of", "the", "jupyter", "section", "and", "next", ...
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/header.py#L121-L201
train
mwouts/jupytext
jupytext/cli.py
system
def system(*args, **kwargs): """Execute the given bash command""" kwargs.setdefault('stdout', subprocess.PIPE) proc = subprocess.Popen(args, **kwargs) out, _ = proc.communicate() if proc.returncode: raise SystemExit(proc.returncode) return out.decode('utf-8')
python
def system(*args, **kwargs): """Execute the given bash command""" kwargs.setdefault('stdout', subprocess.PIPE) proc = subprocess.Popen(args, **kwargs) out, _ = proc.communicate() if proc.returncode: raise SystemExit(proc.returncode) return out.decode('utf-8')
[ "def", "system", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "kwargs", ".", "setdefault", "(", "'stdout'", ",", "subprocess", ".", "PIPE", ")", "proc", "=", "subprocess", ".", "Popen", "(", "args", ",", "*", "*", "kwargs", ")", "out", ",",...
Execute the given bash command
[ "Execute", "the", "given", "bash", "command" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cli.py#L20-L27
train
mwouts/jupytext
jupytext/cli.py
str2bool
def str2bool(value): """Parse Yes/No/Default string https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse""" if value.lower() in ('yes', 'true', 't', 'y', '1'): return True if value.lower() in ('no', 'false', 'f', 'n', '0'): return False if value.lower() i...
python
def str2bool(value): """Parse Yes/No/Default string https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse""" if value.lower() in ('yes', 'true', 't', 'y', '1'): return True if value.lower() in ('no', 'false', 'f', 'n', '0'): return False if value.lower() i...
[ "def", "str2bool", "(", "value", ")", ":", "if", "value", ".", "lower", "(", ")", "in", "(", "'yes'", ",", "'true'", ",", "'t'", ",", "'y'", ",", "'1'", ")", ":", "return", "True", "if", "value", ".", "lower", "(", ")", "in", "(", "'no'", ",", ...
Parse Yes/No/Default string https://stackoverflow.com/questions/15008758/parsing-boolean-values-with-argparse
[ "Parse", "Yes", "/", "No", "/", "Default", "string", "https", ":", "//", "stackoverflow", ".", "com", "/", "questions", "/", "15008758", "/", "parsing", "-", "boolean", "-", "values", "-", "with", "-", "argparse" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cli.py#L30-L39
train
mwouts/jupytext
jupytext/cli.py
parse_jupytext_args
def parse_jupytext_args(args=None): """Command line parser for jupytext""" parser = argparse.ArgumentParser( description='Jupyter notebooks as markdown documents, Julia, Python or R scripts', formatter_class=argparse.RawTextHelpFormatter) # Input parser.add_argument('notebooks', ...
python
def parse_jupytext_args(args=None): """Command line parser for jupytext""" parser = argparse.ArgumentParser( description='Jupyter notebooks as markdown documents, Julia, Python or R scripts', formatter_class=argparse.RawTextHelpFormatter) # Input parser.add_argument('notebooks', ...
[ "def", "parse_jupytext_args", "(", "args", "=", "None", ")", ":", "parser", "=", "argparse", ".", "ArgumentParser", "(", "description", "=", "'Jupyter notebooks as markdown documents, Julia, Python or R scripts'", ",", "formatter_class", "=", "argparse", ".", "RawTextHelp...
Command line parser for jupytext
[ "Command", "line", "parser", "for", "jupytext" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cli.py#L42-L135
train
mwouts/jupytext
jupytext/cli.py
jupytext_cli
def jupytext_cli(args=None): """Entry point for the jupytext script""" try: jupytext(args) except (ValueError, TypeError, IOError) as err: sys.stderr.write('[jupytext] Error: ' + str(err) + '\n') exit(1)
python
def jupytext_cli(args=None): """Entry point for the jupytext script""" try: jupytext(args) except (ValueError, TypeError, IOError) as err: sys.stderr.write('[jupytext] Error: ' + str(err) + '\n') exit(1)
[ "def", "jupytext_cli", "(", "args", "=", "None", ")", ":", "try", ":", "jupytext", "(", "args", ")", "except", "(", "ValueError", ",", "TypeError", ",", "IOError", ")", "as", "err", ":", "sys", ".", "stderr", ".", "write", "(", "'[jupytext] Error: '", ...
Entry point for the jupytext script
[ "Entry", "point", "for", "the", "jupytext", "script" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cli.py#L138-L144
train
mwouts/jupytext
jupytext/cli.py
jupytext
def jupytext(args=None): """Internal implementation of Jupytext command line""" args = parse_jupytext_args(args) def log(text): if not args.quiet: sys.stdout.write(text + '\n') if args.version: log(__version__) return 0 if args.pre_commit: if args.noteb...
python
def jupytext(args=None): """Internal implementation of Jupytext command line""" args = parse_jupytext_args(args) def log(text): if not args.quiet: sys.stdout.write(text + '\n') if args.version: log(__version__) return 0 if args.pre_commit: if args.noteb...
[ "def", "jupytext", "(", "args", "=", "None", ")", ":", "args", "=", "parse_jupytext_args", "(", "args", ")", "def", "log", "(", "text", ")", ":", "if", "not", "args", ".", "quiet", ":", "sys", ".", "stdout", ".", "write", "(", "text", "+", "'\\n'",...
Internal implementation of Jupytext command line
[ "Internal", "implementation", "of", "Jupytext", "command", "line" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cli.py#L147-L332
train
mwouts/jupytext
jupytext/cli.py
notebooks_in_git_index
def notebooks_in_git_index(fmt): """Return the list of modified and deleted ipynb files in the git index that match the given format""" git_status = system('git', 'status', '--porcelain') re_modified = re.compile(r'^[AM]+\s+(?P<name>.*)', re.MULTILINE) modified_files_in_git_index = re_modified.findall(g...
python
def notebooks_in_git_index(fmt): """Return the list of modified and deleted ipynb files in the git index that match the given format""" git_status = system('git', 'status', '--porcelain') re_modified = re.compile(r'^[AM]+\s+(?P<name>.*)', re.MULTILINE) modified_files_in_git_index = re_modified.findall(g...
[ "def", "notebooks_in_git_index", "(", "fmt", ")", ":", "git_status", "=", "system", "(", "'git'", ",", "'status'", ",", "'--porcelain'", ")", "re_modified", "=", "re", ".", "compile", "(", "r'^[AM]+\\s+(?P<name>.*)'", ",", "re", ".", "MULTILINE", ")", "modifie...
Return the list of modified and deleted ipynb files in the git index that match the given format
[ "Return", "the", "list", "of", "modified", "and", "deleted", "ipynb", "files", "in", "the", "git", "index", "that", "match", "the", "given", "format" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cli.py#L335-L349
train
mwouts/jupytext
jupytext/cli.py
print_paired_paths
def print_paired_paths(nb_file, fmt): """Display the paired paths for this notebook""" notebook = readf(nb_file, fmt) formats = notebook.metadata.get('jupytext', {}).get('formats') if formats: for path, _ in paired_paths(nb_file, fmt, formats): if path != nb_file: sys...
python
def print_paired_paths(nb_file, fmt): """Display the paired paths for this notebook""" notebook = readf(nb_file, fmt) formats = notebook.metadata.get('jupytext', {}).get('formats') if formats: for path, _ in paired_paths(nb_file, fmt, formats): if path != nb_file: sys...
[ "def", "print_paired_paths", "(", "nb_file", ",", "fmt", ")", ":", "notebook", "=", "readf", "(", "nb_file", ",", "fmt", ")", "formats", "=", "notebook", ".", "metadata", ".", "get", "(", "'jupytext'", ",", "{", "}", ")", ".", "get", "(", "'formats'", ...
Display the paired paths for this notebook
[ "Display", "the", "paired", "paths", "for", "this", "notebook" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cli.py#L352-L359
train
mwouts/jupytext
jupytext/cli.py
recursive_update
def recursive_update(target, update): """ Update recursively a (nested) dictionary with the content of another. Inspired from https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth """ for key in update: value = update[key] if value is None: ...
python
def recursive_update(target, update): """ Update recursively a (nested) dictionary with the content of another. Inspired from https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth """ for key in update: value = update[key] if value is None: ...
[ "def", "recursive_update", "(", "target", ",", "update", ")", ":", "for", "key", "in", "update", ":", "value", "=", "update", "[", "key", "]", "if", "value", "is", "None", ":", "del", "target", "[", "key", "]", "elif", "isinstance", "(", "value", ","...
Update recursively a (nested) dictionary with the content of another. Inspired from https://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth
[ "Update", "recursively", "a", "(", "nested", ")", "dictionary", "with", "the", "content", "of", "another", ".", "Inspired", "from", "https", ":", "//", "stackoverflow", ".", "com", "/", "questions", "/", "3232943", "/", "update", "-", "value", "-", "of", ...
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cli.py#L362-L374
train
mwouts/jupytext
jupytext/cli.py
set_format_options
def set_format_options(fmt, format_options): """Apply the desired format options to the format description fmt""" if not format_options: return for opt in format_options: try: key, value = opt.split('=') except ValueError: raise ValueError("Format options are...
python
def set_format_options(fmt, format_options): """Apply the desired format options to the format description fmt""" if not format_options: return for opt in format_options: try: key, value = opt.split('=') except ValueError: raise ValueError("Format options are...
[ "def", "set_format_options", "(", "fmt", ",", "format_options", ")", ":", "if", "not", "format_options", ":", "return", "for", "opt", "in", "format_options", ":", "try", ":", "key", ",", "value", "=", "opt", ".", "split", "(", "'='", ")", "except", "Valu...
Apply the desired format options to the format description fmt
[ "Apply", "the", "desired", "format", "options", "to", "the", "format", "description", "fmt" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cli.py#L377-L395
train
mwouts/jupytext
jupytext/cli.py
set_prefix_and_suffix
def set_prefix_and_suffix(fmt, notebook, nb_file): """Add prefix and suffix information from jupytext.formats if format and path matches""" for alt_fmt in long_form_multiple_formats(notebook.metadata.get('jupytext', {}).get('formats')): if (alt_fmt['extension'] == fmt['extension'] and fm...
python
def set_prefix_and_suffix(fmt, notebook, nb_file): """Add prefix and suffix information from jupytext.formats if format and path matches""" for alt_fmt in long_form_multiple_formats(notebook.metadata.get('jupytext', {}).get('formats')): if (alt_fmt['extension'] == fmt['extension'] and fm...
[ "def", "set_prefix_and_suffix", "(", "fmt", ",", "notebook", ",", "nb_file", ")", ":", "for", "alt_fmt", "in", "long_form_multiple_formats", "(", "notebook", ".", "metadata", ".", "get", "(", "'jupytext'", ",", "{", "}", ")", ".", "get", "(", "'formats'", ...
Add prefix and suffix information from jupytext.formats if format and path matches
[ "Add", "prefix", "and", "suffix", "information", "from", "jupytext", ".", "formats", "if", "format", "and", "path", "matches" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cli.py#L398-L408
train
mwouts/jupytext
jupytext/cli.py
load_paired_notebook
def load_paired_notebook(notebook, fmt, nb_file, log): """Update the notebook with the inputs and outputs of the most recent paired files""" formats = notebook.metadata.get('jupytext', {}).get('formats') if not formats: raise ValueError("'{}' is not a paired notebook".format(nb_file)) max_mtim...
python
def load_paired_notebook(notebook, fmt, nb_file, log): """Update the notebook with the inputs and outputs of the most recent paired files""" formats = notebook.metadata.get('jupytext', {}).get('formats') if not formats: raise ValueError("'{}' is not a paired notebook".format(nb_file)) max_mtim...
[ "def", "load_paired_notebook", "(", "notebook", ",", "fmt", ",", "nb_file", ",", "log", ")", ":", "formats", "=", "notebook", ".", "metadata", ".", "get", "(", "'jupytext'", ",", "{", "}", ")", ".", "get", "(", "'formats'", ")", "if", "not", "formats",...
Update the notebook with the inputs and outputs of the most recent paired files
[ "Update", "the", "notebook", "with", "the", "inputs", "and", "outputs", "of", "the", "most", "recent", "paired", "files" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cli.py#L411-L447
train
mwouts/jupytext
jupytext/cli.py
pipe_notebook
def pipe_notebook(notebook, command, fmt='py:percent', update=True, preserve_outputs=True): """Pipe the notebook, in the desired representation, to the given command. Update the notebook with the returned content if desired.""" if command in ['black', 'flake8', 'autopep8']: command = command + ' -' ...
python
def pipe_notebook(notebook, command, fmt='py:percent', update=True, preserve_outputs=True): """Pipe the notebook, in the desired representation, to the given command. Update the notebook with the returned content if desired.""" if command in ['black', 'flake8', 'autopep8']: command = command + ' -' ...
[ "def", "pipe_notebook", "(", "notebook", ",", "command", ",", "fmt", "=", "'py:percent'", ",", "update", "=", "True", ",", "preserve_outputs", "=", "True", ")", ":", "if", "command", "in", "[", "'black'", ",", "'flake8'", ",", "'autopep8'", "]", ":", "co...
Pipe the notebook, in the desired representation, to the given command. Update the notebook with the returned content if desired.
[ "Pipe", "the", "notebook", "in", "the", "desired", "representation", "to", "the", "given", "command", ".", "Update", "the", "notebook", "with", "the", "returned", "content", "if", "desired", "." ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cli.py#L450-L483
train
mwouts/jupytext
jupytext/cell_reader.py
uncomment
def uncomment(lines, prefix='#'): """Remove prefix and space, or only prefix, when possible""" if not prefix: return lines prefix_and_space = prefix + ' ' length_prefix = len(prefix) length_prefix_and_space = len(prefix_and_space) return [line[length_prefix_and_space:] if line.startswith...
python
def uncomment(lines, prefix='#'): """Remove prefix and space, or only prefix, when possible""" if not prefix: return lines prefix_and_space = prefix + ' ' length_prefix = len(prefix) length_prefix_and_space = len(prefix_and_space) return [line[length_prefix_and_space:] if line.startswith...
[ "def", "uncomment", "(", "lines", ",", "prefix", "=", "'#'", ")", ":", "if", "not", "prefix", ":", "return", "lines", "prefix_and_space", "=", "prefix", "+", "' '", "length_prefix", "=", "len", "(", "prefix", ")", "length_prefix_and_space", "=", "len", "("...
Remove prefix and space, or only prefix, when possible
[ "Remove", "prefix", "and", "space", "or", "only", "prefix", "when", "possible" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L24-L33
train
mwouts/jupytext
jupytext/cell_reader.py
paragraph_is_fully_commented
def paragraph_is_fully_commented(lines, comment, main_language): """Is the paragraph fully commented?""" for i, line in enumerate(lines): if line.startswith(comment): if line.startswith((comment + ' %', comment + ' ?', comment + ' !')) and is_magic(line, main_language): retur...
python
def paragraph_is_fully_commented(lines, comment, main_language): """Is the paragraph fully commented?""" for i, line in enumerate(lines): if line.startswith(comment): if line.startswith((comment + ' %', comment + ' ?', comment + ' !')) and is_magic(line, main_language): retur...
[ "def", "paragraph_is_fully_commented", "(", "lines", ",", "comment", ",", "main_language", ")", ":", "for", "i", ",", "line", "in", "enumerate", "(", "lines", ")", ":", "if", "line", ".", "startswith", "(", "comment", ")", ":", "if", "line", ".", "starts...
Is the paragraph fully commented?
[ "Is", "the", "paragraph", "fully", "commented?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L36-L44
train
mwouts/jupytext
jupytext/cell_reader.py
next_code_is_indented
def next_code_is_indented(lines): """Is the next unescaped line indented?""" for line in lines: if _BLANK_LINE.match(line) or _PY_COMMENT.match(line): continue return _PY_INDENTED.match(line) return False
python
def next_code_is_indented(lines): """Is the next unescaped line indented?""" for line in lines: if _BLANK_LINE.match(line) or _PY_COMMENT.match(line): continue return _PY_INDENTED.match(line) return False
[ "def", "next_code_is_indented", "(", "lines", ")", ":", "for", "line", "in", "lines", ":", "if", "_BLANK_LINE", ".", "match", "(", "line", ")", "or", "_PY_COMMENT", ".", "match", "(", "line", ")", ":", "continue", "return", "_PY_INDENTED", ".", "match", ...
Is the next unescaped line indented?
[ "Is", "the", "next", "unescaped", "line", "indented?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L47-L53
train
mwouts/jupytext
jupytext/cell_reader.py
count_lines_to_next_cell
def count_lines_to_next_cell(cell_end_marker, next_cell_start, total, explicit_eoc): """How many blank lines between end of cell marker and next cell?""" if cell_end_marker < total: lines_to_next_cell = next_cell_start - cell_end_marker if explicit_eoc: lines_to_next_cell -= 1 ...
python
def count_lines_to_next_cell(cell_end_marker, next_cell_start, total, explicit_eoc): """How many blank lines between end of cell marker and next cell?""" if cell_end_marker < total: lines_to_next_cell = next_cell_start - cell_end_marker if explicit_eoc: lines_to_next_cell -= 1 ...
[ "def", "count_lines_to_next_cell", "(", "cell_end_marker", ",", "next_cell_start", ",", "total", ",", "explicit_eoc", ")", ":", "if", "cell_end_marker", "<", "total", ":", "lines_to_next_cell", "=", "next_cell_start", "-", "cell_end_marker", "if", "explicit_eoc", ":",...
How many blank lines between end of cell marker and next cell?
[ "How", "many", "blank", "lines", "between", "end", "of", "cell", "marker", "and", "next", "cell?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L56-L66
train
mwouts/jupytext
jupytext/cell_reader.py
last_two_lines_blank
def last_two_lines_blank(source): """Are the two last lines blank, and not the third last one?""" if len(source) < 3: return False return not _BLANK_LINE.match(source[-3]) and _BLANK_LINE.match(source[-2]) and _BLANK_LINE.match(source[-1])
python
def last_two_lines_blank(source): """Are the two last lines blank, and not the third last one?""" if len(source) < 3: return False return not _BLANK_LINE.match(source[-3]) and _BLANK_LINE.match(source[-2]) and _BLANK_LINE.match(source[-1])
[ "def", "last_two_lines_blank", "(", "source", ")", ":", "if", "len", "(", "source", ")", "<", "3", ":", "return", "False", "return", "not", "_BLANK_LINE", ".", "match", "(", "source", "[", "-", "3", "]", ")", "and", "_BLANK_LINE", ".", "match", "(", ...
Are the two last lines blank, and not the third last one?
[ "Are", "the", "two", "last", "lines", "blank", "and", "not", "the", "third", "last", "one?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L69-L73
train
mwouts/jupytext
jupytext/cell_reader.py
BaseCellReader.read
def read(self, lines): """Read one cell from the given lines, and return the cell, plus the position of the next cell """ # Do we have an explicit code marker on the first line? self.metadata_and_language_from_option_line(lines[0]) if self.metadata and 'language' in sel...
python
def read(self, lines): """Read one cell from the given lines, and return the cell, plus the position of the next cell """ # Do we have an explicit code marker on the first line? self.metadata_and_language_from_option_line(lines[0]) if self.metadata and 'language' in sel...
[ "def", "read", "(", "self", ",", "lines", ")", ":", "# Do we have an explicit code marker on the first line?", "self", ".", "metadata_and_language_from_option_line", "(", "lines", "[", "0", "]", ")", "if", "self", ".", "metadata", "and", "'language'", "in", "self", ...
Read one cell from the given lines, and return the cell, plus the position of the next cell
[ "Read", "one", "cell", "from", "the", "given", "lines", "and", "return", "the", "cell", "plus", "the", "position", "of", "the", "next", "cell" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L105-L140
train
mwouts/jupytext
jupytext/cell_reader.py
BaseCellReader.metadata_and_language_from_option_line
def metadata_and_language_from_option_line(self, line): """Parse code options on the given line. When a start of a code cell is found, self.metadata is set to a dictionary.""" if self.start_code_re.match(line): self.language, self.metadata = self.options_to_metadata(self.start_code_r...
python
def metadata_and_language_from_option_line(self, line): """Parse code options on the given line. When a start of a code cell is found, self.metadata is set to a dictionary.""" if self.start_code_re.match(line): self.language, self.metadata = self.options_to_metadata(self.start_code_r...
[ "def", "metadata_and_language_from_option_line", "(", "self", ",", "line", ")", ":", "if", "self", ".", "start_code_re", ".", "match", "(", "line", ")", ":", "self", ".", "language", ",", "self", ".", "metadata", "=", "self", ".", "options_to_metadata", "(",...
Parse code options on the given line. When a start of a code cell is found, self.metadata is set to a dictionary.
[ "Parse", "code", "options", "on", "the", "given", "line", ".", "When", "a", "start", "of", "a", "code", "cell", "is", "found", "self", ".", "metadata", "is", "set", "to", "a", "dictionary", "." ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L142-L146
train
mwouts/jupytext
jupytext/cell_reader.py
BaseCellReader.find_cell_content
def find_cell_content(self, lines): """Parse cell till its end and set content, lines_to_next_cell. Return the position of next cell start""" cell_end_marker, next_cell_start, self.explicit_eoc = self.find_cell_end(lines) # Metadata to dict if self.metadata is None: ...
python
def find_cell_content(self, lines): """Parse cell till its end and set content, lines_to_next_cell. Return the position of next cell start""" cell_end_marker, next_cell_start, self.explicit_eoc = self.find_cell_end(lines) # Metadata to dict if self.metadata is None: ...
[ "def", "find_cell_content", "(", "self", ",", "lines", ")", ":", "cell_end_marker", ",", "next_cell_start", ",", "self", ".", "explicit_eoc", "=", "self", ".", "find_cell_end", "(", "lines", ")", "# Metadata to dict", "if", "self", ".", "metadata", "is", "None...
Parse cell till its end and set content, lines_to_next_cell. Return the position of next cell start
[ "Parse", "cell", "till", "its", "end", "and", "set", "content", "lines_to_next_cell", ".", "Return", "the", "position", "of", "next", "cell", "start" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L157-L215
train
mwouts/jupytext
jupytext/cell_reader.py
MarkdownCellReader.find_cell_end
def find_cell_end(self, lines): """Return position of end of cell marker, and position of first line after cell""" if self.in_region: self.cell_type = 'markdown' for i, line in enumerate(lines): if self.end_region_re.match(line): return...
python
def find_cell_end(self, lines): """Return position of end of cell marker, and position of first line after cell""" if self.in_region: self.cell_type = 'markdown' for i, line in enumerate(lines): if self.end_region_re.match(line): return...
[ "def", "find_cell_end", "(", "self", ",", "lines", ")", ":", "if", "self", ".", "in_region", ":", "self", ".", "cell_type", "=", "'markdown'", "for", "i", ",", "line", "in", "enumerate", "(", "lines", ")", ":", "if", "self", ".", "end_region_re", ".", ...
Return position of end of cell marker, and position of first line after cell
[ "Return", "position", "of", "end", "of", "cell", "marker", "and", "position", "of", "first", "line", "after", "cell" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L261-L321
train
mwouts/jupytext
jupytext/cell_reader.py
RScriptCellReader.find_cell_end
def find_cell_end(self, lines): """Return position of end of cell marker, and position of first line after cell""" if self.metadata is None and lines[0].startswith("#'"): self.cell_type = 'markdown' for i, line in enumerate(lines): if not line.startswith("...
python
def find_cell_end(self, lines): """Return position of end of cell marker, and position of first line after cell""" if self.metadata is None and lines[0].startswith("#'"): self.cell_type = 'markdown' for i, line in enumerate(lines): if not line.startswith("...
[ "def", "find_cell_end", "(", "self", ",", "lines", ")", ":", "if", "self", ".", "metadata", "is", "None", "and", "lines", "[", "0", "]", ".", "startswith", "(", "\"#'\"", ")", ":", "self", ".", "cell_type", "=", "'markdown'", "for", "i", ",", "line",...
Return position of end of cell marker, and position of first line after cell
[ "Return", "position", "of", "end", "of", "cell", "marker", "and", "position", "of", "first", "line", "after", "cell" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L381-L426
train
mwouts/jupytext
jupytext/cell_reader.py
LightScriptCellReader.find_cell_end
def find_cell_end(self, lines): """Return position of end of cell marker, and position of first line after cell""" if self.metadata is None and not (self.cell_marker_end and self.end_code_re.match(lines[0])) \ and paragraph_is_fully_commented(lines, self.comment, self.default_language): ...
python
def find_cell_end(self, lines): """Return position of end of cell marker, and position of first line after cell""" if self.metadata is None and not (self.cell_marker_end and self.end_code_re.match(lines[0])) \ and paragraph_is_fully_commented(lines, self.comment, self.default_language): ...
[ "def", "find_cell_end", "(", "self", ",", "lines", ")", ":", "if", "self", ".", "metadata", "is", "None", "and", "not", "(", "self", ".", "cell_marker_end", "and", "self", ".", "end_code_re", ".", "match", "(", "lines", "[", "0", "]", ")", ")", "and"...
Return position of end of cell marker, and position of first line after cell
[ "Return", "position", "of", "end", "of", "cell", "marker", "and", "position", "of", "first", "line", "after", "cell" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L491-L507
train
mwouts/jupytext
jupytext/cell_reader.py
LightScriptCellReader.find_region_end
def find_region_end(self, lines): """Find the end of the region started with start and end markers""" if self.metadata and 'cell_type' in self.metadata: self.cell_type = self.metadata.pop('cell_type') else: self.cell_type = 'code' parser = StringParser(self.langu...
python
def find_region_end(self, lines): """Find the end of the region started with start and end markers""" if self.metadata and 'cell_type' in self.metadata: self.cell_type = self.metadata.pop('cell_type') else: self.cell_type = 'code' parser = StringParser(self.langu...
[ "def", "find_region_end", "(", "self", ",", "lines", ")", ":", "if", "self", ".", "metadata", "and", "'cell_type'", "in", "self", ".", "metadata", ":", "self", ".", "cell_type", "=", "self", ".", "metadata", ".", "pop", "(", "'cell_type'", ")", "else", ...
Find the end of the region started with start and end markers
[ "Find", "the", "end", "of", "the", "region", "started", "with", "start", "and", "end", "markers" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L509-L557
train
mwouts/jupytext
jupytext/cell_reader.py
DoublePercentScriptCellReader.metadata_and_language_from_option_line
def metadata_and_language_from_option_line(self, line): """Parse code options on the given line. When a start of a code cell is found, self.metadata is set to a dictionary.""" if self.start_code_re.match(line): self.language, self.metadata = self.options_to_metadata(line[line.find('%...
python
def metadata_and_language_from_option_line(self, line): """Parse code options on the given line. When a start of a code cell is found, self.metadata is set to a dictionary.""" if self.start_code_re.match(line): self.language, self.metadata = self.options_to_metadata(line[line.find('%...
[ "def", "metadata_and_language_from_option_line", "(", "self", ",", "line", ")", ":", "if", "self", ".", "start_code_re", ".", "match", "(", "line", ")", ":", "self", ".", "language", ",", "self", ".", "metadata", "=", "self", ".", "options_to_metadata", "(",...
Parse code options on the given line. When a start of a code cell is found, self.metadata is set to a dictionary.
[ "Parse", "code", "options", "on", "the", "given", "line", ".", "When", "a", "start", "of", "a", "code", "cell", "is", "found", "self", ".", "metadata", "is", "set", "to", "a", "dictionary", "." ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L572-L578
train
mwouts/jupytext
jupytext/cell_reader.py
DoublePercentScriptCellReader.find_cell_content
def find_cell_content(self, lines): """Parse cell till its end and set content, lines_to_next_cell. Return the position of next cell start""" cell_end_marker, next_cell_start, explicit_eoc = self.find_cell_end(lines) # Metadata to dict if self.start_code_re.match(lines[0]) or se...
python
def find_cell_content(self, lines): """Parse cell till its end and set content, lines_to_next_cell. Return the position of next cell start""" cell_end_marker, next_cell_start, explicit_eoc = self.find_cell_end(lines) # Metadata to dict if self.start_code_re.match(lines[0]) or se...
[ "def", "find_cell_content", "(", "self", ",", "lines", ")", ":", "cell_end_marker", ",", "next_cell_start", ",", "explicit_eoc", "=", "self", ".", "find_cell_end", "(", "lines", ")", "# Metadata to dict", "if", "self", ".", "start_code_re", ".", "match", "(", ...
Parse cell till its end and set content, lines_to_next_cell. Return the position of next cell start
[ "Parse", "cell", "till", "its", "end", "and", "set", "content", "lines_to_next_cell", ".", "Return", "the", "position", "of", "next", "cell", "start" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L583-L612
train
mwouts/jupytext
jupytext/cell_reader.py
DoublePercentScriptCellReader.find_cell_end
def find_cell_end(self, lines): """Return position of end of cell marker, and position of first line after cell""" if self.metadata and 'cell_type' in self.metadata: self.cell_type = self.metadata.pop('cell_type') else: self.cell_type = 'code' next_cell ...
python
def find_cell_end(self, lines): """Return position of end of cell marker, and position of first line after cell""" if self.metadata and 'cell_type' in self.metadata: self.cell_type = self.metadata.pop('cell_type') else: self.cell_type = 'code' next_cell ...
[ "def", "find_cell_end", "(", "self", ",", "lines", ")", ":", "if", "self", ".", "metadata", "and", "'cell_type'", "in", "self", ".", "metadata", ":", "self", ".", "cell_type", "=", "self", ".", "metadata", ".", "pop", "(", "'cell_type'", ")", "else", "...
Return position of end of cell marker, and position of first line after cell
[ "Return", "position", "of", "end", "of", "cell", "marker", "and", "position", "of", "first", "line", "after", "cell" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L614-L633
train
mwouts/jupytext
jupytext/cell_reader.py
SphinxGalleryScriptCellReader.start_of_new_markdown_cell
def start_of_new_markdown_cell(self, line): """Does this line starts a new markdown cell? Then, return the cell marker""" for empty_markdown_cell in ['""', "''"]: if line == empty_markdown_cell: return empty_markdown_cell for triple_quote in ['"""', "'''"]: ...
python
def start_of_new_markdown_cell(self, line): """Does this line starts a new markdown cell? Then, return the cell marker""" for empty_markdown_cell in ['""', "''"]: if line == empty_markdown_cell: return empty_markdown_cell for triple_quote in ['"""', "'''"]: ...
[ "def", "start_of_new_markdown_cell", "(", "self", ",", "line", ")", ":", "for", "empty_markdown_cell", "in", "[", "'\"\"'", ",", "\"''\"", "]", ":", "if", "line", "==", "empty_markdown_cell", ":", "return", "empty_markdown_cell", "for", "triple_quote", "in", "["...
Does this line starts a new markdown cell? Then, return the cell marker
[ "Does", "this", "line", "starts", "a", "new", "markdown", "cell?", "Then", "return", "the", "cell", "marker" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L656-L670
train
mwouts/jupytext
jupytext/cell_reader.py
SphinxGalleryScriptCellReader.find_cell_end
def find_cell_end(self, lines): """Return position of end of cell, and position of first line after cell, and whether there was an explicit end of cell marker""" if self.cell_type == 'markdown': # Empty cell "" or '' if len(self.markdown_marker) <= 2: ...
python
def find_cell_end(self, lines): """Return position of end of cell, and position of first line after cell, and whether there was an explicit end of cell marker""" if self.cell_type == 'markdown': # Empty cell "" or '' if len(self.markdown_marker) <= 2: ...
[ "def", "find_cell_end", "(", "self", ",", "lines", ")", ":", "if", "self", ".", "cell_type", "==", "'markdown'", ":", "# Empty cell \"\" or ''", "if", "len", "(", "self", ".", "markdown_marker", ")", "<=", "2", ":", "if", "len", "(", "lines", ")", "==", ...
Return position of end of cell, and position of first line after cell, and whether there was an explicit end of cell marker
[ "Return", "position", "of", "end", "of", "cell", "and", "position", "of", "first", "line", "after", "cell", "and", "whether", "there", "was", "an", "explicit", "end", "of", "cell", "marker" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L681-L727
train
mwouts/jupytext
jupytext/cell_reader.py
SphinxGalleryScriptCellReader.find_cell_content
def find_cell_content(self, lines): """Parse cell till its end and set content, lines_to_next_cell. Return the position of next cell start""" cell_end_marker, next_cell_start, explicit_eoc = self.find_cell_end(lines) # Metadata to dict cell_start = 0 if self.cell_type ==...
python
def find_cell_content(self, lines): """Parse cell till its end and set content, lines_to_next_cell. Return the position of next cell start""" cell_end_marker, next_cell_start, explicit_eoc = self.find_cell_end(lines) # Metadata to dict cell_start = 0 if self.cell_type ==...
[ "def", "find_cell_content", "(", "self", ",", "lines", ")", ":", "cell_end_marker", ",", "next_cell_start", ",", "explicit_eoc", "=", "self", ".", "find_cell_end", "(", "lines", ")", "# Metadata to dict", "cell_start", "=", "0", "if", "self", ".", "cell_type", ...
Parse cell till its end and set content, lines_to_next_cell. Return the position of next cell start
[ "Parse", "cell", "till", "its", "end", "and", "set", "content", "lines_to_next_cell", ".", "Return", "the", "position", "of", "next", "cell", "start" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_reader.py#L729-L775
train
mwouts/jupytext
jupytext/paired_paths.py
base_path
def base_path(main_path, fmt): """Given a path and options for a format (ext, suffix, prefix), return the corresponding base path""" if not fmt: return os.path.splitext(main_path)[0] fmt = long_form_one_format(fmt) fmt_ext = fmt['extension'] suffix = fmt.get('suffix') prefix = fmt.get('...
python
def base_path(main_path, fmt): """Given a path and options for a format (ext, suffix, prefix), return the corresponding base path""" if not fmt: return os.path.splitext(main_path)[0] fmt = long_form_one_format(fmt) fmt_ext = fmt['extension'] suffix = fmt.get('suffix') prefix = fmt.get('...
[ "def", "base_path", "(", "main_path", ",", "fmt", ")", ":", "if", "not", "fmt", ":", "return", "os", ".", "path", ".", "splitext", "(", "main_path", ")", "[", "0", "]", "fmt", "=", "long_form_one_format", "(", "fmt", ")", "fmt_ext", "=", "fmt", "[", ...
Given a path and options for a format (ext, suffix, prefix), return the corresponding base path
[ "Given", "a", "path", "and", "options", "for", "a", "format", "(", "ext", "suffix", "prefix", ")", "return", "the", "corresponding", "base", "path" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/paired_paths.py#L13-L58
train
mwouts/jupytext
jupytext/paired_paths.py
full_path
def full_path(base, fmt): """Return the full path for the notebook, given the base path""" ext = fmt['extension'] suffix = fmt.get('suffix') prefix = fmt.get('prefix') full = base if prefix: prefix_dir, prefix_file_name = os.path.split(prefix) notebook_dir, notebook_file_name =...
python
def full_path(base, fmt): """Return the full path for the notebook, given the base path""" ext = fmt['extension'] suffix = fmt.get('suffix') prefix = fmt.get('prefix') full = base if prefix: prefix_dir, prefix_file_name = os.path.split(prefix) notebook_dir, notebook_file_name =...
[ "def", "full_path", "(", "base", ",", "fmt", ")", ":", "ext", "=", "fmt", "[", "'extension'", "]", "suffix", "=", "fmt", ".", "get", "(", "'suffix'", ")", "prefix", "=", "fmt", ".", "get", "(", "'prefix'", ")", "full", "=", "base", "if", "prefix", ...
Return the full path for the notebook, given the base path
[ "Return", "the", "full", "path", "for", "the", "notebook", "given", "the", "base", "path" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/paired_paths.py#L61-L94
train
mwouts/jupytext
jupytext/paired_paths.py
find_base_path_and_format
def find_base_path_and_format(main_path, formats): """Return the base path and the format corresponding to the given path""" for fmt in formats: try: return base_path(main_path, fmt), fmt except InconsistentPath: continue raise InconsistentPath(u"Path '{}' matches no...
python
def find_base_path_and_format(main_path, formats): """Return the base path and the format corresponding to the given path""" for fmt in formats: try: return base_path(main_path, fmt), fmt except InconsistentPath: continue raise InconsistentPath(u"Path '{}' matches no...
[ "def", "find_base_path_and_format", "(", "main_path", ",", "formats", ")", ":", "for", "fmt", "in", "formats", ":", "try", ":", "return", "base_path", "(", "main_path", ",", "fmt", ")", ",", "fmt", "except", "InconsistentPath", ":", "continue", "raise", "Inc...
Return the base path and the format corresponding to the given path
[ "Return", "the", "base", "path", "and", "the", "format", "corresponding", "to", "the", "given", "path" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/paired_paths.py#L97-L108
train
mwouts/jupytext
jupytext/paired_paths.py
paired_paths
def paired_paths(main_path, fmt, formats): """Return the list of paired notebooks, given main path, and the list of formats""" if not formats: return [(main_path, {'extension': os.path.splitext(main_path)[1]})] formats = long_form_multiple_formats(formats) # Is there a format that matches the ...
python
def paired_paths(main_path, fmt, formats): """Return the list of paired notebooks, given main path, and the list of formats""" if not formats: return [(main_path, {'extension': os.path.splitext(main_path)[1]})] formats = long_form_multiple_formats(formats) # Is there a format that matches the ...
[ "def", "paired_paths", "(", "main_path", ",", "fmt", ",", "formats", ")", ":", "if", "not", "formats", ":", "return", "[", "(", "main_path", ",", "{", "'extension'", ":", "os", ".", "path", ".", "splitext", "(", "main_path", ")", "[", "1", "]", "}", ...
Return the list of paired notebooks, given main path, and the list of formats
[ "Return", "the", "list", "of", "paired", "notebooks", "given", "main", "path", "and", "the", "list", "of", "formats" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/paired_paths.py#L111-L131
train
mwouts/jupytext
jupytext/cell_metadata.py
metadata_to_rmd_options
def metadata_to_rmd_options(language, metadata): """ Convert language and metadata information to their rmd representation :param language: :param metadata: :return: """ options = (language or 'R').lower() if 'name' in metadata: options += ' ' + metadata['name'] + ',' del...
python
def metadata_to_rmd_options(language, metadata): """ Convert language and metadata information to their rmd representation :param language: :param metadata: :return: """ options = (language or 'R').lower() if 'name' in metadata: options += ' ' + metadata['name'] + ',' del...
[ "def", "metadata_to_rmd_options", "(", "language", ",", "metadata", ")", ":", "options", "=", "(", "language", "or", "'R'", ")", ".", "lower", "(", ")", "if", "'name'", "in", "metadata", ":", "options", "+=", "' '", "+", "metadata", "[", "'name'", "]", ...
Convert language and metadata information to their rmd representation :param language: :param metadata: :return:
[ "Convert", "language", "and", "metadata", "information", "to", "their", "rmd", "representation", ":", "param", "language", ":", ":", "param", "metadata", ":", ":", "return", ":" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L63-L95
train
mwouts/jupytext
jupytext/cell_metadata.py
update_metadata_from_rmd_options
def update_metadata_from_rmd_options(name, value, metadata): """ Update metadata using the _BOOLEAN_OPTIONS_DICTIONARY mapping :param name: option name :param value: option value :param metadata: :return: """ for jupyter_option, rmd_option, rev in _BOOLEAN_OPTIONS_DICTIONARY: if ...
python
def update_metadata_from_rmd_options(name, value, metadata): """ Update metadata using the _BOOLEAN_OPTIONS_DICTIONARY mapping :param name: option name :param value: option value :param metadata: :return: """ for jupyter_option, rmd_option, rev in _BOOLEAN_OPTIONS_DICTIONARY: if ...
[ "def", "update_metadata_from_rmd_options", "(", "name", ",", "value", ",", "metadata", ")", ":", "for", "jupyter_option", ",", "rmd_option", ",", "rev", "in", "_BOOLEAN_OPTIONS_DICTIONARY", ":", "if", "name", "==", "rmd_option", ":", "try", ":", "metadata", "[",...
Update metadata using the _BOOLEAN_OPTIONS_DICTIONARY mapping :param name: option name :param value: option value :param metadata: :return:
[ "Update", "metadata", "using", "the", "_BOOLEAN_OPTIONS_DICTIONARY", "mapping", ":", "param", "name", ":", "option", "name", ":", "param", "value", ":", "option", "value", ":", "param", "metadata", ":", ":", "return", ":" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L98-L113
train
mwouts/jupytext
jupytext/cell_metadata.py
parse_rmd_options
def parse_rmd_options(line): """ Given a R markdown option line, returns a list of pairs name,value :param line: :return: """ parsing_context = ParsingContext(line) result = [] prev_char = '' name = '' value = '' for char in ',' + line + ',': if parsing_context.in_...
python
def parse_rmd_options(line): """ Given a R markdown option line, returns a list of pairs name,value :param line: :return: """ parsing_context = ParsingContext(line) result = [] prev_char = '' name = '' value = '' for char in ',' + line + ',': if parsing_context.in_...
[ "def", "parse_rmd_options", "(", "line", ")", ":", "parsing_context", "=", "ParsingContext", "(", "line", ")", "result", "=", "[", "]", "prev_char", "=", "''", "name", "=", "''", "value", "=", "''", "for", "char", "in", "','", "+", "line", "+", "','", ...
Given a R markdown option line, returns a list of pairs name,value :param line: :return:
[ "Given", "a", "R", "markdown", "option", "line", "returns", "a", "list", "of", "pairs", "name", "value", ":", "param", "line", ":", ":", "return", ":" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L167-L210
train
mwouts/jupytext
jupytext/cell_metadata.py
rmd_options_to_metadata
def rmd_options_to_metadata(options): """ Parse rmd options and return a metadata dictionary :param options: :return: """ options = re.split(r'\s|,', options, 1) if len(options) == 1: language = options[0] chunk_options = [] else: language, others = options ...
python
def rmd_options_to_metadata(options): """ Parse rmd options and return a metadata dictionary :param options: :return: """ options = re.split(r'\s|,', options, 1) if len(options) == 1: language = options[0] chunk_options = [] else: language, others = options ...
[ "def", "rmd_options_to_metadata", "(", "options", ")", ":", "options", "=", "re", ".", "split", "(", "r'\\s|,'", ",", "options", ",", "1", ")", "if", "len", "(", "options", ")", "==", "1", ":", "language", "=", "options", "[", "0", "]", "chunk_options"...
Parse rmd options and return a metadata dictionary :param options: :return:
[ "Parse", "rmd", "options", "and", "return", "a", "metadata", "dictionary", ":", "param", "options", ":", ":", "return", ":" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L213-L251
train
mwouts/jupytext
jupytext/cell_metadata.py
metadata_to_md_options
def metadata_to_md_options(metadata): """Encode {'class':None, 'key':'value'} into 'class key="value"' """ return ' '.join(["{}={}".format(key, dumps(metadata[key])) if metadata[key] is not None else key for key in metadata])
python
def metadata_to_md_options(metadata): """Encode {'class':None, 'key':'value'} into 'class key="value"' """ return ' '.join(["{}={}".format(key, dumps(metadata[key])) if metadata[key] is not None else key for key in metadata])
[ "def", "metadata_to_md_options", "(", "metadata", ")", ":", "return", "' '", ".", "join", "(", "[", "\"{}={}\"", ".", "format", "(", "key", ",", "dumps", "(", "metadata", "[", "key", "]", ")", ")", "if", "metadata", "[", "key", "]", "is", "not", "Non...
Encode {'class':None, 'key':'value'} into 'class key="value"'
[ "Encode", "{", "class", ":", "None", "key", ":", "value", "}", "into", "class", "key", "=", "value" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L254-L258
train
mwouts/jupytext
jupytext/cell_metadata.py
parse_md_code_options
def parse_md_code_options(options): """Parse 'python class key="value"' into [('python', None), ('class', None), ('key', 'value')]""" metadata = [] while options: name_and_value = re.split(r'[\s=]+', options, maxsplit=1) name = name_and_value[0] # Equal sign in between name and wha...
python
def parse_md_code_options(options): """Parse 'python class key="value"' into [('python', None), ('class', None), ('key', 'value')]""" metadata = [] while options: name_and_value = re.split(r'[\s=]+', options, maxsplit=1) name = name_and_value[0] # Equal sign in between name and wha...
[ "def", "parse_md_code_options", "(", "options", ")", ":", "metadata", "=", "[", "]", "while", "options", ":", "name_and_value", "=", "re", ".", "split", "(", "r'[\\s=]+'", ",", "options", ",", "maxsplit", "=", "1", ")", "name", "=", "name_and_value", "[", ...
Parse 'python class key="value"' into [('python', None), ('class', None), ('key', 'value')]
[ "Parse", "python", "class", "key", "=", "value", "into", "[", "(", "python", "None", ")", "(", "class", "None", ")", "(", "key", "value", ")", "]" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L261-L298
train
mwouts/jupytext
jupytext/cell_metadata.py
md_options_to_metadata
def md_options_to_metadata(options): """Parse markdown options and return language and metadata""" metadata = parse_md_code_options(options) if metadata: language = metadata[0][0] for lang in _JUPYTER_LANGUAGES + ['julia', 'scheme', 'c++']: if language.lower() == lang.lower(): ...
python
def md_options_to_metadata(options): """Parse markdown options and return language and metadata""" metadata = parse_md_code_options(options) if metadata: language = metadata[0][0] for lang in _JUPYTER_LANGUAGES + ['julia', 'scheme', 'c++']: if language.lower() == lang.lower(): ...
[ "def", "md_options_to_metadata", "(", "options", ")", ":", "metadata", "=", "parse_md_code_options", "(", "options", ")", "if", "metadata", ":", "language", "=", "metadata", "[", "0", "]", "[", "0", "]", "for", "lang", "in", "_JUPYTER_LANGUAGES", "+", "[", ...
Parse markdown options and return language and metadata
[ "Parse", "markdown", "options", "and", "return", "language", "and", "metadata" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L301-L311
train
mwouts/jupytext
jupytext/cell_metadata.py
try_eval_metadata
def try_eval_metadata(metadata, name): """Evaluate given metadata to a python object, if possible""" value = metadata[name] if not isinstance(value, (str, unicode)): return if (value.startswith('"') and value.endswith('"')) or (value.startswith("'") and value.endswith("'")): if name in [...
python
def try_eval_metadata(metadata, name): """Evaluate given metadata to a python object, if possible""" value = metadata[name] if not isinstance(value, (str, unicode)): return if (value.startswith('"') and value.endswith('"')) or (value.startswith("'") and value.endswith("'")): if name in [...
[ "def", "try_eval_metadata", "(", "metadata", ",", "name", ")", ":", "value", "=", "metadata", "[", "name", "]", "if", "not", "isinstance", "(", "value", ",", "(", "str", ",", "unicode", ")", ")", ":", "return", "if", "(", "value", ".", "startswith", ...
Evaluate given metadata to a python object, if possible
[ "Evaluate", "given", "metadata", "to", "a", "python", "object", "if", "possible" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L314-L330
train
mwouts/jupytext
jupytext/cell_metadata.py
json_options_to_metadata
def json_options_to_metadata(options, add_brackets=True): """Read metadata from its json representation""" try: options = loads('{' + options + '}' if add_brackets else options) return options except ValueError: return {}
python
def json_options_to_metadata(options, add_brackets=True): """Read metadata from its json representation""" try: options = loads('{' + options + '}' if add_brackets else options) return options except ValueError: return {}
[ "def", "json_options_to_metadata", "(", "options", ",", "add_brackets", "=", "True", ")", ":", "try", ":", "options", "=", "loads", "(", "'{'", "+", "options", "+", "'}'", "if", "add_brackets", "else", "options", ")", "return", "options", "except", "ValueErr...
Read metadata from its json representation
[ "Read", "metadata", "from", "its", "json", "representation" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L333-L339
train
mwouts/jupytext
jupytext/cell_metadata.py
is_active
def is_active(ext, metadata): """Is the cell active for the given file extension?""" if metadata.get('run_control', {}).get('frozen') is True: return False if 'active' not in metadata: return True return ext.replace('.', '') in re.split('\\.|,', metadata['active'])
python
def is_active(ext, metadata): """Is the cell active for the given file extension?""" if metadata.get('run_control', {}).get('frozen') is True: return False if 'active' not in metadata: return True return ext.replace('.', '') in re.split('\\.|,', metadata['active'])
[ "def", "is_active", "(", "ext", ",", "metadata", ")", ":", "if", "metadata", ".", "get", "(", "'run_control'", ",", "{", "}", ")", ".", "get", "(", "'frozen'", ")", "is", "True", ":", "return", "False", "if", "'active'", "not", "in", "metadata", ":",...
Is the cell active for the given file extension?
[ "Is", "the", "cell", "active", "for", "the", "given", "file", "extension?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L350-L356
train
mwouts/jupytext
jupytext/cell_metadata.py
double_percent_options_to_metadata
def double_percent_options_to_metadata(options): """Parse double percent options""" matches = _PERCENT_CELL.findall('# %%' + options) # Fail safe when regexp matching fails #116 # (occurs e.g. if square brackets are found in the title) if not matches: return {'title': options.strip()} ...
python
def double_percent_options_to_metadata(options): """Parse double percent options""" matches = _PERCENT_CELL.findall('# %%' + options) # Fail safe when regexp matching fails #116 # (occurs e.g. if square brackets are found in the title) if not matches: return {'title': options.strip()} ...
[ "def", "double_percent_options_to_metadata", "(", "options", ")", ":", "matches", "=", "_PERCENT_CELL", ".", "findall", "(", "'# %%'", "+", "options", ")", "# Fail safe when regexp matching fails #116", "# (occurs e.g. if square brackets are found in the title)", "if", "not", ...
Parse double percent options
[ "Parse", "double", "percent", "options" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L359-L395
train
mwouts/jupytext
jupytext/cell_metadata.py
metadata_to_double_percent_options
def metadata_to_double_percent_options(metadata): """Metadata to double percent lines""" options = [] if 'cell_depth' in metadata: options.append('%' * metadata.pop('cell_depth')) if 'title' in metadata: options.append(metadata.pop('title')) if 'cell_type' in metadata: option...
python
def metadata_to_double_percent_options(metadata): """Metadata to double percent lines""" options = [] if 'cell_depth' in metadata: options.append('%' * metadata.pop('cell_depth')) if 'title' in metadata: options.append(metadata.pop('title')) if 'cell_type' in metadata: option...
[ "def", "metadata_to_double_percent_options", "(", "metadata", ")", ":", "options", "=", "[", "]", "if", "'cell_depth'", "in", "metadata", ":", "options", ".", "append", "(", "'%'", "*", "metadata", ".", "pop", "(", "'cell_depth'", ")", ")", "if", "'title'", ...
Metadata to double percent lines
[ "Metadata", "to", "double", "percent", "lines" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L398-L410
train
mwouts/jupytext
jupytext/cell_metadata.py
ParsingContext.in_global_expression
def in_global_expression(self): """Currently inside an expression""" return (self.parenthesis_count == 0 and self.curly_bracket_count == 0 and self.square_bracket_count == 0 and not self.in_single_quote and not self.in_double_quote)
python
def in_global_expression(self): """Currently inside an expression""" return (self.parenthesis_count == 0 and self.curly_bracket_count == 0 and self.square_bracket_count == 0 and not self.in_single_quote and not self.in_double_quote)
[ "def", "in_global_expression", "(", "self", ")", ":", "return", "(", "self", ".", "parenthesis_count", "==", "0", "and", "self", ".", "curly_bracket_count", "==", "0", "and", "self", ".", "square_bracket_count", "==", "0", "and", "not", "self", ".", "in_sing...
Currently inside an expression
[ "Currently", "inside", "an", "expression" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L129-L133
train
mwouts/jupytext
jupytext/cell_metadata.py
ParsingContext.count_special_chars
def count_special_chars(self, char, prev_char): """Update parenthesis counters""" if char == '(': self.parenthesis_count += 1 elif char == ')': self.parenthesis_count -= 1 if self.parenthesis_count < 0: raise RMarkdownOptionParsingError( ...
python
def count_special_chars(self, char, prev_char): """Update parenthesis counters""" if char == '(': self.parenthesis_count += 1 elif char == ')': self.parenthesis_count -= 1 if self.parenthesis_count < 0: raise RMarkdownOptionParsingError( ...
[ "def", "count_special_chars", "(", "self", ",", "char", ",", "prev_char", ")", ":", "if", "char", "==", "'('", ":", "self", ".", "parenthesis_count", "+=", "1", "elif", "char", "==", "')'", ":", "self", ".", "parenthesis_count", "-=", "1", "if", "self", ...
Update parenthesis counters
[ "Update", "parenthesis", "counters" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_metadata.py#L135-L164
train
mwouts/jupytext
jupytext/formats.py
get_format_implementation
def get_format_implementation(ext, format_name=None): """Return the implementation for the desired format""" # remove pre-extension if any ext = '.' + ext.split('.')[-1] formats_for_extension = [] for fmt in JUPYTEXT_FORMATS: if fmt.extension == ext: if fmt.format_name == format...
python
def get_format_implementation(ext, format_name=None): """Return the implementation for the desired format""" # remove pre-extension if any ext = '.' + ext.split('.')[-1] formats_for_extension = [] for fmt in JUPYTEXT_FORMATS: if fmt.extension == ext: if fmt.format_name == format...
[ "def", "get_format_implementation", "(", "ext", ",", "format_name", "=", "None", ")", ":", "# remove pre-extension if any", "ext", "=", "'.'", "+", "ext", ".", "split", "(", "'.'", ")", "[", "-", "1", "]", "formats_for_extension", "=", "[", "]", "for", "fm...
Return the implementation for the desired format
[ "Return", "the", "implementation", "for", "the", "desired", "format" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L151-L170
train
mwouts/jupytext
jupytext/formats.py
read_metadata
def read_metadata(text, ext): """Return the header metadata""" ext = '.' + ext.split('.')[-1] lines = text.splitlines() if ext in ['.md', '.Rmd']: comment = '' else: comment = _SCRIPT_EXTENSIONS.get(ext, {}).get('comment', '#') metadata, _, _, _ = header_to_metadata_and_cell(li...
python
def read_metadata(text, ext): """Return the header metadata""" ext = '.' + ext.split('.')[-1] lines = text.splitlines() if ext in ['.md', '.Rmd']: comment = '' else: comment = _SCRIPT_EXTENSIONS.get(ext, {}).get('comment', '#') metadata, _, _, _ = header_to_metadata_and_cell(li...
[ "def", "read_metadata", "(", "text", ",", "ext", ")", ":", "ext", "=", "'.'", "+", "ext", ".", "split", "(", "'.'", ")", "[", "-", "1", "]", "lines", "=", "text", ".", "splitlines", "(", ")", "if", "ext", "in", "[", "'.md'", ",", "'.Rmd'", "]",...
Return the header metadata
[ "Return", "the", "header", "metadata" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L173-L187
train
mwouts/jupytext
jupytext/formats.py
read_format_from_metadata
def read_format_from_metadata(text, ext): """Return the format of the file, when that information is available from the metadata""" metadata = read_metadata(text, ext) rearrange_jupytext_metadata(metadata) return format_name_for_ext(metadata, ext, explicit_default=False)
python
def read_format_from_metadata(text, ext): """Return the format of the file, when that information is available from the metadata""" metadata = read_metadata(text, ext) rearrange_jupytext_metadata(metadata) return format_name_for_ext(metadata, ext, explicit_default=False)
[ "def", "read_format_from_metadata", "(", "text", ",", "ext", ")", ":", "metadata", "=", "read_metadata", "(", "text", ",", "ext", ")", "rearrange_jupytext_metadata", "(", "metadata", ")", "return", "format_name_for_ext", "(", "metadata", ",", "ext", ",", "explic...
Return the format of the file, when that information is available from the metadata
[ "Return", "the", "format", "of", "the", "file", "when", "that", "information", "is", "available", "from", "the", "metadata" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L190-L194
train
mwouts/jupytext
jupytext/formats.py
guess_format
def guess_format(text, ext): """Guess the format and format options of the file, given its extension and content""" lines = text.splitlines() metadata = read_metadata(text, ext) if ('jupytext' in metadata and set(metadata['jupytext']) .difference(['encoding', 'executable', 'main_language']...
python
def guess_format(text, ext): """Guess the format and format options of the file, given its extension and content""" lines = text.splitlines() metadata = read_metadata(text, ext) if ('jupytext' in metadata and set(metadata['jupytext']) .difference(['encoding', 'executable', 'main_language']...
[ "def", "guess_format", "(", "text", ",", "ext", ")", ":", "lines", "=", "text", ".", "splitlines", "(", ")", "metadata", "=", "read_metadata", "(", "text", ",", "ext", ")", "if", "(", "'jupytext'", "in", "metadata", "and", "set", "(", "metadata", "[", ...
Guess the format and format options of the file, given its extension and content
[ "Guess", "the", "format", "and", "format", "options", "of", "the", "file", "given", "its", "extension", "and", "content" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L197-L276
train
mwouts/jupytext
jupytext/formats.py
divine_format
def divine_format(text): """Guess the format of the notebook, based on its content #148""" try: nbformat.reads(text, as_version=4) return 'ipynb' except nbformat.reader.NotJSONError: pass lines = text.splitlines() for comment in ['', '#'] + _COMMENT_CHARS: metadata, ...
python
def divine_format(text): """Guess the format of the notebook, based on its content #148""" try: nbformat.reads(text, as_version=4) return 'ipynb' except nbformat.reader.NotJSONError: pass lines = text.splitlines() for comment in ['', '#'] + _COMMENT_CHARS: metadata, ...
[ "def", "divine_format", "(", "text", ")", ":", "try", ":", "nbformat", ".", "reads", "(", "text", ",", "as_version", "=", "4", ")", "return", "'ipynb'", "except", "nbformat", ".", "reader", ".", "NotJSONError", ":", "pass", "lines", "=", "text", ".", "...
Guess the format of the notebook, based on its content #148
[ "Guess", "the", "format", "of", "the", "notebook", "based", "on", "its", "content", "#148" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L279-L299
train
mwouts/jupytext
jupytext/formats.py
check_file_version
def check_file_version(notebook, source_path, outputs_path): """Raise if file version in source file would override outputs""" if not insert_or_test_version_number(): return _, ext = os.path.splitext(source_path) if ext.endswith('.ipynb'): return version = notebook.metadata.get('jup...
python
def check_file_version(notebook, source_path, outputs_path): """Raise if file version in source file would override outputs""" if not insert_or_test_version_number(): return _, ext = os.path.splitext(source_path) if ext.endswith('.ipynb'): return version = notebook.metadata.get('jup...
[ "def", "check_file_version", "(", "notebook", ",", "source_path", ",", "outputs_path", ")", ":", "if", "not", "insert_or_test_version_number", "(", ")", ":", "return", "_", ",", "ext", "=", "os", ".", "path", ".", "splitext", "(", "source_path", ")", "if", ...
Raise if file version in source file would override outputs
[ "Raise", "if", "file", "version", "in", "source", "file", "would", "override", "outputs" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L302-L333
train
mwouts/jupytext
jupytext/formats.py
format_name_for_ext
def format_name_for_ext(metadata, ext, cm_default_formats=None, explicit_default=True): """Return the format name for that extension""" # Is the format information available in the text representation? text_repr = metadata.get('jupytext', {}).get('text_representation', {}) if text_repr.get('extension', ...
python
def format_name_for_ext(metadata, ext, cm_default_formats=None, explicit_default=True): """Return the format name for that extension""" # Is the format information available in the text representation? text_repr = metadata.get('jupytext', {}).get('text_representation', {}) if text_repr.get('extension', ...
[ "def", "format_name_for_ext", "(", "metadata", ",", "ext", ",", "cm_default_formats", "=", "None", ",", "explicit_default", "=", "True", ")", ":", "# Is the format information available in the text representation?", "text_repr", "=", "metadata", ".", "get", "(", "'jupyt...
Return the format name for that extension
[ "Return", "the", "format", "name", "for", "that", "extension" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L336-L354
train
mwouts/jupytext
jupytext/formats.py
identical_format_path
def identical_format_path(fmt1, fmt2): """Do the two (long representation) of formats target the same file?""" for key in ['extension', 'prefix', 'suffix']: if fmt1.get(key) != fmt2.get(key): return False return True
python
def identical_format_path(fmt1, fmt2): """Do the two (long representation) of formats target the same file?""" for key in ['extension', 'prefix', 'suffix']: if fmt1.get(key) != fmt2.get(key): return False return True
[ "def", "identical_format_path", "(", "fmt1", ",", "fmt2", ")", ":", "for", "key", "in", "[", "'extension'", ",", "'prefix'", ",", "'suffix'", "]", ":", "if", "fmt1", ".", "get", "(", "key", ")", "!=", "fmt2", ".", "get", "(", "key", ")", ":", "retu...
Do the two (long representation) of formats target the same file?
[ "Do", "the", "two", "(", "long", "representation", ")", "of", "formats", "target", "the", "same", "file?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L357-L362
train
mwouts/jupytext
jupytext/formats.py
update_jupytext_formats_metadata
def update_jupytext_formats_metadata(metadata, new_format): """Update the jupytext_format metadata in the Jupyter notebook""" new_format = long_form_one_format(new_format) formats = long_form_multiple_formats(metadata.get('jupytext', {}).get('formats', '')) if not formats: return for fmt in...
python
def update_jupytext_formats_metadata(metadata, new_format): """Update the jupytext_format metadata in the Jupyter notebook""" new_format = long_form_one_format(new_format) formats = long_form_multiple_formats(metadata.get('jupytext', {}).get('formats', '')) if not formats: return for fmt in...
[ "def", "update_jupytext_formats_metadata", "(", "metadata", ",", "new_format", ")", ":", "new_format", "=", "long_form_one_format", "(", "new_format", ")", "formats", "=", "long_form_multiple_formats", "(", "metadata", ".", "get", "(", "'jupytext'", ",", "{", "}", ...
Update the jupytext_format metadata in the Jupyter notebook
[ "Update", "the", "jupytext_format", "metadata", "in", "the", "Jupyter", "notebook" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L365-L377
train
mwouts/jupytext
jupytext/formats.py
rearrange_jupytext_metadata
def rearrange_jupytext_metadata(metadata): """Convert the jupytext_formats metadata entry to jupytext/formats, etc. See #91""" # Backward compatibility with nbrmd for key in ['nbrmd_formats', 'nbrmd_format_version']: if key in metadata: metadata[key.replace('nbrmd', 'jupytext')] = metad...
python
def rearrange_jupytext_metadata(metadata): """Convert the jupytext_formats metadata entry to jupytext/formats, etc. See #91""" # Backward compatibility with nbrmd for key in ['nbrmd_formats', 'nbrmd_format_version']: if key in metadata: metadata[key.replace('nbrmd', 'jupytext')] = metad...
[ "def", "rearrange_jupytext_metadata", "(", "metadata", ")", ":", "# Backward compatibility with nbrmd", "for", "key", "in", "[", "'nbrmd_formats'", ",", "'nbrmd_format_version'", "]", ":", "if", "key", "in", "metadata", ":", "metadata", "[", "key", ".", "replace", ...
Convert the jupytext_formats metadata entry to jupytext/formats, etc. See #91
[ "Convert", "the", "jupytext_formats", "metadata", "entry", "to", "jupytext", "/", "formats", "etc", ".", "See", "#91" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L380-L422
train
mwouts/jupytext
jupytext/formats.py
long_form_one_format
def long_form_one_format(jupytext_format, metadata=None, update=None): """Parse 'sfx.py:percent' into {'suffix':'sfx', 'extension':'py', 'format_name':'percent'}""" if isinstance(jupytext_format, dict): if update: jupytext_format.update(update) return validate_one_format(jupytext_for...
python
def long_form_one_format(jupytext_format, metadata=None, update=None): """Parse 'sfx.py:percent' into {'suffix':'sfx', 'extension':'py', 'format_name':'percent'}""" if isinstance(jupytext_format, dict): if update: jupytext_format.update(update) return validate_one_format(jupytext_for...
[ "def", "long_form_one_format", "(", "jupytext_format", ",", "metadata", "=", "None", ",", "update", "=", "None", ")", ":", "if", "isinstance", "(", "jupytext_format", ",", "dict", ")", ":", "if", "update", ":", "jupytext_format", ".", "update", "(", "update"...
Parse 'sfx.py:percent' into {'suffix':'sfx', 'extension':'py', 'format_name':'percent'}
[ "Parse", "sfx", ".", "py", ":", "percent", "into", "{", "suffix", ":", "sfx", "extension", ":", "py", "format_name", ":", "percent", "}" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L425-L467
train
mwouts/jupytext
jupytext/formats.py
long_form_multiple_formats
def long_form_multiple_formats(jupytext_formats, metadata=None): """Convert a concise encoding of jupytext.formats to a list of formats, encoded as dictionaries""" if not jupytext_formats: return [] if not isinstance(jupytext_formats, list): jupytext_formats = [fmt for fmt in jupytext_forma...
python
def long_form_multiple_formats(jupytext_formats, metadata=None): """Convert a concise encoding of jupytext.formats to a list of formats, encoded as dictionaries""" if not jupytext_formats: return [] if not isinstance(jupytext_formats, list): jupytext_formats = [fmt for fmt in jupytext_forma...
[ "def", "long_form_multiple_formats", "(", "jupytext_formats", ",", "metadata", "=", "None", ")", ":", "if", "not", "jupytext_formats", ":", "return", "[", "]", "if", "not", "isinstance", "(", "jupytext_formats", ",", "list", ")", ":", "jupytext_formats", "=", ...
Convert a concise encoding of jupytext.formats to a list of formats, encoded as dictionaries
[ "Convert", "a", "concise", "encoding", "of", "jupytext", ".", "formats", "to", "a", "list", "of", "formats", "encoded", "as", "dictionaries" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L470-L480
train
mwouts/jupytext
jupytext/formats.py
short_form_one_format
def short_form_one_format(jupytext_format): """Represent one jupytext format as a string""" if not isinstance(jupytext_format, dict): return jupytext_format fmt = jupytext_format['extension'] if 'suffix' in jupytext_format: fmt = jupytext_format['suffix'] + fmt elif fmt.startswith('....
python
def short_form_one_format(jupytext_format): """Represent one jupytext format as a string""" if not isinstance(jupytext_format, dict): return jupytext_format fmt = jupytext_format['extension'] if 'suffix' in jupytext_format: fmt = jupytext_format['suffix'] + fmt elif fmt.startswith('....
[ "def", "short_form_one_format", "(", "jupytext_format", ")", ":", "if", "not", "isinstance", "(", "jupytext_format", ",", "dict", ")", ":", "return", "jupytext_format", "fmt", "=", "jupytext_format", "[", "'extension'", "]", "if", "'suffix'", "in", "jupytext_forma...
Represent one jupytext format as a string
[ "Represent", "one", "jupytext", "format", "as", "a", "string" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L483-L500
train
mwouts/jupytext
jupytext/formats.py
short_form_multiple_formats
def short_form_multiple_formats(jupytext_formats): """Convert jupytext formats, represented as a list of dictionaries, to a comma separated list""" if not isinstance(jupytext_formats, list): return jupytext_formats jupytext_formats = [short_form_one_format(fmt) for fmt in jupytext_formats] retu...
python
def short_form_multiple_formats(jupytext_formats): """Convert jupytext formats, represented as a list of dictionaries, to a comma separated list""" if not isinstance(jupytext_formats, list): return jupytext_formats jupytext_formats = [short_form_one_format(fmt) for fmt in jupytext_formats] retu...
[ "def", "short_form_multiple_formats", "(", "jupytext_formats", ")", ":", "if", "not", "isinstance", "(", "jupytext_formats", ",", "list", ")", ":", "return", "jupytext_formats", "jupytext_formats", "=", "[", "short_form_one_format", "(", "fmt", ")", "for", "fmt", ...
Convert jupytext formats, represented as a list of dictionaries, to a comma separated list
[ "Convert", "jupytext", "formats", "represented", "as", "a", "list", "of", "dictionaries", "to", "a", "comma", "separated", "list" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L503-L509
train
mwouts/jupytext
jupytext/formats.py
validate_one_format
def validate_one_format(jupytext_format): """Validate extension and options for the given format""" if not isinstance(jupytext_format, dict): raise JupytextFormatError('Jupytext format should be a dictionary') for key in jupytext_format: if key not in _VALID_FORMAT_INFO + _VALID_FORMAT_OPTI...
python
def validate_one_format(jupytext_format): """Validate extension and options for the given format""" if not isinstance(jupytext_format, dict): raise JupytextFormatError('Jupytext format should be a dictionary') for key in jupytext_format: if key not in _VALID_FORMAT_INFO + _VALID_FORMAT_OPTI...
[ "def", "validate_one_format", "(", "jupytext_format", ")", ":", "if", "not", "isinstance", "(", "jupytext_format", ",", "dict", ")", ":", "raise", "JupytextFormatError", "(", "'Jupytext format should be a dictionary'", ")", "for", "key", "in", "jupytext_format", ":", ...
Validate extension and options for the given format
[ "Validate", "extension", "and", "options", "for", "the", "given", "format" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/formats.py#L517-L538
train
mwouts/jupytext
jupytext/combine.py
black_invariant
def black_invariant(text, chars=None): """Remove characters that may be changed when reformatting the text with black""" if chars is None: chars = [' ', '\t', '\n', ',', "'", '"', '(', ')', '\\'] for char in chars: text = text.replace(char, '') return text
python
def black_invariant(text, chars=None): """Remove characters that may be changed when reformatting the text with black""" if chars is None: chars = [' ', '\t', '\n', ',', "'", '"', '(', ')', '\\'] for char in chars: text = text.replace(char, '') return text
[ "def", "black_invariant", "(", "text", ",", "chars", "=", "None", ")", ":", "if", "chars", "is", "None", ":", "chars", "=", "[", "' '", ",", "'\\t'", ",", "'\\n'", ",", "','", ",", "\"'\"", ",", "'\"'", ",", "'('", ",", "')'", ",", "'\\\\'", "]",...
Remove characters that may be changed when reformatting the text with black
[ "Remove", "characters", "that", "may", "be", "changed", "when", "reformatting", "the", "text", "with", "black" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/combine.py#L13-L20
train
mwouts/jupytext
jupytext/combine.py
combine_inputs_with_outputs
def combine_inputs_with_outputs(nb_source, nb_outputs, fmt=None): """Copy outputs of the second notebook into the first one, for cells that have matching inputs""" output_code_cells = [cell for cell in nb_outputs.cells if cell.cell_type == 'code'] output_other_cells = [cell for cell in nb_outputs.cells...
python
def combine_inputs_with_outputs(nb_source, nb_outputs, fmt=None): """Copy outputs of the second notebook into the first one, for cells that have matching inputs""" output_code_cells = [cell for cell in nb_outputs.cells if cell.cell_type == 'code'] output_other_cells = [cell for cell in nb_outputs.cells...
[ "def", "combine_inputs_with_outputs", "(", "nb_source", ",", "nb_outputs", ",", "fmt", "=", "None", ")", ":", "output_code_cells", "=", "[", "cell", "for", "cell", "in", "nb_outputs", ".", "cells", "if", "cell", ".", "cell_type", "==", "'code'", "]", "output...
Copy outputs of the second notebook into the first one, for cells that have matching inputs
[ "Copy", "outputs", "of", "the", "second", "notebook", "into", "the", "first", "one", "for", "cells", "that", "have", "matching", "inputs" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/combine.py#L28-L101
train
mwouts/jupytext
jupytext/contentsmanager.py
kernelspec_from_language
def kernelspec_from_language(language): """Return the kernel specification for the first kernel with a matching language""" try: for name in find_kernel_specs(): kernel_specs = get_kernel_spec(name) if kernel_specs.language == language or (language == 'c++' and kernel_specs.langu...
python
def kernelspec_from_language(language): """Return the kernel specification for the first kernel with a matching language""" try: for name in find_kernel_specs(): kernel_specs = get_kernel_spec(name) if kernel_specs.language == language or (language == 'c++' and kernel_specs.langu...
[ "def", "kernelspec_from_language", "(", "language", ")", ":", "try", ":", "for", "name", "in", "find_kernel_specs", "(", ")", ":", "kernel_specs", "=", "get_kernel_spec", "(", "name", ")", "if", "kernel_specs", ".", "language", "==", "language", "or", "(", "...
Return the kernel specification for the first kernel with a matching language
[ "Return", "the", "kernel", "specification", "for", "the", "first", "kernel", "with", "a", "matching", "language" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/contentsmanager.py#L33-L42
train
mwouts/jupytext
jupytext/contentsmanager.py
preferred_format
def preferred_format(incomplete_format, preferred_formats): """Return the preferred format for the given extension""" incomplete_format = long_form_one_format(incomplete_format) if 'format_name' in incomplete_format: return incomplete_format for fmt in long_form_multiple_formats(preferred_forma...
python
def preferred_format(incomplete_format, preferred_formats): """Return the preferred format for the given extension""" incomplete_format = long_form_one_format(incomplete_format) if 'format_name' in incomplete_format: return incomplete_format for fmt in long_form_multiple_formats(preferred_forma...
[ "def", "preferred_format", "(", "incomplete_format", ",", "preferred_formats", ")", ":", "incomplete_format", "=", "long_form_one_format", "(", "incomplete_format", ")", "if", "'format_name'", "in", "incomplete_format", ":", "return", "incomplete_format", "for", "fmt", ...
Return the preferred format for the given extension
[ "Return", "the", "preferred", "format", "for", "the", "given", "extension" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/contentsmanager.py#L45-L60
train
mwouts/jupytext
jupytext/contentsmanager.py
TextFileContentsManager.drop_paired_notebook
def drop_paired_notebook(self, path): """Remove the current notebook from the list of paired notebooks""" if path not in self.paired_notebooks: return fmt, formats = self.paired_notebooks.pop(path) prev_paired_paths = paired_paths(path, fmt, formats) for alt_path, _ ...
python
def drop_paired_notebook(self, path): """Remove the current notebook from the list of paired notebooks""" if path not in self.paired_notebooks: return fmt, formats = self.paired_notebooks.pop(path) prev_paired_paths = paired_paths(path, fmt, formats) for alt_path, _ ...
[ "def", "drop_paired_notebook", "(", "self", ",", "path", ")", ":", "if", "path", "not", "in", "self", ".", "paired_notebooks", ":", "return", "fmt", ",", "formats", "=", "self", ".", "paired_notebooks", ".", "pop", "(", "path", ")", "prev_paired_paths", "=...
Remove the current notebook from the list of paired notebooks
[ "Remove", "the", "current", "notebook", "from", "the", "list", "of", "paired", "notebooks" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/contentsmanager.py#L162-L171
train
mwouts/jupytext
jupytext/contentsmanager.py
TextFileContentsManager.update_paired_notebooks
def update_paired_notebooks(self, path, fmt, formats): """Update the list of paired notebooks to include/update the current pair""" if not formats: self.drop_paired_notebook(path) return new_paired_paths = paired_paths(path, fmt, formats) for alt_path, _ in new_p...
python
def update_paired_notebooks(self, path, fmt, formats): """Update the list of paired notebooks to include/update the current pair""" if not formats: self.drop_paired_notebook(path) return new_paired_paths = paired_paths(path, fmt, formats) for alt_path, _ in new_p...
[ "def", "update_paired_notebooks", "(", "self", ",", "path", ",", "fmt", ",", "formats", ")", ":", "if", "not", "formats", ":", "self", ".", "drop_paired_notebook", "(", "path", ")", "return", "new_paired_paths", "=", "paired_paths", "(", "path", ",", "fmt", ...
Update the list of paired notebooks to include/update the current pair
[ "Update", "the", "list", "of", "paired", "notebooks", "to", "include", "/", "update", "the", "current", "pair" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/contentsmanager.py#L173-L189
train
mwouts/jupytext
jupytext/contentsmanager.py
TextFileContentsManager.set_default_format_options
def set_default_format_options(self, format_options, read=False): """Set default format option""" if self.default_notebook_metadata_filter: format_options.setdefault('notebook_metadata_filter', self.default_notebook_metadata_filter) if self.default_cell_metadata_filter: f...
python
def set_default_format_options(self, format_options, read=False): """Set default format option""" if self.default_notebook_metadata_filter: format_options.setdefault('notebook_metadata_filter', self.default_notebook_metadata_filter) if self.default_cell_metadata_filter: f...
[ "def", "set_default_format_options", "(", "self", ",", "format_options", ",", "read", "=", "False", ")", ":", "if", "self", ".", "default_notebook_metadata_filter", ":", "format_options", ".", "setdefault", "(", "'notebook_metadata_filter'", ",", "self", ".", "defau...
Set default format option
[ "Set", "default", "format", "option" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/contentsmanager.py#L191-L204
train
mwouts/jupytext
jupytext/contentsmanager.py
TextFileContentsManager.default_formats
def default_formats(self, path): """Return the default formats, if they apply to the current path #157""" formats = long_form_multiple_formats(self.default_jupytext_formats) for fmt in formats: try: base_path(path, fmt) return self.default_jupytext_for...
python
def default_formats(self, path): """Return the default formats, if they apply to the current path #157""" formats = long_form_multiple_formats(self.default_jupytext_formats) for fmt in formats: try: base_path(path, fmt) return self.default_jupytext_for...
[ "def", "default_formats", "(", "self", ",", "path", ")", ":", "formats", "=", "long_form_multiple_formats", "(", "self", ".", "default_jupytext_formats", ")", "for", "fmt", "in", "formats", ":", "try", ":", "base_path", "(", "path", ",", "fmt", ")", "return"...
Return the default formats, if they apply to the current path #157
[ "Return", "the", "default", "formats", "if", "they", "apply", "to", "the", "current", "path", "#157" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/contentsmanager.py#L206-L216
train
mwouts/jupytext
jupytext/contentsmanager.py
TextFileContentsManager.create_prefix_dir
def create_prefix_dir(self, path, fmt): """Create the prefix dir, if missing""" create_prefix_dir(self._get_os_path(path.strip('/')), fmt)
python
def create_prefix_dir(self, path, fmt): """Create the prefix dir, if missing""" create_prefix_dir(self._get_os_path(path.strip('/')), fmt)
[ "def", "create_prefix_dir", "(", "self", ",", "path", ",", "fmt", ")", ":", "create_prefix_dir", "(", "self", ".", "_get_os_path", "(", "path", ".", "strip", "(", "'/'", ")", ")", ",", "fmt", ")" ]
Create the prefix dir, if missing
[ "Create", "the", "prefix", "dir", "if", "missing" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/contentsmanager.py#L218-L220
train
mwouts/jupytext
jupytext/contentsmanager.py
TextFileContentsManager.save
def save(self, model, path=''): """Save the file model and return the model with no content.""" if model['type'] != 'notebook': return super(TextFileContentsManager, self).save(model, path) nbk = model['content'] try: metadata = nbk.get('metadata') re...
python
def save(self, model, path=''): """Save the file model and return the model with no content.""" if model['type'] != 'notebook': return super(TextFileContentsManager, self).save(model, path) nbk = model['content'] try: metadata = nbk.get('metadata') re...
[ "def", "save", "(", "self", ",", "model", ",", "path", "=", "''", ")", ":", "if", "model", "[", "'type'", "]", "!=", "'notebook'", ":", "return", "super", "(", "TextFileContentsManager", ",", "self", ")", ".", "save", "(", "model", ",", "path", ")", ...
Save the file model and return the model with no content.
[ "Save", "the", "file", "model", "and", "return", "the", "model", "with", "no", "content", "." ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/contentsmanager.py#L222-L293
train
mwouts/jupytext
jupytext/contentsmanager.py
TextFileContentsManager.get
def get(self, path, content=True, type=None, format=None, load_alternative_format=True): """ Takes a path for an entity and returns its model""" path = path.strip('/') ext = os.path.splitext(path)[1] # Not a notebook? if not self.exists(path) or (type != 'notebook' if type else ...
python
def get(self, path, content=True, type=None, format=None, load_alternative_format=True): """ Takes a path for an entity and returns its model""" path = path.strip('/') ext = os.path.splitext(path)[1] # Not a notebook? if not self.exists(path) or (type != 'notebook' if type else ...
[ "def", "get", "(", "self", ",", "path", ",", "content", "=", "True", ",", "type", "=", "None", ",", "format", "=", "None", ",", "load_alternative_format", "=", "True", ")", ":", "path", "=", "path", ".", "strip", "(", "'/'", ")", "ext", "=", "os", ...
Takes a path for an entity and returns its model
[ "Takes", "a", "path", "for", "an", "entity", "and", "returns", "its", "model" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/contentsmanager.py#L295-L426
train
mwouts/jupytext
jupytext/contentsmanager.py
TextFileContentsManager.trust_notebook
def trust_notebook(self, path): """Trust the current notebook""" if path.endswith('.ipynb') or path not in self.paired_notebooks: super(TextFileContentsManager, self).trust_notebook(path) return fmt, formats = self.paired_notebooks[path] for alt_path, alt_fmt in ...
python
def trust_notebook(self, path): """Trust the current notebook""" if path.endswith('.ipynb') or path not in self.paired_notebooks: super(TextFileContentsManager, self).trust_notebook(path) return fmt, formats = self.paired_notebooks[path] for alt_path, alt_fmt in ...
[ "def", "trust_notebook", "(", "self", ",", "path", ")", ":", "if", "path", ".", "endswith", "(", "'.ipynb'", ")", "or", "path", "not", "in", "self", ".", "paired_notebooks", ":", "super", "(", "TextFileContentsManager", ",", "self", ")", ".", "trust_notebo...
Trust the current notebook
[ "Trust", "the", "current", "notebook" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/contentsmanager.py#L428-L437
train
mwouts/jupytext
jupytext/contentsmanager.py
TextFileContentsManager.rename_file
def rename_file(self, old_path, new_path): """Rename the current notebook, as well as its alternative representations""" if old_path not in self.paired_notebooks: try: # we do not know yet if this is a paired notebook (#190) # -> to get this information we ope...
python
def rename_file(self, old_path, new_path): """Rename the current notebook, as well as its alternative representations""" if old_path not in self.paired_notebooks: try: # we do not know yet if this is a paired notebook (#190) # -> to get this information we ope...
[ "def", "rename_file", "(", "self", ",", "old_path", ",", "new_path", ")", ":", "if", "old_path", "not", "in", "self", ".", "paired_notebooks", ":", "try", ":", "# we do not know yet if this is a paired notebook (#190)", "# -> to get this information we open the notebook", ...
Rename the current notebook, as well as its alternative representations
[ "Rename", "the", "current", "notebook", "as", "well", "as", "its", "alternative", "representations" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/contentsmanager.py#L439-L468
train
mwouts/jupytext
jupytext/pep8.py
next_instruction_is_function_or_class
def next_instruction_is_function_or_class(lines): """Is the first non-empty, non-commented line of the cell either a function or a class?""" for i, line in enumerate(lines): if not line.strip(): # empty line if i > 0 and not lines[i - 1].strip(): return False con...
python
def next_instruction_is_function_or_class(lines): """Is the first non-empty, non-commented line of the cell either a function or a class?""" for i, line in enumerate(lines): if not line.strip(): # empty line if i > 0 and not lines[i - 1].strip(): return False con...
[ "def", "next_instruction_is_function_or_class", "(", "lines", ")", ":", "for", "i", ",", "line", "in", "enumerate", "(", "lines", ")", ":", "if", "not", "line", ".", "strip", "(", ")", ":", "# empty line", "if", "i", ">", "0", "and", "not", "lines", "[...
Is the first non-empty, non-commented line of the cell either a function or a class?
[ "Is", "the", "first", "non", "-", "empty", "non", "-", "commented", "line", "of", "the", "cell", "either", "a", "function", "or", "a", "class?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/pep8.py#L5-L18
train
mwouts/jupytext
jupytext/pep8.py
cell_ends_with_function_or_class
def cell_ends_with_function_or_class(lines): """Does the last line of the cell belong to an indented code?""" non_quoted_lines = [] parser = StringParser('python') for line in lines: if not parser.is_quoted(): non_quoted_lines.append(line) parser.read_line(line) # find t...
python
def cell_ends_with_function_or_class(lines): """Does the last line of the cell belong to an indented code?""" non_quoted_lines = [] parser = StringParser('python') for line in lines: if not parser.is_quoted(): non_quoted_lines.append(line) parser.read_line(line) # find t...
[ "def", "cell_ends_with_function_or_class", "(", "lines", ")", ":", "non_quoted_lines", "=", "[", "]", "parser", "=", "StringParser", "(", "'python'", ")", "for", "line", "in", "lines", ":", "if", "not", "parser", ".", "is_quoted", "(", ")", ":", "non_quoted_...
Does the last line of the cell belong to an indented code?
[ "Does", "the", "last", "line", "of", "the", "cell", "belong", "to", "an", "indented", "code?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/pep8.py#L21-L44
train
mwouts/jupytext
jupytext/pep8.py
cell_ends_with_code
def cell_ends_with_code(lines): """Is the last line of the cell a line with code?""" if not lines: return False if not lines[-1].strip(): return False if lines[-1].startswith('#'): return False return True
python
def cell_ends_with_code(lines): """Is the last line of the cell a line with code?""" if not lines: return False if not lines[-1].strip(): return False if lines[-1].startswith('#'): return False return True
[ "def", "cell_ends_with_code", "(", "lines", ")", ":", "if", "not", "lines", ":", "return", "False", "if", "not", "lines", "[", "-", "1", "]", ".", "strip", "(", ")", ":", "return", "False", "if", "lines", "[", "-", "1", "]", ".", "startswith", "(",...
Is the last line of the cell a line with code?
[ "Is", "the", "last", "line", "of", "the", "cell", "a", "line", "with", "code?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/pep8.py#L47-L55
train
mwouts/jupytext
jupytext/pep8.py
cell_has_code
def cell_has_code(lines): """Is there any code in this cell?""" for i, line in enumerate(lines): stripped_line = line.strip() if stripped_line.startswith('#'): continue # Two consecutive blank lines? if not stripped_line: if i > 0 and not lines[i - 1].str...
python
def cell_has_code(lines): """Is there any code in this cell?""" for i, line in enumerate(lines): stripped_line = line.strip() if stripped_line.startswith('#'): continue # Two consecutive blank lines? if not stripped_line: if i > 0 and not lines[i - 1].str...
[ "def", "cell_has_code", "(", "lines", ")", ":", "for", "i", ",", "line", "in", "enumerate", "(", "lines", ")", ":", "stripped_line", "=", "line", ".", "strip", "(", ")", "if", "stripped_line", ".", "startswith", "(", "'#'", ")", ":", "continue", "# Two...
Is there any code in this cell?
[ "Is", "there", "any", "code", "in", "this", "cell?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/pep8.py#L58-L73
train
mwouts/jupytext
jupytext/pep8.py
pep8_lines_between_cells
def pep8_lines_between_cells(prev_lines, next_lines, ext): """How many blank lines should be added between the two python paragraphs to make them pep8?""" if not next_lines: return 1 if not prev_lines: return 0 if ext != '.py': return 1 if cell_ends_with_function_or_class(pre...
python
def pep8_lines_between_cells(prev_lines, next_lines, ext): """How many blank lines should be added between the two python paragraphs to make them pep8?""" if not next_lines: return 1 if not prev_lines: return 0 if ext != '.py': return 1 if cell_ends_with_function_or_class(pre...
[ "def", "pep8_lines_between_cells", "(", "prev_lines", ",", "next_lines", ",", "ext", ")", ":", "if", "not", "next_lines", ":", "return", "1", "if", "not", "prev_lines", ":", "return", "0", "if", "ext", "!=", "'.py'", ":", "return", "1", "if", "cell_ends_wi...
How many blank lines should be added between the two python paragraphs to make them pep8?
[ "How", "many", "blank", "lines", "should", "be", "added", "between", "the", "two", "python", "paragraphs", "to", "make", "them", "pep8?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/pep8.py#L76-L88
train
mwouts/jupytext
jupytext/compare.py
filtered_cell
def filtered_cell(cell, preserve_outputs, cell_metadata_filter): """Cell type, metadata and source from given cell""" metadata = copy(cell.metadata) filter_metadata(metadata, cell_metadata_filter, _IGNORE_CELL_METADATA) filtered = {'cell_type': cell.cell_type, 'source': cell.source, ...
python
def filtered_cell(cell, preserve_outputs, cell_metadata_filter): """Cell type, metadata and source from given cell""" metadata = copy(cell.metadata) filter_metadata(metadata, cell_metadata_filter, _IGNORE_CELL_METADATA) filtered = {'cell_type': cell.cell_type, 'source': cell.source, ...
[ "def", "filtered_cell", "(", "cell", ",", "preserve_outputs", ",", "cell_metadata_filter", ")", ":", "metadata", "=", "copy", "(", "cell", ".", "metadata", ")", "filter_metadata", "(", "metadata", ",", "cell_metadata_filter", ",", "_IGNORE_CELL_METADATA", ")", "fi...
Cell type, metadata and source from given cell
[ "Cell", "type", "metadata", "and", "source", "from", "given", "cell" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/compare.py#L16-L30
train
mwouts/jupytext
jupytext/compare.py
filtered_notebook_metadata
def filtered_notebook_metadata(notebook): """Notebook metadata, filtered for metadata added by Jupytext itself""" metadata = copy(notebook.metadata) metadata = filter_metadata(metadata, notebook.metadata.get('jupytext', {}).get('notebook_metadata_filter'), ...
python
def filtered_notebook_metadata(notebook): """Notebook metadata, filtered for metadata added by Jupytext itself""" metadata = copy(notebook.metadata) metadata = filter_metadata(metadata, notebook.metadata.get('jupytext', {}).get('notebook_metadata_filter'), ...
[ "def", "filtered_notebook_metadata", "(", "notebook", ")", ":", "metadata", "=", "copy", "(", "notebook", ".", "metadata", ")", "metadata", "=", "filter_metadata", "(", "metadata", ",", "notebook", ".", "metadata", ".", "get", "(", "'jupytext'", ",", "{", "}...
Notebook metadata, filtered for metadata added by Jupytext itself
[ "Notebook", "metadata", "filtered", "for", "metadata", "added", "by", "Jupytext", "itself" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/compare.py#L33-L41
train
mwouts/jupytext
jupytext/compare.py
same_content
def same_content(ref_source, test_source, allow_removed_final_blank_line): """Is the content of two cells the same, except for an optional final blank line?""" if ref_source == test_source: return True if not allow_removed_final_blank_line: return False # Is ref identical to test, plus...
python
def same_content(ref_source, test_source, allow_removed_final_blank_line): """Is the content of two cells the same, except for an optional final blank line?""" if ref_source == test_source: return True if not allow_removed_final_blank_line: return False # Is ref identical to test, plus...
[ "def", "same_content", "(", "ref_source", ",", "test_source", ",", "allow_removed_final_blank_line", ")", ":", "if", "ref_source", "==", "test_source", ":", "return", "True", "if", "not", "allow_removed_final_blank_line", ":", "return", "False", "# Is ref identical to t...
Is the content of two cells the same, except for an optional final blank line?
[ "Is", "the", "content", "of", "two", "cells", "the", "same", "except", "for", "an", "optional", "final", "blank", "line?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/compare.py#L48-L66
train
mwouts/jupytext
jupytext/compare.py
compare_notebooks
def compare_notebooks(notebook_expected, notebook_actual, fmt=None, allow_expected_differences=True, raise_on_first_difference=True, compare_outputs=False): """Compare the two notebooks, and raise with a me...
python
def compare_notebooks(notebook_expected, notebook_actual, fmt=None, allow_expected_differences=True, raise_on_first_difference=True, compare_outputs=False): """Compare the two notebooks, and raise with a me...
[ "def", "compare_notebooks", "(", "notebook_expected", ",", "notebook_actual", ",", "fmt", "=", "None", ",", "allow_expected_differences", "=", "True", ",", "raise_on_first_difference", "=", "True", ",", "compare_outputs", "=", "False", ")", ":", "fmt", "=", "long_...
Compare the two notebooks, and raise with a meaningful message that explains the differences, if any
[ "Compare", "the", "two", "notebooks", "and", "raise", "with", "a", "meaningful", "message", "that", "explains", "the", "differences", "if", "any" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/compare.py#L69-L218
train
mwouts/jupytext
jupytext/cell_to_text.py
cell_source
def cell_source(cell): """Return the source of the current cell, as an array of lines""" source = cell.source if source == '': return [''] if source.endswith('\n'): return source.splitlines() + [''] return source.splitlines()
python
def cell_source(cell): """Return the source of the current cell, as an array of lines""" source = cell.source if source == '': return [''] if source.endswith('\n'): return source.splitlines() + [''] return source.splitlines()
[ "def", "cell_source", "(", "cell", ")", ":", "source", "=", "cell", ".", "source", "if", "source", "==", "''", ":", "return", "[", "''", "]", "if", "source", ".", "endswith", "(", "'\\n'", ")", ":", "return", "source", ".", "splitlines", "(", ")", ...
Return the source of the current cell, as an array of lines
[ "Return", "the", "source", "of", "the", "current", "cell", "as", "an", "array", "of", "lines" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_to_text.py#L17-L24
train
mwouts/jupytext
jupytext/cell_to_text.py
endofcell_marker
def endofcell_marker(source, comment): """Issues #31 #38: does the cell contain a blank line? In that case we add an end-of-cell marker""" endofcell = '-' while True: endofcell_re = re.compile(r'^{}( )'.format(comment) + endofcell + r'\s*$') if list(filter(endofcell_re.match, source)): ...
python
def endofcell_marker(source, comment): """Issues #31 #38: does the cell contain a blank line? In that case we add an end-of-cell marker""" endofcell = '-' while True: endofcell_re = re.compile(r'^{}( )'.format(comment) + endofcell + r'\s*$') if list(filter(endofcell_re.match, source)): ...
[ "def", "endofcell_marker", "(", "source", ",", "comment", ")", ":", "endofcell", "=", "'-'", "while", "True", ":", "endofcell_re", "=", "re", ".", "compile", "(", "r'^{}( )'", ".", "format", "(", "comment", ")", "+", "endofcell", "+", "r'\\s*$'", ")", "i...
Issues #31 #38: does the cell contain a blank line? In that case we add an end-of-cell marker
[ "Issues", "#31", "#38", ":", "does", "the", "cell", "contain", "a", "blank", "line?", "In", "that", "case", "we", "add", "an", "end", "-", "of", "-", "cell", "marker" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_to_text.py#L182-L191
train
mwouts/jupytext
jupytext/cell_to_text.py
BaseCellExporter.is_code
def is_code(self): """Is this cell a code cell?""" if self.cell_type == 'code': return True if self.cell_type == 'raw' and 'active' in self.metadata: return True return False
python
def is_code(self): """Is this cell a code cell?""" if self.cell_type == 'code': return True if self.cell_type == 'raw' and 'active' in self.metadata: return True return False
[ "def", "is_code", "(", "self", ")", ":", "if", "self", ".", "cell_type", "==", "'code'", ":", "return", "True", "if", "self", ".", "cell_type", "==", "'raw'", "and", "'active'", "in", "self", ".", "metadata", ":", "return", "True", "return", "False" ]
Is this cell a code cell?
[ "Is", "this", "cell", "a", "code", "cell?" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_to_text.py#L66-L72
train
mwouts/jupytext
jupytext/cell_to_text.py
BaseCellExporter.cell_to_text
def cell_to_text(self): """Return the text representation for the cell""" if self.is_code(): return self.code_to_text() source = copy(self.source) if not self.comment: escape_code_start(source, self.ext, None) return self.markdown_to_text(source)
python
def cell_to_text(self): """Return the text representation for the cell""" if self.is_code(): return self.code_to_text() source = copy(self.source) if not self.comment: escape_code_start(source, self.ext, None) return self.markdown_to_text(source)
[ "def", "cell_to_text", "(", "self", ")", ":", "if", "self", ".", "is_code", "(", ")", ":", "return", "self", ".", "code_to_text", "(", ")", "source", "=", "copy", "(", "self", ".", "source", ")", "if", "not", "self", ".", "comment", ":", "escape_code...
Return the text representation for the cell
[ "Return", "the", "text", "representation", "for", "the", "cell" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_to_text.py#L74-L82
train
mwouts/jupytext
jupytext/cell_to_text.py
BaseCellExporter.markdown_to_text
def markdown_to_text(self, source): """Escape the given source, for a markdown cell""" if self.comment and self.comment != "#'": source = copy(source) comment_magic(source, self.language, self.comment_magics) return comment_lines(source, self.comment)
python
def markdown_to_text(self, source): """Escape the given source, for a markdown cell""" if self.comment and self.comment != "#'": source = copy(source) comment_magic(source, self.language, self.comment_magics) return comment_lines(source, self.comment)
[ "def", "markdown_to_text", "(", "self", ",", "source", ")", ":", "if", "self", ".", "comment", "and", "self", ".", "comment", "!=", "\"#'\"", ":", "source", "=", "copy", "(", "source", ")", "comment_magic", "(", "source", ",", "self", ".", "language", ...
Escape the given source, for a markdown cell
[ "Escape", "the", "given", "source", "for", "a", "markdown", "cell" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_to_text.py#L84-L90
train
mwouts/jupytext
jupytext/cell_to_text.py
MarkdownCellExporter.cell_to_text
def cell_to_text(self): """Return the text representation of a cell""" if self.cell_type == 'markdown': # Is an explicit region required? if self.metadata or self.cell_reader(self.fmt).read(self.source)[1] < len(self.source): if self.metadata: ...
python
def cell_to_text(self): """Return the text representation of a cell""" if self.cell_type == 'markdown': # Is an explicit region required? if self.metadata or self.cell_reader(self.fmt).read(self.source)[1] < len(self.source): if self.metadata: ...
[ "def", "cell_to_text", "(", "self", ")", ":", "if", "self", ".", "cell_type", "==", "'markdown'", ":", "# Is an explicit region required?", "if", "self", ".", "metadata", "or", "self", ".", "cell_reader", "(", "self", ".", "fmt", ")", ".", "read", "(", "se...
Return the text representation of a cell
[ "Return", "the", "text", "representation", "of", "a", "cell" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_to_text.py#L116-L134
train
mwouts/jupytext
jupytext/cell_to_text.py
MarkdownCellExporter.code_to_text
def code_to_text(self): """Return the text representation of a code cell""" source = copy(self.source) comment_magic(source, self.language, self.comment_magics) options = [] if self.cell_type == 'code' and self.language: options.append(self.language) filtere...
python
def code_to_text(self): """Return the text representation of a code cell""" source = copy(self.source) comment_magic(source, self.language, self.comment_magics) options = [] if self.cell_type == 'code' and self.language: options.append(self.language) filtere...
[ "def", "code_to_text", "(", "self", ")", ":", "source", "=", "copy", "(", "self", ".", "source", ")", "comment_magic", "(", "source", ",", "self", ".", "language", ",", "self", ".", "comment_magics", ")", "options", "=", "[", "]", "if", "self", ".", ...
Return the text representation of a code cell
[ "Return", "the", "text", "representation", "of", "a", "code", "cell" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_to_text.py#L136-L151
train
mwouts/jupytext
jupytext/cell_to_text.py
LightScriptCellExporter.code_to_text
def code_to_text(self): """Return the text representation of a code cell""" active = is_active(self.ext, self.metadata) if self.language != self.default_language and 'active' not in self.metadata: active = False source = copy(self.source) escape_code_start(source, se...
python
def code_to_text(self): """Return the text representation of a code cell""" active = is_active(self.ext, self.metadata) if self.language != self.default_language and 'active' not in self.metadata: active = False source = copy(self.source) escape_code_start(source, se...
[ "def", "code_to_text", "(", "self", ")", ":", "active", "=", "is_active", "(", "self", ".", "ext", ",", "self", ".", "metadata", ")", "if", "self", ".", "language", "!=", "self", ".", "default_language", "and", "'active'", "not", "in", "self", ".", "me...
Return the text representation of a code cell
[ "Return", "the", "text", "representation", "of", "a", "code", "cell" ]
eb7d6aee889f80ad779cfc53441c648f0db9246d
https://github.com/mwouts/jupytext/blob/eb7d6aee889f80ad779cfc53441c648f0db9246d/jupytext/cell_to_text.py#L218-L255
train