Domen Preložnik
Domen Preložnik

Reputation: 348

Is there a way to remove Jupyter "Run Cell" buttons in Visual Studio Code?

I want to remove the Jupyter "Run Cell|Run All Cells" buttons that appear if the syntax #%% is present in Visual Studio Code.

vsc

Is there a setting that controls that?

Upvotes: 16

Views: 4201

Answers (4)

bad programmer
bad programmer

Reputation: 934

Save the code snippet below as : remove_inline_comment.py
Assuming your filename as : sample_file.py,
RUN : python remove_inline_comment.py sample_file.py

[ NOTE : Make sure both of these files are in same folder ]

import argparse
import os
import sys
import re


def process(filename):
    """Removes empty lines and lines that contain only whitespace, and
    lines with comments"""

    with open(filename) as in_file, open(filename, "r+") as out_file:
        for line in in_file:
            if re.match("# In\[[0-9\\d+\]]", line):
                out_file.write("\n")
            else:
                out_file.writelines(line)


if __name__ == "__main__":

    my_parser = argparse.ArgumentParser(
        description="Removing the In#\[[0-9\d+\]] in notebook to script conversion"
    )

    my_parser.add_argument(
        "script_path",
        metavar="path",
        type=str,
        help="path to script that requires a conversion",
    )

    args = my_parser.parse_args()
    script_path = args.script_path

    file_format = script_path.split(".")[1]
    if file_format != "py":
        print("File is not a py file")
        sys.exit()

    try:
        print(f"processing : {script_path}")
        process(script_path)
    except FileNotFoundError:
        print("Please provide path correctly")

Upvotes: -2

Adav
Adav

Reputation: 468

Update for others coming to this question:

With recent update you can choose what's displayed Run cell |...". If you're looking to remove clutter delete everything and save like below:

enter image description here

I would recommend leaving at least python.datascience.runcell as it seems to disable shift+enter shortcut

Upvotes: 2

mirkancal
mirkancal

Reputation: 5385

You can toggle off Python>Data Science: Enable Cell Code Lens settings.

Screenshot from settings

Upvotes: 11

Ian Huff
Ian Huff

Reputation: 3117

If you turn off the data science features (the Python Interactive window) under Settings>Python>Data Science>Enabled then you won't see those code lenses any more. However that will also hide the rest of the data science features along with the lenses. Were you looking to turn off all data science features in the python extension or just the lenses?

Upvotes: 2

Related Questions