How to use the jupytext.magics.comment_magic function in jupytext

To help you get started, we’ve selected a few jupytext examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mwouts / jupytext / tests / test_escape_magics.py View on Github external
def test_escape_magic_only(line):
    assert comment_magic([line]) == [line]
github mwouts / jupytext / tests / test_escape_magics.py View on Github external
def test_force_noescape_with_gbl_esc_flag(line):
    assert comment_magic([line], global_escape_flag=True) == [line]
github mwouts / jupytext / tests / test_escape_magics.py View on Github external
def test_do_not_comment_python_cmds(not_magic_cmd):
    assert comment_magic([not_magic_cmd]) == [not_magic_cmd]
    assert uncomment_magic([not_magic_cmd]) == [not_magic_cmd]
github mwouts / jupytext / tests / test_escape_magics.py View on Github external
def test_do_not_comment_bash_commands_in_R(magic_cmd):
    assert comment_magic([magic_cmd], language='R') == [magic_cmd]
    assert uncomment_magic([magic_cmd], language='R') == [magic_cmd]
github mwouts / jupytext / tests / test_escape_magics.py View on Github external
def test_comment_bash_commands_in_python(magic_cmd):
    assert comment_magic([magic_cmd]) == ['# ' + magic_cmd]
    assert uncomment_magic(['# ' + magic_cmd]) == [magic_cmd]
github mwouts / jupytext / jupytext / cell_to_text.py View on Github external
if cell_markers:
            if ',' in cell_markers:
                left, right = cell_markers.split(',', 1)
            else:
                left = cell_markers + '\n'
                right = '\n' + cell_markers
            if left[:3] == right[-3:] and left[:3] in ['"""', "'''"]:
                source = copy(source)
                source[0] = left + source[0]
                source[-1] = source[-1] + right
                return source

        if self.comment and self.comment != "#'" and is_active(self.ext, self.metadata) and \
                self.fmt.get('format_name') not in ['percent', 'hydrogen']:
            source = copy(source)
            comment_magic(source, self.language, self.comment_magics, explicitly_code=self.cell_type == 'code')

        return comment_lines(source, self.comment)
github mwouts / jupytext / jupytext / cell_to_text.py View on Github external
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)

        if self.metadata.get('active') == '':
            self.metadata.pop('active')

        self.language = self.metadata.pop('language', self.language)
        if self.cell_type == 'raw' and not is_active(self.ext, self.metadata, False):
            return self.html_comment(self.metadata, 'raw')

        options = metadata_to_text(self.language, self.metadata)
        return ['```' + options] + source + ['```']
github mwouts / jupytext / jupytext / cell_to_text.py View on Github external
def cell_to_text(self):
        """Return the text representation for the cell"""
        if self.cell_type == 'code':
            source = copy(self.source)
            return comment_magic(source, self.language, self.comment_magics)

        if 'cell_marker' in self.metadata:
            cell_marker = self.metadata.pop('cell_marker')
        else:
            cell_marker = self.default_cell_marker

        if self.source == ['']:
            return [cell_marker] if cell_marker in ['""', "''"] else ['""']

        if cell_marker in ['"""', "'''"]:
            return [cell_marker] + self.source + [cell_marker]

        return [cell_marker if cell_marker.startswith('#' * 20)
                else self.default_cell_marker] + comment_lines(self.source, self.comment)
github mwouts / jupytext / jupytext / cell_to_text.py View on Github external
def code_to_text(self):
        """Return the text representation of a code cell"""
        active = is_active(self.ext, self.metadata, self.language == self.default_language)
        source = copy(self.source)
        escape_code_start(source, self.ext, self.language)
        comment_questions = self.metadata.pop('comment_questions', True)

        if active:
            comment_magic(source, self.language, self.comment_magics, comment_questions)
        else:
            source = self.markdown_to_text(source)

        if (active and comment_questions and need_explicit_marker(self.source, self.language, self.comment_magics)) \
                or self.explicit_start_marker(source):
            self.metadata['endofcell'] = self.cell_marker_end or endofcell_marker(source, self.comment)

        if not self.metadata or not self.use_cell_markers:
            return source

        lines = []
        endofcell = self.metadata['endofcell']
        if endofcell == '-' or self.cell_marker_end:
            del self.metadata['endofcell']

        cell_start = [self.comment, self.cell_marker_start or '+']