def __init__(self, clean): executable = get_workbench().get_option("CustomInterpreter.path") # Rembember the usage of this non-default interpreter used_interpreters = get_workbench().get_option( "CustomInterpreter.used_paths") if executable not in used_interpreters: used_interpreters.append(executable) get_workbench().set_option("CustomInterpreter.used_paths", used_interpreters) super().__init__(clean, get_interpreter_for_subprocess(executable))
def _create_venv(self, event=None): messagebox.showinfo( "Creating new virtual environment", "After clicking 'OK' you need to choose an empty directory, " "which will be the root of your new virtual environment.", parent=self, ) path = None while True: path = askdirectory( parent=self.winfo_toplevel(), initialdir=path, title=tr("Select empty directory for new virtual environment"), ) if not path: return if os.listdir(path): messagebox.showerror( tr("Bad directory"), tr("Selected directory is not empty.\nSelect another or cancel." ), master=self, ) else: break assert os.path.isdir(path) path = normpath_with_actual_case(path) proc = subprocess.Popen( [running.get_interpreter_for_subprocess(), "-m", "venv", path], stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, ) from thonny.workdlg import SubprocessDialog dlg = SubprocessDialog(self, proc, tr("Creating virtual environment"), autostart=True) ui_utils.show_dialog(dlg) if running_on_windows(): exe_path = normpath_with_actual_case( os.path.join(path, "Scripts", "python.exe")) else: exe_path = os.path.join(path, "bin", "python3") if os.path.exists(exe_path): self._configuration_variable.set(exe_path)
def _get_esptool_command(self): try: import esptool return [get_interpreter_for_subprocess(), "-u", "-m", "esptool"] except ImportError: import shutil result = shutil.which("esptool") if result: return result else: return shutil.which("esptool.py")
def start_analysis(self, main_file_path, imported_file_paths): relevant_symbols = { checks_by_id[key]["msg_sym"] for key in checks_by_id if checks_by_id[key]["usage"] == "warning" } if "bad-python3-import" in relevant_symbols: # https://github.com/PyCQA/pylint/issues/2453 # TODO: allow if this is fixed in minimum version relevant_symbols.remove("bad-python3-import") # remove user-disabled checks relevant_symbols = relevant_symbols - set( get_workbench().get_option("assistance.disabled_checks")) ignored_modules = {"turtle"} # has dynamically generated attributes options = [ # "--rcfile=None", # TODO: make it ignore any rcfiles that can be somewhere "--persistent=n", # "--confidence=HIGH", # Leave empty to show all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED # "--disable=missing-docstring,invalid-name,trailing-whitespace,trailing-newlines,missing-final-newline,locally-disabled,suppressed-message", "--disable=all", "--enable=" + ",".join(relevant_symbols), "--ignored-modules=" + ",".join(ignored_modules), "--max-line-length=120", "--output-format=text", "--reports=n", "--msg-template={{'filename':{abspath!r}, 'lineno':{line}, 'col_offset':{column}, 'symbol':{symbol!r}, 'msg':{msg!r}, 'msg_id':{msg_id!r}, 'category' : {C!r} }}", ] # disallow unused globals only in main script """ Not good idea, because unused * imports also count as unused global vars from pylint.__pkginfo__ import numversion if not imported_file_paths and numversion >= (1, 7): # (unfortunately can't separate main script when user modules are present) options.append("--allow-global-unused-variables=no") """ self._proc = ui_utils.popen_with_ui_thread_callback( [get_interpreter_for_subprocess(), "-m", "pylint"] + options + [main_file_path] + list(imported_file_paths), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, on_completion=self._parse_and_output_warnings, )
def start_analysis(self, main_file_path, imported_file_paths: Iterable[str]) -> None: self.interesting_files = [main_file_path] + list(imported_file_paths) args = [ get_interpreter_for_subprocess(), "-m", "mypy", "--ignore-missing-imports", "--check-untyped-defs", "--warn-redundant-casts", "--show-column-numbers", main_file_path, ] + list(imported_file_paths) # TODO: ignore "... need type annotation" messages from mypy.version import __version__ try: ver = tuple(map(int, __version__.split("."))) except Exception: ver = (0, 470) # minimum required version if ver >= (0, 520): args.insert(3, "--no-implicit-optional") if ver >= (0, 590): args.insert(3, "--python-executable") args.insert(4, get_runner().get_local_executable()) env = os.environ.copy() env["MYPYPATH"] = os.path.join(os.path.dirname(__file__), "typeshed_extras") self._proc = ui_utils.popen_with_ui_thread_callback( args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, env=env, on_completion=self._parse_and_output_warnings, # Specify a cwd which is not ancestor of user files. # This gives absolute filenames in the output. # Note that mypy doesn't accept when cwd is sys.prefix # or dirname(sys.executable) cwd=os.path.dirname(__file__), )
def start_server(): global _server_process out_err_filename = os.path.join(THONNY_USER_DIR, "birdseye.log") output_file = open(out_err_filename, "w") _server_process = subprocess.Popen( [ running.get_interpreter_for_subprocess(), "-m", "birdseye", "-p", str(get_workbench().get_option("run.birdseye_port")), ], stdout=output_file, stderr=output_file, ) atexit.register(close_server)
def _create_venv(self): path = None while True: path = askdirectory( master=self, initialdir=path, title=tr("Select empty directory for new virtual environment"), ) if not path: return if os.listdir(path): messagebox.showerror( tr("Bad directory"), tr("Selected directory is not empty.\nSelect another or cancel." ), ) else: break assert os.path.isdir(path) path = normpath_with_actual_case(path) proc = subprocess.Popen( [running.get_interpreter_for_subprocess(), "-m", "venv", path], stdin=None, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, ) dlg = SubprocessDialog(self, proc, tr("Creating virtual environment")) ui_utils.show_dialog(dlg) if running_on_windows(): exe_path = normpath_with_actual_case( os.path.join(path, "Scripts", "python.exe")) else: exe_path = os.path.join(path, "bin", "python3") if os.path.exists(exe_path): self._configuration_variable.set(exe_path)
def __init__(self, master): super().__init__(master) label = ttk.Label(self, text=get_interpreter_for_subprocess()) label.grid()
def __init__(self, clean): super().__init__(clean, get_interpreter_for_subprocess())
def _get_interpreter(self): return get_interpreter_for_subprocess(sys.executable)
def __init__(self, clean): self._lib_dirs = [] super().__init__(clean, running.get_interpreter_for_subprocess())
def __init__(self, clean): self._mp_executable = get_workbench().get_option( "LocalMicroPython.executable") super().__init__(clean, running.get_interpreter_for_subprocess())