Skip to content

Commit

Permalink
Clean up IPython dependencies (#19)
Browse files Browse the repository at this point in the history
Some IPython dependencies were unnecesary. This commit removes them,
simplifying the code.
  • Loading branch information
GlassOfWhiskey authored May 27, 2023
1 parent b69b476 commit 94c5b5d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion jupyter_workflow/ipython/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import os
import shutil
import sys
from tempfile import TemporaryDirectory

from IPython.utils.tempdir import TemporaryDirectory
from jupyter_client.kernelspec import KernelSpecManager

kernel_json = {
Expand Down
6 changes: 0 additions & 6 deletions jupyter_workflow/ipython/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
from jupyter_workflow.config.validator import validate
from jupyter_workflow.ipython.shell import StreamFlowInteractiveShell

try:
# noinspection PyProtectedMember
from IPython.core.interactiveshell import _asyncio_runner
except ImportError:
_asyncio_runner = None


class WorkflowIPythonKernel(IPythonKernel):
# Set StreamFlow shell
Expand Down
5 changes: 2 additions & 3 deletions jupyter_workflow/ipython/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from io import FileIO, TextIOWrapper
from typing import Any, List, MutableMapping, Tuple, cast

import IPython
import streamflow.log_handler
from IPython.core.error import InputRejected
from IPython.core.interactiveshell import ExecutionResult, softspace
Expand Down Expand Up @@ -48,11 +47,11 @@

def _classify_nodes(nodelist, interactivity):
if interactivity == "last_expr_or_assign":
if isinstance(nodelist[-1], IPython.core.interactiveshell._assign_nodes):
if isinstance(nodelist[-1], (ast.AugAssign, ast.AnnAssign, ast.Assign)):
asg = nodelist[-1]
if isinstance(asg, ast.Assign) and len(asg.targets) == 1:
target = asg.targets[0]
elif isinstance(asg, IPython.core.interactiveshell._single_targets_nodes):
elif isinstance(asg, (ast.AugAssign, ast.AnnAssign)):
target = asg.target
else:
target = None
Expand Down
6 changes: 3 additions & 3 deletions jupyter_workflow/streamflow/command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ast
import asyncio
import codeop
import json
import os
import tempfile
Expand All @@ -8,7 +9,6 @@
from typing import Any, List, MutableMapping, Optional, Tuple

import cloudpickle as pickle
from IPython.core.compilerop import CachingCompiler
from streamflow.core.deployment import LOCAL_LOCATION, Location
from streamflow.core.utils import random_name
from streamflow.core.workflow import Command, CommandOutput, Job, Status, Step
Expand Down Expand Up @@ -43,7 +43,7 @@ def __init__(
self,
step: Step,
ast_nodes: List[Tuple[ast.AST, str]],
compiler: CachingCompiler,
compiler: codeop.Compile,
interpreter: str,
input_tokens: MutableMapping[str, JupyterCommandToken],
output_tokens: MutableMapping[str, JupyterCommandToken],
Expand All @@ -54,7 +54,7 @@ def __init__(
):
super().__init__(step)
self.ast_nodes: List[Tuple[ast.AST, str]] = ast_nodes
self.compiler: CachingCompiler = compiler
self.compiler: codeop.Compile = compiler
self.interpreter: str = interpreter
self.input_tokens: MutableMapping[str, JupyterCommandToken] = input_tokens
self.output_tokens: MutableMapping[str, JupyterCommandToken] = output_tokens
Expand Down
12 changes: 5 additions & 7 deletions jupyter_workflow/streamflow/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import ast
import asyncio
import codeop
import json
import sys
from abc import ABC, abstractmethod
from typing import Any, MutableMapping, Type, cast
from typing import Any, MutableMapping, cast

import cloudpickle as pickle
from IPython.core.compilerop import CachingCompiler
from IPython.core.interactiveshell import softspace
from streamflow.core.context import StreamFlowContext
from streamflow.core.exception import (
Expand Down Expand Up @@ -217,13 +217,13 @@ def __init__(
workflow: Workflow,
ast_nodes: list[tuple[ast.AST, str]],
autoawait: bool,
compiler: CachingCompiler,
compiler: codeop.Compile,
context_port: ProgramContextPort,
):
super().__init__(name, workflow)
self.ast_nodes: list[tuple[ast.AST, str]] = ast_nodes
self.autoawait: bool = autoawait
self.compiler: CachingCompiler = compiler
self.compiler: codeop.Compile = compiler
self.output_processors: MutableMapping[str, CommandOutputProcessor] = {}
self.add_input_port("__context__", context_port)
self.add_output_port(
Expand All @@ -243,9 +243,7 @@ async def _load(
workflow=await loading_context.load_workflow(context, row["workflow"]),
ast_nodes=pickle.loads(params["ast_nodes"]),
autoawait=params["autoawait"],
compiler=cast(
Type[CachingCompiler], get_class_from_name(params["compiler"])
)(),
compiler=get_class_from_name(params["compiler"])(),
context_port=cast(
ProgramContextPort,
await loading_context.load_port(context, params["context_port"]),
Expand Down
12 changes: 6 additions & 6 deletions jupyter_workflow/streamflow/translator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import ast
import codeop
import hashlib
import json
import os
Expand All @@ -11,7 +12,6 @@
MutableSequence,
)

from IPython.core.compilerop import CachingCompiler
from IPython.utils.text import DollarFormatter
from streamflow.core import utils
from streamflow.core.config import BindingConfig
Expand Down Expand Up @@ -125,7 +125,7 @@ def _build_target(


def _extract_dependencies(
cell_name: str, compiler: CachingCompiler, ast_nodes: list[tuple[ast.AST, str]]
cell_name: str, compiler: codeop.Compile, ast_nodes: list[tuple[ast.AST, str]]
) -> MutableSequence[str]:
visitor = DependenciesRetriever(cell_name, compiler)
for node, _ in ast_nodes:
Expand Down Expand Up @@ -206,10 +206,10 @@ def __contains__(self, name: str) -> bool:


class DependenciesRetriever(ast.NodeVisitor):
def __init__(self, cell_name: str, compiler: CachingCompiler):
def __init__(self, cell_name: str, compiler: codeop.Compile):
super().__init__()
self.cell_name: str = cell_name
self.compiler: CachingCompiler = compiler
self.compiler: codeop.Compile = compiler
self.deps: set[str] = set()
self.names: NamesStack = NamesStack()

Expand Down Expand Up @@ -348,12 +348,12 @@ def __init__(
self,
name: str,
code: list[tuple[ast.AST, str]],
compiler: CachingCompiler,
compiler: codeop.Compile,
metadata: MutableMapping[str, Any] | None = None,
):
self.name: str = name
self.code: list[tuple[ast.AST, str]] = code
self.compiler: CachingCompiler = compiler
self.compiler: codeop.Compile = compiler
self.metadata: MutableMapping[str, Any] | None = metadata or {}


Expand Down

0 comments on commit 94c5b5d

Please sign in to comment.