Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Generalize Run plugin to support generic inputs and executors #17467

Merged
merged 102 commits into from
Feb 15, 2023
Merged
Changes from 1 commit
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
d89e4b4
Start Run plugin generalization
andfoy Mar 10, 2022
c103a55
Finish typing stubs and Run API interfaces
andfoy Mar 10, 2022
cb61372
Add register and deregister methods for InputProviders, Executors and…
andfoy Mar 16, 2022
a1b920c
Merge remote-tracking branch 'upstream/master' into split_run_editor
andfoy Mar 17, 2022
dbb2bf6
Fix docstrings and some interface naming
andfoy Mar 27, 2022
738e0fa
Move context and extension to run configuration metadata
andfoy Mar 29, 2022
e26c41f
Start working on the new Run dialog
andfoy Mar 30, 2022
5a00314
Define abstract models for both model configurations as well as execu…
andfoy Apr 20, 2022
6e57446
Merge branch 'master' into split_run_editor
andfoy Apr 20, 2022
e4a986e
Register files from the editor
andfoy Apr 21, 2022
56dda5f
Fix issues with the run configuration combobox
andfoy May 9, 2022
2cd4f3f
Merge branch 'master' into split_run_editor
andfoy May 9, 2022
958fbf6
Deregister run configurations from the Editor
andfoy May 9, 2022
17800e9
Merge branch 'split_run_editor' of https://github.com/andfoy/spyder i…
andfoy May 9, 2022
8e89657
Make sure combobox follows the focused run configuration
andfoy May 10, 2022
ceffc24
Ensure executors combo box is updated correctly
andfoy May 16, 2022
ddd57c7
Load stored parameters from configuration
andfoy May 18, 2022
53a909f
Add combobox and checkbox to create new run configurations
andfoy May 23, 2022
1f3b28f
Decouple run parameters from files
andfoy May 24, 2022
7165efa
Per-executor configuration parameters are now being saved and loaded
andfoy May 26, 2022
6b4a065
Run is now working with files
andfoy May 27, 2022
0c1e651
Move external console options to a separate executor
andfoy May 30, 2022
7274b74
Add support for bash files
andfoy May 31, 2022
42996dc
Save last used parameters per file
andfoy Jun 1, 2022
4f1a388
Fix parameter initialization in dialog
andfoy Jun 1, 2022
48ac435
Add selection action
andfoy Jun 3, 2022
4e4077d
Add support for cells and script selection
andfoy Jun 4, 2022
a1ed3c7
Add support for cells and advance
andfoy Jun 7, 2022
53b8ca2
Merge branch 'master' into split_run_editor
andfoy Jun 7, 2022
cad2038
Try to override shortcuts
andfoy Jun 7, 2022
79a485b
Add run to/from line actions
andfoy Jun 7, 2022
978a59e
Add open configuration dialog action
andfoy Jun 8, 2022
35ab62f
Add re-run last file action
andfoy Jun 8, 2022
1c0d828
Add re-run cell option
andfoy Jun 9, 2022
23c7520
Migrate Profiler to use the new Run API
andfoy Jun 10, 2022
bfec106
Get around Python scope limitations
andfoy Jun 10, 2022
28a6e92
Move Pylint to use the new Run infraestructure
andfoy Jun 13, 2022
bb91bb0
Add teardown routines for Run methods and dependencies
andfoy Jun 13, 2022
b9f395b
Start re-working the Run configuration page
andfoy Jun 14, 2022
bba8245
Add configuration page edition dialog
andfoy Jun 15, 2022
22e2932
Configuration page is now working as expected
andfoy Jun 17, 2022
9069f26
Remove unwanted import
andfoy Jun 20, 2022
4761fca
Ensure powershell and cmd work as expected
andfoy Jun 20, 2022
c8401f3
Start fixing fast tests
andfoy Jun 20, 2022
748342d
Merge remote-tracking branch 'upstream/master' into split_run_editor
andfoy Jun 20, 2022
99da57b
Rename action to make it visible in macOS
steff456 Jun 20, 2022
3b5716b
Merge branch 'master' into split_run_editor
andfoy Jun 21, 2022
717d9c2
Fix mainwindow tests
andfoy Jun 21, 2022
8550e23
Merge with master
andfoy Jun 21, 2022
cbf6d4f
Add temporary run api to debug files
andfoy Jun 21, 2022
f3f413a
Fix cell copy options
andfoy Jun 21, 2022
edc8532
Fix a few more tests
andfoy Jun 21, 2022
01ac4df
Fix remaining tests
andfoy Jun 22, 2022
836626a
Merge branch 'master' into split_run_editor
andfoy Jun 23, 2022
b1e958f
Merge remote-tracking branch 'upstream/master' into split_run_editor
andfoy Jun 23, 2022
4a1339d
Fix test_connection_to_external_kernel
andfoy Jun 24, 2022
9b5dd10
Add external console test
andfoy Jun 27, 2022
17612ce
Fix shell test in Windows
andfoy Jun 27, 2022
4f5c406
Apply review comments
steff456 Jun 28, 2022
8a05705
Inherit RunExecutor from QObject in order to ensure MRO resolution
andfoy Jun 28, 2022
8fd758e
Add API versioning how-to
andfoy Jun 28, 2022
90951bc
Fix pep8 issues
steff456 Jun 29, 2022
f6a13f7
Merge branch 'master' into split_run_editor
andfoy Jun 29, 2022
54bdaff
Add comments to fix test on windows CI
steff456 Jun 30, 2022
41a08d9
Merge branch 'split_run_editor' of github.com:andfoy/spyder into spli…
steff456 Jun 30, 2022
a65c8a8
Fix failing test in frames
steff456 Jun 30, 2022
25ab1f3
Refactor run dialog to use async Qt API
andfoy Jul 1, 2022
0986382
Extend test to run an input in transient mode
andfoy Jul 2, 2022
a72dde9
Extend test to consider subordinate contexts
andfoy Jul 5, 2022
77b5422
Use Run button instead of shortcut on test_varexp_rename
andfoy Jul 5, 2022
5c68b36
Merge branch 'master' into split_run_editor
andfoy Jul 5, 2022
85eb1a4
Test teardown deregistration for Run
andfoy Jul 5, 2022
e059967
Try to prevent duplicate shortcuts
andfoy Jul 7, 2022
d223b4c
Group some run tests
andfoy Jul 11, 2022
cd7d70c
Skip test_runcell_edge_cases
andfoy Jul 11, 2022
4df2264
Skip test_runcell_pdb on Windows
andfoy Jul 11, 2022
c5b14e9
Fix typo
steff456 Jul 12, 2022
89e2d4d
Skip test_runcell_cache on Windows
andfoy Jul 12, 2022
fee8db9
Merge branch 'split_run_editor' of https://github.com/andfoy/spyder i…
andfoy Jul 12, 2022
10542d3
Skip test_runcell_after_restart on Windows
andfoy Jul 12, 2022
ffbf1e3
Move test_varexp_remove to call the Run button directly
andfoy Jul 12, 2022
d84f28a
Increase timeout on test_print_multiprocessing
andfoy Jul 13, 2022
48965d3
Fix issues with whitespaces when running shell files
andfoy Jul 13, 2022
45d5053
Retrieve run configurations for super contexts via get_run_configurat…
andfoy Jul 13, 2022
b64f181
Force editor to set focus appropiately in test_print_multiprocessing
andfoy Jul 13, 2022
3204b63
Add wait for test_print_faulthandler
andfoy Jul 13, 2022
7020323
Fix Run configuration page table issues
andfoy Jul 13, 2022
500887c
Display only the executors that have a configuration dialog
andfoy Jul 13, 2022
ebf2b63
Add wait time to refresh run file in test_debug_unsaved_function
andfoy Jul 14, 2022
646f321
Merge after releasing 5.3.3
ccordoba12 Feb 3, 2023
0e80241
Merge after releasing 5.4.0
ccordoba12 Feb 4, 2023
8ede54f
Merge after releasing 5.4.1
ccordoba12 Feb 5, 2023
1c156b7
Fix line endings of batch scripts
ccordoba12 Feb 5, 2023
0e07d4a
Merge branch 'master' into split_run_editor
ccordoba12 Feb 5, 2023
58525e3
Testing: Refactor code used to generate run parameters
ccordoba12 Feb 5, 2023
4d42430
Main Window: Remove attributes related to the Run menu and toolbar
ccordoba12 Feb 5, 2023
fd12df1
Testing: Fix most failing tests and skip others
ccordoba12 Feb 5, 2023
8215c66
Debugger: Fix debugging selections
ccordoba12 Feb 7, 2023
5304a54
Ignore revision that updated the new run architecture with master
ccordoba12 Feb 9, 2023
b4782dc
Merge branch 'master' into split_run_editor
ccordoba12 Feb 11, 2023
4068d25
Add some missing docstrings, fix style issues and other minor things
ccordoba12 Feb 11, 2023
5cf60eb
Testing: Skip test_shell_execution on Mac because it's failing
ccordoba12 Feb 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Finish typing stubs and Run API interfaces
  • Loading branch information
