diff --git a/jaclang/cli/cli.py b/jaclang/cli/cli.py index f2e63ccfe..a932be1af 100644 --- a/jaclang/cli/cli.py +++ b/jaclang/cli/cli.py @@ -100,19 +100,24 @@ def run( base_path=base, cachable=cache, override_name="__main__" if main else None, + is_origin=True, ) + if ret_module is None: loaded_mod = None else: (loaded_mod,) = ret_module elif filename.endswith(".jir"): with open(filename, "rb") as f: + JacMachine(base).attach_program( + JacProgram(mod_bundle=pickle.load(f), bytecode=None) + ) ret_module = jac_import( target=mod, base_path=base, cachable=cache, override_name="__main__" if main else None, - jac_program=JacProgram(mod_bundle=pickle.load(f), bytecode=None), + is_origin=True, ) if ret_module is None: loaded_mod = None @@ -233,7 +238,7 @@ def enter( base, mod_name = os.path.split(filename) base = base if base else "./" mod_name = mod_name[:-4] - (mod,) = jac_import(target=mod_name, base_path=base) + (mod,) = jac_import(target=mod_name, base_path=base, is_origin=True) if not mod: print("Errors occurred while importing the module.") else: @@ -386,7 +391,7 @@ def dot( if filename.endswith(".jac"): jac_machine = JacMachine(base) - jac_import(target=mod, base_path=base, jac_machine=jac_machine) + jac_import(target=mod, base_path=base, is_origin=True) module = jac_machine.loaded_modules.get(mod) globals().update(vars(module)) try: diff --git a/jaclang/compiler/tests/test_importer.py b/jaclang/compiler/tests/test_importer.py index 410af5f15..c7b630647 100644 --- a/jaclang/compiler/tests/test_importer.py +++ b/jaclang/compiler/tests/test_importer.py @@ -14,13 +14,13 @@ class TestLoader(TestCase): def test_import_basic_python(self) -> None: """Test basic self loading.""" - (h,) = jac_import("fixtures.hello_world", base_path=__file__) + (h,) = jac_import("fixtures.hello_world", base_path=__file__, is_origin=True) self.assertEqual(h.hello(), "Hello World!") # type: ignore def test_modules_correct(self) -> None: """Test basic self loading.""" jac_machine = JacMachine(__file__) - jac_import("fixtures.hello_world", base_path=__file__, jac_machine=jac_machine) + jac_import("fixtures.hello_world", base_path=__file__, is_origin=True) self.assertIn( "module 'fixtures.hello_world'", str(jac_machine.loaded_modules), diff --git a/jaclang/plugin/default.py b/jaclang/plugin/default.py index b4bc98c1c..c657e8d9f 100644 --- a/jaclang/plugin/default.py +++ b/jaclang/plugin/default.py @@ -79,6 +79,12 @@ def get_datasource() -> Memory: """Get current execution context.""" return ExecutionContext.get().datasource + @staticmethod + @hookimpl + def get_machine(base_path: str) -> JacMachine: + """Get current execution context.""" + return JacMachine.get(base_path) + @staticmethod @hookimpl def make_architype( @@ -238,8 +244,7 @@ def jac_import( lng: Optional[str], items: Optional[dict[str, Union[str, Optional[str]]]], reload_module: Optional[bool], - jac_machine: Optional[JacMachine], - jac_program: Optional[JacProgram], + is_origin: bool, ) -> tuple[types.ModuleType, ...]: """Core Import Process.""" spec = ImportPathSpec( @@ -252,14 +257,19 @@ def jac_import( lng, items, ) - jac_machine = jac_machine or JacMachine(base_path) - jac_machine.attach_program( - jac_program or JacProgram(mod_bundle=None, bytecode=None) - ) + + jac_machine = JacMachine.get(base_path) + if not jac_machine.jac_program: + jac_machine.attach_program(JacProgram(mod_bundle=None, bytecode=None)) + if lng == "py": import_result = PythonImporter(jac_machine).run_import(spec) else: import_result = JacImporter(jac_machine).run_import(spec, reload_module) + + if is_origin: + JacMachine.detach() + return ( (import_result.ret_mod,) if absorb or not items diff --git a/jaclang/plugin/feature.py b/jaclang/plugin/feature.py index c0a4b858a..9aea8125d 100644 --- a/jaclang/plugin/feature.py +++ b/jaclang/plugin/feature.py @@ -19,7 +19,7 @@ WalkerArchitype, ) from jaclang.runtimelib.context import ExecutionContext -from jaclang.runtimelib.machine import JacMachine, JacProgram +from jaclang.runtimelib.machine import JacMachine import pluggy @@ -53,6 +53,11 @@ def get_datasource() -> Memory: """Get current execution context.""" return pm.hook.get_datasource() + @staticmethod + def get_machine(base_path: str = "") -> JacMachine: + """Get current jac machine.""" + return pm.hook.get_machine(base_path=base_path) + @staticmethod def make_architype( cls: type, @@ -111,8 +116,7 @@ def jac_import( lng: Optional[str] = "jac", items: Optional[dict[str, Union[str, Optional[str]]]] = None, reload_module: Optional[bool] = False, - jac_machine: Optional[JacMachine] = None, - jac_program: Optional[JacProgram] = None, + is_origin: bool = False, ) -> tuple[types.ModuleType, ...]: """Core Import Process.""" return pm.hook.jac_import( @@ -125,8 +129,7 @@ def jac_import( lng=lng, items=items, reload_module=reload_module, - jac_machine=jac_machine, - jac_program=jac_program, + is_origin=is_origin, ) @staticmethod diff --git a/jaclang/plugin/spec.py b/jaclang/plugin/spec.py index 0edb2d710..2e7fbfcf2 100644 --- a/jaclang/plugin/spec.py +++ b/jaclang/plugin/spec.py @@ -30,7 +30,7 @@ ) from jaclang.runtimelib.constructs import EdgeArchitype, NodeAnchor, NodeArchitype from jaclang.runtimelib.context import ExecutionContext - from jaclang.runtimelib.machine import JacMachine, JacProgram + from jaclang.runtimelib.machine import JacMachine from jaclang.runtimelib.memory import Memory import pluggy @@ -56,6 +56,12 @@ def get_datasource() -> Memory: """Get current execution context datasource.""" raise NotImplementedError + @staticmethod + @hookspec(firstresult=True) + def get_machine(base_path: str) -> JacMachine: + """Get current jac machine.""" + raise NotImplementedError + @staticmethod @hookspec(firstresult=True) def make_architype( @@ -119,8 +125,7 @@ def jac_import( lng: Optional[str], items: Optional[dict[str, Union[str, Optional[str]]]], reload_module: Optional[bool], - jac_machine: Optional[JacMachine], - jac_program: Optional[JacProgram], + is_origin: bool, ) -> tuple[types.ModuleType, ...]: """Core Import Process.""" raise NotImplementedError diff --git a/jaclang/runtimelib/machine.py b/jaclang/runtimelib/machine.py index 9f6070654..e1d90873d 100644 --- a/jaclang/runtimelib/machine.py +++ b/jaclang/runtimelib/machine.py @@ -5,6 +5,7 @@ import os import sys import types +from contextvars import ContextVar from typing import Optional from jaclang.compiler.absyntree import Module @@ -17,6 +18,9 @@ logger = logging.getLogger(__name__) +JACMACHINE_CONTEXT = ContextVar["JacMachine | None"]("JacMachine") + + class JacMachine: """JacMachine to handle the VM-related functionalities and loaded programs.""" @@ -33,6 +37,8 @@ def __init__(self, base_path: str = "") -> None: ) self.jac_program: Optional[JacProgram] = None + JACMACHINE_CONTEXT.set(self) + def attach_program(self, jac_program: "JacProgram") -> None: """Attach a JacProgram to the machine.""" self.jac_program = jac_program @@ -99,6 +105,18 @@ def list_edges(self, module_name: str) -> list[str]: return nodes return [] + @staticmethod + def get(base_path: str = "") -> "JacMachine": + """Get current jac machine.""" + if (jac_machine := JACMACHINE_CONTEXT.get(None)) is None: + jac_machine = JacMachine(base_path) + return jac_machine + + @staticmethod + def detach() -> None: + """Detach current jac machine.""" + JACMACHINE_CONTEXT.set(None) + class JacProgram: """Class to hold the mod_bundle and bytecode for Jac modules.""" diff --git a/jaclang/tests/fixtures/foo.jac b/jaclang/tests/fixtures/foo.jac index c98576529..4f288f844 100644 --- a/jaclang/tests/fixtures/foo.jac +++ b/jaclang/tests/fixtures/foo.jac @@ -5,13 +5,13 @@ import:jac from bar, bar_walk; # Test runner to initialize the walker can test_run { # Print the loaded modules - modules = Jac.context().jac_machine.list_modules(); + modules = Jac.get_machine().list_modules(); "Loaded Modules:" |> print; for mod_name in modules { f"Module: {mod_name}" |> print; } # Print walkers - walkers = Jac.context().jac_machine.list_walkers(mod_name); + walkers = Jac.get_machine().list_walkers(mod_name); if walkers{ f"Walkers in {mod_name}:" |> print; for walker in walkers{ @@ -20,7 +20,7 @@ can test_run { } # Print nodes - nodes = Jac.context().jac_machine.list_nodes(mod_name); + nodes = Jac.get_machine().list_nodes(mod_name); if nodes{ f"Nodes in {mod_name}:" |> print; for node in nodes{ @@ -28,7 +28,7 @@ can test_run { } } # Print edges - edges = Jac.context().jac_machine.list_edges(mod_name); + edges = Jac.get_machine().list_edges(mod_name); if edges{ f"Edges in {mod_name}:" |> print; for edge in edges{ diff --git a/jaclang/tests/test_language.py b/jaclang/tests/test_language.py index 33eee04d9..dab43a90d 100644 --- a/jaclang/tests/test_language.py +++ b/jaclang/tests/test_language.py @@ -63,7 +63,9 @@ def test_simple_jac_red(self) -> None: """Parse micro jac file.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("micro.simple_walk", base_path=self.examples_abs_path("")) + jac_import( + "micro.simple_walk", base_path=self.examples_abs_path(""), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual( @@ -76,7 +78,7 @@ def test_guess_game(self) -> None: """Parse micro jac file.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("guess_game", base_path=self.fixture_abs_path("./")) + jac_import("guess_game", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual( @@ -88,7 +90,9 @@ def test_chandra_bugs(self) -> None: """Parse micro jac file.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("chandra_bugs", base_path=self.fixture_abs_path("./")) + jac_import( + "chandra_bugs", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual( @@ -100,7 +104,9 @@ def test_chandra_bugs2(self) -> None: """Parse micro jac file.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("chandra_bugs2", base_path=self.fixture_abs_path("./")) + jac_import( + "chandra_bugs2", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual( @@ -115,7 +121,7 @@ def test_ignore(self) -> None: """Parse micro jac file.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("ignore_dup", base_path=self.fixture_abs_path("./")) + jac_import("ignore_dup", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual(stdout_value.split("\n")[0].count("here"), 10) @@ -125,7 +131,9 @@ def test_dataclass_hasability(self) -> None: """Parse micro jac file.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("hashcheck_dup", base_path=self.fixture_abs_path("./")) + jac_import( + "hashcheck_dup", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual(stdout_value.count("check"), 2) @@ -144,7 +152,9 @@ def test_need_import(self) -> None: """Test importing python.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("needs_import", base_path=self.fixture_abs_path("./")) + jac_import( + "needs_import", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn(" None: """Test the dot gen of nodes and edges of bubblesort.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("gendot_bubble_sort", base_path=self.fixture_abs_path("./")) + jac_import( + "gendot_bubble_sort", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn( @@ -177,7 +189,9 @@ def test_assign_compr(self) -> None: """Test assign_compr.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("assign_compr_dup", base_path=self.fixture_abs_path("./")) + jac_import( + "assign_compr_dup", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual( @@ -189,7 +203,7 @@ def test_semstr(self) -> None: """Test semstring.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("semstr", base_path=self.fixture_abs_path("./")) + jac_import("semstr", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertNotIn("Error", stdout_value) @@ -198,7 +212,9 @@ def test_raw_bytestr(self) -> None: """Test raw string and byte string.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("raw_byte_string", base_path=self.fixture_abs_path("./")) + jac_import( + "raw_byte_string", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual(stdout_value.count(r"\\\\"), 2) @@ -209,7 +225,7 @@ def test_deep_imports(self) -> None: captured_output = io.StringIO() sys.stdout = captured_output - jac_import("deep_import", base_path=self.fixture_abs_path("./")) + jac_import("deep_import", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual(stdout_value.split("\n")[0], "one level deeperslHello World!") @@ -228,9 +244,7 @@ def test_deep_imports_mods(self) -> None: del sys.modules[i] jac_machine = JacMachine(self.fixture_abs_path("./")) jac_import( - "deep_import_mods", - base_path=self.fixture_abs_path("./"), - jac_machine=jac_machine, + "deep_import_mods", base_path=self.fixture_abs_path("./"), is_origin=True ) mods = jac_machine.loaded_modules.keys() for i in targets: @@ -242,7 +256,9 @@ def test_deep_outer_imports_one(self) -> None: captured_output = io.StringIO() sys.stdout = captured_output jac_import( - "deep.deeper.deep_outer_import", base_path=self.fixture_abs_path("./") + "deep.deeper.deep_outer_import", + base_path=self.fixture_abs_path("./"), + is_origin=True, ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() @@ -276,7 +292,9 @@ def test_has_lambda_goodness(self) -> None: """Test has lambda_goodness.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("has_goodness", base_path=self.fixture_abs_path("./")) + jac_import( + "has_goodness", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual(stdout_value.split("\n")[0], "mylist: [1, 2, 3]") @@ -286,7 +304,7 @@ def test_conn_assign_on_edges(self) -> None: """Test conn assign on edges.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("edge_ops", base_path=self.fixture_abs_path("./")) + jac_import("edge_ops", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("[(3, 5), (14, 1), (5, 1)]", stdout_value) @@ -297,7 +315,7 @@ def test_disconnect(self) -> None: """Test conn assign on edges.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("disconn", base_path=self.fixture_abs_path("./")) + jac_import("disconn", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue().split("\n") self.assertIn("c(cc=0)", stdout_value[0]) @@ -314,7 +332,9 @@ def test_simple_archs(self) -> None: """Test conn assign on edges.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("simple_archs", base_path=self.fixture_abs_path("./")) + jac_import( + "simple_archs", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual(stdout_value.split("\n")[0], "1 2 0") @@ -324,7 +344,7 @@ def test_edge_walk(self) -> None: """Test walking through edges.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("edges_walk", base_path=self.fixture_abs_path("./")) + jac_import("edges_walk", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("creator()\n", stdout_value) @@ -337,7 +357,7 @@ def test_impl_grab(self) -> None: """Test walking through edges.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("impl_grab", base_path=self.fixture_abs_path("./")) + jac_import("impl_grab", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("1.414", stdout_value) @@ -346,7 +366,7 @@ def test_tuple_of_tuple_assign(self) -> None: """Test walking through edges.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("tuplytuples", base_path=self.fixture_abs_path("./")) + jac_import("tuplytuples", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn( @@ -358,7 +378,9 @@ def test_deferred_field(self) -> None: """Test walking through edges.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("deferred_field", base_path=self.fixture_abs_path("./")) + jac_import( + "deferred_field", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn( @@ -370,7 +392,9 @@ def test_gen_dot_builtin(self) -> None: """Test the dot gen of nodes and edges as a builtin.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("builtin_dotgen", base_path=self.fixture_abs_path("./")) + jac_import( + "builtin_dotgen", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual(stdout_value.count("True"), 14) @@ -379,7 +403,9 @@ def test_with_contexts(self) -> None: """Test walking through edges.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("with_context", base_path=self.fixture_abs_path("./")) + jac_import( + "with_context", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("im in", stdout_value) @@ -397,6 +423,7 @@ def test_typed_filter_compr(self) -> None: jac_import( "micro.typed_filter_compr", base_path=self.examples_abs_path(""), + is_origin=True, ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() @@ -411,7 +438,9 @@ def test_edge_node_walk(self) -> None: """Test walking through edges and nodes.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("edge_node_walk", base_path=self.fixture_abs_path("./")) + jac_import( + "edge_node_walk", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("creator()\n", stdout_value) @@ -430,7 +459,7 @@ def test_impl_decl_resolution_fix(self) -> None: """Test walking through edges and nodes.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("mtest", base_path=self.fixture_abs_path("./")) + jac_import("mtest", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("2.0\n", stdout_value) @@ -439,7 +468,7 @@ def test_registry(self) -> None: """Test Jac registry feature.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("registry", base_path=self.fixture_abs_path("./")) + jac_import("registry", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertNotIn("Error", stdout_value) @@ -462,7 +491,11 @@ def test_enum_inside_arch(self) -> None: """Test Enum as member stmt.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("enum_inside_archtype", base_path=self.fixture_abs_path("./")) + jac_import( + "enum_inside_archtype", + base_path=self.fixture_abs_path("./"), + is_origin=True, + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual("2\n", stdout_value) @@ -489,7 +522,9 @@ def test_needs_import_1(self) -> None: self.assertEqual(len(ir.get_all_sub_nodes(ast.Architype)), 7) captured_output = io.StringIO() sys.stdout = captured_output - jac_import("needs_import_1", base_path=self.fixture_abs_path("./")) + jac_import( + "needs_import_1", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("pyfunc_1 imported", stdout_value) @@ -549,7 +584,9 @@ def test_needs_import_2(self) -> None: ) # Because of the Architype from math captured_output = io.StringIO() sys.stdout = captured_output - jac_import("needs_import_2", base_path=self.fixture_abs_path("./")) + jac_import( + "needs_import_2", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("pyfunc_2 imported", stdout_value) @@ -597,7 +634,9 @@ def test_needs_import_3(self) -> None: ) # Because of the Architype from other imports captured_output = io.StringIO() sys.stdout = captured_output - jac_import("needs_import_3", base_path=self.fixture_abs_path("./")) + jac_import( + "needs_import_3", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("pyfunc_3 imported", stdout_value) @@ -662,7 +701,9 @@ def test_inherit_check(self) -> None: """Test py ast to Jac ast conversion output.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("inherit_check", base_path=self.fixture_abs_path("./")) + jac_import( + "inherit_check", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual("I am in b\nI am in b\nwww is also in b\n", stdout_value) @@ -671,7 +712,7 @@ def test_tuple_unpack(self) -> None: """Test tuple unpack.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("tupleunpack", base_path=self.fixture_abs_path("./")) + jac_import("tupleunpack", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue().split("\n") self.assertIn("1", stdout_value[0]) @@ -681,7 +722,7 @@ def test_try_finally(self) -> None: """Test try finally.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("try_finally", base_path=self.fixture_abs_path("./")) + jac_import("try_finally", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue().split("\n") self.assertIn("try block", stdout_value[0]) @@ -694,7 +735,9 @@ def test_arithmetic_bug(self) -> None: """Test arithmetic bug.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("arithmetic_bug", base_path=self.fixture_abs_path("./")) + jac_import( + "arithmetic_bug", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue().split("\n") self.assertEqual("0.0625", stdout_value[0]) @@ -707,7 +750,7 @@ def test_lambda_expr(self) -> None: """Test lambda expr.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("lambda", base_path=self.fixture_abs_path("./")) + jac_import("lambda", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue().split("\n") self.assertEqual("9", stdout_value[0]) @@ -786,7 +829,9 @@ def test_deep_convert(self) -> None: self.assertEqual(len(ir.get_all_sub_nodes(ast.SubNodeList)), 269) captured_output = io.StringIO() sys.stdout = captured_output - jac_import("deep_convert", base_path=self.fixture_abs_path("./")) + jac_import( + "deep_convert", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("Deep convo is imported", stdout_value) @@ -795,7 +840,9 @@ def test_override_walker_inherit(self) -> None: """Test py ast to Jac ast conversion output.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("walker_override", base_path=self.fixture_abs_path("./")) + jac_import( + "walker_override", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual("baz\nbar\n", stdout_value) @@ -831,7 +878,7 @@ def test_self_with_no_sig(self) -> None: # we can get rid of this, isn't? """Test py ast to Jac ast conversion output.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("nosigself", base_path=self.fixture_abs_path("./")) + jac_import("nosigself", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual(stdout_value.count("5"), 2) @@ -840,7 +887,9 @@ def test_hash_init_check(self) -> None: # we can get rid of this, isn't? """Test py ast to Jac ast conversion output.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("hash_init_check", base_path=self.fixture_abs_path("./")) + jac_import( + "hash_init_check", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("Test Passed", stdout_value) @@ -889,7 +938,9 @@ def test_edge_expr_not_type(self) -> None: """Test importing python.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("edgetypeissue", base_path=self.fixture_abs_path("./")) + jac_import( + "edgetypeissue", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("[x()]", stdout_value) @@ -898,7 +949,9 @@ def test_blank_with_entry(self) -> None: """Test importing python.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("blankwithentry", base_path=self.fixture_abs_path("./")) + jac_import( + "blankwithentry", base_path=self.fixture_abs_path("./"), is_origin=True + ) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertIn("i work", stdout_value) @@ -907,7 +960,7 @@ def test_double_import_exec(self) -> None: """Test importing python.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("dblhello", base_path=self.fixture_abs_path("./")) + jac_import("dblhello", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue() self.assertEqual(stdout_value.count("Hello World!"), 1) @@ -917,7 +970,7 @@ def test_cls_method(self) -> None: """Test class method output.""" captured_output = io.StringIO() sys.stdout = captured_output - jac_import("cls_method", base_path=self.fixture_abs_path("./")) + jac_import("cls_method", base_path=self.fixture_abs_path("./"), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue().split("\n") self.assertEqual("MyClass", stdout_value[0]) @@ -929,7 +982,7 @@ def test_list_methods(self) -> None: captured_output = io.StringIO() sys.stdout = captured_output - jac_import("foo", base_path=self.fixture_abs_path(".")) + jac_import("foo", base_path=self.fixture_abs_path("."), is_origin=True) sys.stdout = sys.__stdout__ stdout_value = captured_output.getvalue()