Beispiel #1
0
    def __init__(self, clean):
        self._port = get_workbench().get_option(self.backend_name + ".port")
        self._clean_start = clean

        if self._port == "auto":
            potential = self._detect_potential_ports()
            if len(potential) == 1:
                self._port = potential[0][0]
            else:
                self._port = None
                message = dedent("""\
                    Couldn't find the device automatically. 
                    Check the connection (making sure the device is not in bootloader mode)
                    or choose "Tools → Options → Interpreter" to select the port manually."""
                                 )

                if len(potential) > 1:
                    _, descriptions = zip(*potential)
                    message += "\n\nLikely candidates are:\n * " + "\n * ".join(
                        descriptions)

                self._show_error(message)

        super().__init__(clean, running.get_frontend_python())

        # Following is required for compatibility with older MP plugins (ESP)
        # TODO: remove it later
        self.micropython_upload_enabled = False
Beispiel #2
0
 def construct_firmware_upload_command(self, firmware_path):
     return [get_frontend_python(), '-u', '-m', 
             'esptool', 
             '--port', self.port, 
             #'--baud', '460800',  
             'write_flash', 
             #'--flash_size', 'detect',
             #"--flash_mode", self.flash_mode,
             '0x0000', firmware_path]
Beispiel #3
0
 def erase_flash(self):
     self.disconnect()
     cmd = [get_frontend_python(), '-u', '-m', 
             'esptool', 
             '--port', self.port, 
             'erase_flash']
     proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                         universal_newlines=True)
     dlg = SubprocessDialog(get_workbench(), proc, "Erasing flash", autoclose=False)
     dlg.wait_window()
Beispiel #4
0
    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_frontend_python(),
            "-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__),
        )
Beispiel #5
0
    def _create_venv(self):
        path = None
        while True:
            path = askdirectory(
                master=self,
                initialdir=path,
                title=_("Select empty directory for new virtual environment"),
            )
            if not path:
                return

            if os.listdir(path):
                messagebox.showerror(
                    _("Bad directory"),
                    _("Selected directory is not empty.\nSelect another or cancel."
                      ),
                    parent=get_workbench(),
                )
            else:
                break
        assert os.path.isdir(path)
        path = normpath_with_actual_case(path)

        proc = subprocess.Popen(
            [running.get_frontend_python(), "-m", "venv", path],
            stdin=None,
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            universal_newlines=True,
        )
        dlg = SubprocessDialog(self, proc, _("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)
Beispiel #6
0
    def __init__(self, clean):
        self._port = get_workbench().get_option(self.backend_name + ".port")

        if self._port == "auto":
            potential = self._detect_potential_ports()
            if len(potential) == 1:
                self._port = potential[0][0]
            else:
                self._port = None
                message = dedent("""\
                    Couldn't find the device automatically. 
                    Check the connection (making sure the device is not in bootloader mode)
                    or choose "Tools → Options → Backend" to select the port manually."""
                                 )

                if len(potential) > 1:
                    _, descriptions = zip(*potential)
                    message += "\n\nLikely candidates are:\n * " + "\n * ".join(
                        descriptions)

                self._show_error(message)

        super().__init__(clean, running.get_frontend_python())