andfoy committed Mar 10, 2022
commit c103a554a480f99f196f61909867e5d0d50cf9f9
159 changes: 147 additions & 12 deletions spyder/plugins/run/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@
"""Spyder Run API."""

# Standard library imports
from __future__ import annotations

import sys
from enum import Enum
from typing import Tuple, Dict, TypedDict, Any
from datetime import datetime
from typing import Any, Set, List, Union, Optional

# PEP 589 and 544 are available from Python 3.8 onwards
if sys.version_info >= (3, 8):
from typing import TypedDict
from typing import TypedDict, Protocol
else:
from typing_extensions import TypedDict
from typing_extensions import TypedDict, Protocol

# Support PEP 655 (available from Python 3.11 onwards)
from typing_extensions import NotRequired


class RunActions:
Expand All @@ -41,32 +47,115 @@ def __getattribute__(self, key: str) -> str:


RunContext = RunContextType('context')
RunResultDisplay = RunContextType('result display')
RunResultFormat = RunContextType('result display format')
RunInputFormat = set({})

RunContext.File = 'file'
RunContext.Selection = 'selection'
RunContext.Cell = 'cell'

RunResultFormat.NoDisplay = 'no_display'


class RunInputMetadata(TypedDict):
"""Run input metadata schema."""
# Human-readable name for the run input.
name: str
# Source of the input provided.
source: str
# Timestamp of the run input information.
timestamp: datetime
# Extra metadata information.
extra: NotRequired[dict]


