Exemple #1
0
    def execute_current(self, command_name: str) -> None:
        """
        This method's job is to create a command for running/debugging
        current file/script and submit it to shell
        """

        if not self.is_waiting_toplevel_command():
            self.restart_backend(False, False, 2)

        filename = get_saved_current_script_filename()

        if not filename:
            # user has cancelled file saving
            return

        if is_remote_path(filename) or not self._proxy.uses_local_filesystem():
            working_directory = None
        else:
            # changing dir may be required
            script_dir = os.path.dirname(filename)

            if get_workbench().get_option(
                    "run.auto_cd") and command_name[0].isupper():
                working_directory = script_dir  # type: Optional[str]
            else:
                working_directory = None

        args = self._get_active_arguments()

        self.execute_script(filename, args, working_directory, command_name)
Exemple #2
0
    def execute_current(self, command_name: str) -> None:
        """
        This method's job is to create a command for running/debugging
        current file/script and submit it to shell
        """

        if not self.is_waiting_toplevel_command():
            self.restart_backend(False, False, 2)

        filename = get_saved_current_script_filename()

        if not filename:
            # cancel must have been pushed
            return

        # changing dir may be required
        script_dir = normpath_with_actual_case(os.path.dirname(filename))

        if get_workbench().get_option(
                "run.auto_cd") and command_name[0].isupper():
            working_directory = script_dir  # type: Optional[str]
        else:
            working_directory = None

        args = self._get_active_arguments()

        self.execute_script(filename, args, working_directory, command_name)
Exemple #3
0
 def _cmd_run_current_script_in_terminal(self) -> None:
     filename = get_saved_current_script_filename()
     self._proxy.run_script_in_terminal(
         filename,
         self._get_active_arguments(),
         get_workbench().get_option("run.run_in_terminal_python_repl"),
         get_workbench().get_option("run.run_in_terminal_keep_open"),
     )
Exemple #4
0
def _open_system_shell():
    """Main task is to modify path and open terminal window.
    Bonus (and most difficult) part is executing a script in this window
    for recommending commands for running given python and related pip"""

    filename = get_saved_current_script_filename(force=False)
    if filename:
        cwd = os.path.dirname(filename)
    else:
        cwd = None

    proxy = get_runner().get_backend_proxy()
    if proxy and proxy.get_local_executable():
        target_executable = proxy.get_local_executable()
    else:
        target_executable = sys.executable

    exe_dirs = get_exe_dirs()
    if hasattr(proxy, "get_exe_dirs") and proxy.get_exe_dirs():
        # use both backend and frontend exe dirs
        exe_dirs = proxy.get_exe_dirs() + exe_dirs

    env_overrides = get_environment_overrides_for_python_subprocess(
        target_executable)
    env_overrides["PATH"] = get_augmented_system_path(exe_dirs)

    explainer = os.path.join(os.path.dirname(__file__),
                             "explain_environment.py")
    cmd = [target_executable, explainer]

    activate = os.path.join(
        os.path.dirname(target_executable),
        "activate.bat" if platform.system() == "Windows" else "activate")

    if os.path.isfile(activate):
        del env_overrides["PATH"]
        if platform.system() == "Windows":
            cmd = [activate, "&"] + cmd
        else:
            cmd = ["source", activate, ";"] + cmd

    return terminal.run_in_terminal(cmd, cwd, env_overrides, True)