Пример #1
0
    def _create_private_venv(self,
                             path,
                             description,
                             clear=False,
                             upgrade=False):
        if not _check_venv_installed(self):
            return
        # Don't include system site packages
        # This way all students will have similar configuration
        # independently of system Python (if Thonny is used with system Python)

        # NB! Cant run venv.create directly, because in Windows bundle
        # it tries to link venv to thonny.exe.
        # Need to run it via proper python
        args = ["-m", "venv"]
        if clear:
            args.append("--clear")
        if upgrade:
            args.append("--upgrade")

        try:
            import ensurepip
        except ImportError:
            args.append("--without-pip")

        args.append(path)

        proc = create_frontend_python_process(args)

        from thonny.workdlg import SubprocessDialog

        dlg = SubprocessDialog(
            get_workbench(),
            proc,
            "Preparing the backend",
            long_description=description,
            autostart=True,
        )
        try:
            ui_utils.show_dialog(dlg)
        except Exception:
            # if using --without-pip the dialog may close very quickly
            # and for some reason wait_window would give error then
            logging.exception("Problem with waiting for venv creation dialog")
        get_workbench().become_active_window(
        )  # Otherwise focus may get stuck somewhere

        bindir = os.path.dirname(get_private_venv_executable())
        # create private env marker
        marker_path = os.path.join(bindir, "is_private")
        with open(marker_path, mode="w") as fp:
            fp.write("# This file marks Thonny-private venv")

        # Create recommended pip conf to get rid of list deprecation warning
        # https://github.com/pypa/pip/issues/4058
        pip_conf = "pip.ini" if running_on_windows() else "pip.conf"
        with open(os.path.join(path, pip_conf), mode="w") as fp:
            fp.write("[list]\nformat = columns")

        assert os.path.isdir(path)
Пример #2
0
 def _run_pip_with_dialog(self, args, title) -> Tuple[int, str, str]:
     args = ["-m", "thonny.plugins.micropython.minipip"] + args
     proc = running.create_frontend_python_process(args, stderr=subprocess.STDOUT)
     cmd = proc.cmd
     dlg = SubprocessDialog(self, proc, "minipip", long_description=title, autostart=True)
     ui_utils.show_dialog(dlg)
     return dlg.returncode, dlg.stdout, dlg.stderr
Пример #3
0
 def _run_pip_with_dialog(self, args, title) -> Tuple[int, str, str]:
     args = ["-m", "thonny.plugins.micropython.minipip"] + args
     proc = running.create_frontend_python_process(args, stderr=subprocess.STDOUT)
     cmd = proc.cmd
     dlg = InstallAndUploadDialog(
         self,
         proc,
         back_cmd=self._create_upload_command,
         title="minipip",
         instructions=title,
         autostart=True,
         output_prelude=subprocess.list2cmdline(cmd) + "\n",
     )
     ui_utils.show_dialog(dlg)
     assert dlg.returncode is not None
     return dlg.returncode, dlg.stdout, dlg.stderr
Пример #4
0
 def _create_python_process(self, args, stderr):
     proc = running.create_frontend_python_process(args, stderr=stderr)
     return proc, proc.cmd