class RunInformation(TypedDict):
"""Type stubs for """
"""Run input information schema."""

# The context of the input provided. e.g., file, selection, cell, others.
# This attribute can be customized by the `RunInputProvider` when
# registering with the run plugin. The context can be compared against the
# values of `RunContext`. e.g., `info['context'] == RunContext.File`
context: str

# Input to process by the executor. The executor is responsible of the
# The output format to produce after executing the input. Each entry on the
# set must belong to the `RunResultFormat` dict. The executor is responsible
# of producing the correct format. This field will be available on a
# RunExecutorProvider but it is not necessary for a RunInputProvider to
# include it.
output_formats: NotRequired[Set[str]]

# Input to process by the executor. The executor is responsible for the
# correct interpretation of the input type.
run_input: Any

# File extension or identifier of the input context
# Run input metadata information.
metadata: RunInputMetadata

# File extension or identifier of the input context. It must belong to the
# `RunInputFormat` set.
input_extension: str


class RunExecutionMetadata(TypedDict):
"""Run result metadata schema."""

# Human readable identifier for the run executor.
executor: str
# Start timestamp of the run execution.
start_timestamp: datetime
# End timestamp of the run execution.
end_timestamp: datetime
# Extra execution metadata. This field can be used to store
# resource consumption, statistics and other fields that might be relevant.
extra: NotRequired[dict]


class RunResultError(TypedDict):
# Error code for the current error.
code: Optional[int]
# Human-readable message that describes the error.
message: Optional[str]


class RunResult(TypedDict):
"""Run result entry schema."""

# The output format for the current run result. It must belong to the
# `RunResultDisplay` dict.
output_format: str

# The output of the run result. The viewer is responsible for the current
# interpretation of the output type.
run_output: Union[Any, RunResultError]

# File extension or identifier of the input context. It must belong to the
# `RunInputFormat` set.
input_extension: str

# Original run input metadata.
metadata: RunInputMetadata

# Execution metadata.
execution_metadata: RunExecutionMetadata

# True if the execution result yielded an error, False otherwise. If the
# execution failed, then the `run_output` field will comply with the
# `RunResultError` schema.
is_error: bool

class RunResults(TypedDict):
pass

class SupportedRunConfiguration(TypedDict):
"""Run configuration entry schema."""

# File extension or identifier of the input context. It must belong to the
# `RunInputFormat` set.
input_extension: str

# The supported contexts for the given input extension. e.g., file, selection, cell, others.
# The context can be compared against the values of `RunContext`. e.g.,
# `info['context'] == RunContext.File`
contexts: List[str]


class RunInputProvider:
Expand Down Expand Up @@ -102,7 +191,53 @@ class RunExecutorProvider:
Interface used to execute run context information.

This API needs to be implemented by any plugin that wants to execute
an input produced by a :class:`RunInputProvider`.
an input produced by a :class:`RunInputProvider` to produce an output
compatible by a :class:`RunResultViewer`
"""

def run_input(self, input: RunInformation) -> :
def exec_run_input(self, input: RunInformation) -> List[RunResult]:
"""
Execute a run input.

Arguments
---------
input: RunInformation
A dictionary containing the information required to execute the
run input.

Returns
-------
results: List[RunResult]
A list of `RunResult` dictionary entries, one per each `run_output`
format requested by the input. Each entry must comply with the
format requested.

Notes
-----
This function must not crash or raise an exception, instead the
`RunResult` must wrap a `RunResultError` structure.
"""
raise NotImplementedError(f'{type(self)} must implement exec_run_input')


class RunResultViewer:
"""
Interface used to display run execution results.

This API needs to be implemented by any plugin that wants to display
an output produced by a :class:`RunResultViewer`.
"""

def display_run_result(self, result: RunResult):
"""
Display the output of a run execution.

Arguments
---------
result: RunResult
A `RunResult` entry that contains the run execution information,
including both input and execution metadata, as well as the result
representation in a format that the `RunResultViewer` instance
supports.
"""
raise NotImplementedError(f'{type(self)} must implement display_run_result')