pipescript 0.0.13__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pipescript/__init__.py ADDED
@@ -0,0 +1,97 @@
1
+ """
2
+ pipescript: powerful pipeline syntax for IPython and Jupyter.
3
+ Just run `%load_ext pipescript` to begin using pipe operators, placeholders, and more.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import sys
9
+ from typing import TYPE_CHECKING
10
+
11
+ import pipescript.api
12
+ from pipescript.api import * # noqa: F403
13
+ from pipescript.extension import (
14
+ clear_tracer_stacks,
15
+ identify_dynamic_macros,
16
+ load_builtin_dynamic_macros,
17
+ )
18
+ from pipescript.extension import load_ipython_extension as load_ipython_extension_base
19
+ from pipescript.extension import (
20
+ unload_ipython_extension as unload_ipython_extension_base,
21
+ )
22
+ from pipescript.patches.completion_patch import patch_completer, unpatch_completer
23
+ from pipescript.tracers.macro_tracer import MacroTracer
24
+ from pipescript.tracers.optional_chaining_tracer import OptionalChainingTracer
25
+ from pipescript.tracers.pipeline_tracer import PipelineTracer
26
+
27
+ from . import _version # noqa: E402
28
+
29
+ __version__ = _version.get_versions()["version"]
30
+
31
+ if TYPE_CHECKING:
32
+ from IPython.core.interactiveshell import InteractiveShell
33
+
34
+
35
+ def load_ipython_extension_ipyflow(shell: InteractiveShell) -> None:
36
+ from ipyflow.shell.interactiveshell import IPyflowInteractiveShell
37
+
38
+ assert isinstance(shell, IPyflowInteractiveShell)
39
+ shell.run_line_magic(
40
+ "flow", f"register {PipelineTracer.__module__}.{PipelineTracer.__name__}"
41
+ )
42
+ shell.run_line_magic(
43
+ "flow",
44
+ f"register {MacroTracer.__module__}.{MacroTracer.__name__}",
45
+ )
46
+ shell.run_line_magic(
47
+ "flow",
48
+ f"register {OptionalChainingTracer.__module__}.{OptionalChainingTracer.__name__}",
49
+ )
50
+ shell.events.register("post_run_cell", clear_tracer_stacks)
51
+ shell.events.register("post_run_cell", identify_dynamic_macros)
52
+ patch_completer(shell.Completer)
53
+ load_builtin_dynamic_macros(shell)
54
+
55
+
56
+ def unload_ipython_extension_ipyflow(shell: InteractiveShell) -> None:
57
+ unpatch_completer(shell.Completer)
58
+ shell.events.unregister("post_run_cell", identify_dynamic_macros)
59
+ shell.events.unregister("post_run_cell", clear_tracer_stacks)
60
+ shell.run_line_magic(
61
+ "flow",
62
+ f"deregister {OptionalChainingTracer.__module__}.{OptionalChainingTracer.__name__}",
63
+ )
64
+ shell.run_line_magic(
65
+ "flow",
66
+ f"deregister {MacroTracer.__module__}.{MacroTracer.__name__}",
67
+ )
68
+ shell.run_line_magic(
69
+ "flow", f"deregister {PipelineTracer.__module__}.{PipelineTracer.__name__}"
70
+ )
71
+
72
+
73
+ def load_ipython_extension(shell: InteractiveShell) -> None:
74
+ IPyflowInteractiveShell = getattr(
75
+ sys.modules.get("ipyflow.shell.interactiveshell"),
76
+ "IPyflowInteractiveShell",
77
+ type(None),
78
+ )
79
+ if isinstance(shell, IPyflowInteractiveShell):
80
+ load_ipython_extension_ipyflow(shell)
81
+ else:
82
+ load_ipython_extension_base(shell)
83
+
84
+
85
+ def unload_ipython_extension(shell: InteractiveShell) -> None:
86
+ IPyflowInteractiveShell = getattr(
87
+ sys.modules.get("ipyflow.shell.interactiveshell"),
88
+ "IPyflowInteractiveShell",
89
+ type(None),
90
+ )
91
+ if isinstance(shell, IPyflowInteractiveShell):
92
+ unload_ipython_extension_ipyflow(shell)
93
+ else:
94
+ unload_ipython_extension_base(shell)
95
+
96
+
97
+ __all__ = list(pipescript.api.__all__)
pipescript/__main__.py ADDED
@@ -0,0 +1,26 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import sys
5
+
6
+ import pyccolo as pyc
7
+ from pyccolo.__main__ import main as pyccolo_main
8
+
9
+ import pipescript.tracers
10
+
11
+
12
+ def main() -> int:
13
+ script_path = os.path.abspath(sys.argv[1])
14
+ tracer_refs = [
15
+ f"{pipescript.tracers.__name__}.{tracer_name}"
16
+ for tracer_name in pipescript.tracers.__all__
17
+ ]
18
+ for tracer_ref in tracer_refs:
19
+ tracer = pyc.resolve_tracer(tracer_ref).instance()
20
+ tracer._tracing_enabled_files.add(script_path)
21
+ sys.argv.extend(["-t"] + tracer_refs)
22
+ return pyccolo_main()
23
+
24
+
25
+ if __name__ == "__main__":
26
+ sys.exit(main())