Skip to content

Commit

Permalink
Merge pull request #245 from Jaseci-Labs/recursive_imports
Browse files Browse the repository at this point in the history
Recursive imports
  • Loading branch information
marsninja authored Apr 28, 2022
2 parents 68c26cf + fe74096 commit 9c4b0b3
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 11 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ repos:
- id: check-yaml
args: [--allow-multiple-documents]
- id: check-json
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.3.0
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Updates

- Improvement: import now works recursively through chain of files
- Improvement: JSCTL shows token on login
- Major Feature: JSCTL has persistent log in sessions, and can logout
- Improvement: `*` and `&` precedence hierarch locations improved.
Expand Down
1 change: 0 additions & 1 deletion jaseci_core/fileiotest.txt

This file was deleted.

11 changes: 11 additions & 0 deletions jaseci_core/jaseci/actions/standard/file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Built in actions for Jaseci"""
from jaseci.actions.live_actions import jaseci_action
import os
import json


Expand Down Expand Up @@ -40,3 +41,13 @@ def dump_json(fn: str, obj, indent: int = None):
"""Standard built in for dumping json to file from dictionary"""
with open(fn, "w") as file:
json.dump(obj, file, indent=indent)


@jaseci_action()
def delete(fn: str):
"""Standard built in for deleting a file"""
if os.path.exists(fn):
os.remove(fn)
return True
else:
return False
1 change: 1 addition & 0 deletions jaseci_core/jaseci/actions/tests/std_test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
file.append_str(fn, c);
c=file.load_str(fn);
report c;
file.delete(fn);
}
"""

Expand Down
2 changes: 1 addition & 1 deletion jaseci_core/jaseci/jac/interpreter/sentinel_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class sentinel_interp(interp):

def run_start(self, jac_ast):
"""
start: ver_label? element+ EOF;
start: ver_label? element* EOF;
"""
kid = self.set_cur_ast(jac_ast)
if kid[0].name == "ver_label":
Expand Down
17 changes: 13 additions & 4 deletions jaseci_core/jaseci/jac/ir/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
self._start_rule = start_rule
self.mod_name = mod_name if mod_name is not None else "@default"
self._mod_dir = mod_dir
self._keep = False
self.line = 0
self.column = 0
self.kid = []
Expand Down Expand Up @@ -159,9 +160,12 @@ def run_import_module(self, jac_ast):
filter(lambda x: x.name == "element", parsed_ast.kid)
)
if kid[2].name == "STAR_MUL":
return import_elements
ret = import_elements
else:
return self.run_import_items(kid[2], import_elements)
ret = self.run_import_items(kid[2], import_elements)
for i in ret:
i._keep = True
return ret
else:
return []

Expand All @@ -176,13 +180,17 @@ def run_import_items(self, jac_ast, import_elements):
"""
kid = jac_ast.kid
ret_elements = list(
filter(lambda x: x.kid[0].kid[0].name == kid[0].name, import_elements)
filter(
lambda x: x._keep or x.kid[0].kid[0].name == kid[0].name,
import_elements,
)
)
if kid[1].name == "import_names":
import_names = self.run_import_names(kid[1])
ret_elements = list(
filter(
lambda x: x.kid[0].kid[1].token_text() in import_names,
lambda x: x._keep
or x.kid[0].kid[1].token_text() in import_names,
ret_elements,
)
)
Expand All @@ -192,6 +200,7 @@ def run_import_items(self, jac_ast, import_elements):
+ "Module name not found!"
)
self.tree_root._parse_errors.append(err)

if kid[-1].name == "import_items":
return ret_elements + self.run_import_items(kid[-1], import_elements)

Expand Down
6 changes: 6 additions & 0 deletions jaseci_core/jaseci/jsctl/tests/base5.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {walker::gen} with 'indirect1.jac';

walker init {
spawn here walker::gen;
report -->[0].details['name'];
}
5 changes: 5 additions & 0 deletions jaseci_core/jaseci/jsctl/tests/indirect1.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {node::plain} with 'indirect2.jac';

walker gen {
spawn here --> node::plain;
}
1 change: 1 addition & 0 deletions jaseci_core/jaseci/jsctl/tests/indirect2.jac
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node plain;
9 changes: 9 additions & 0 deletions jaseci_core/jaseci/jsctl/tests/test_jsctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ def test_jsctl_import_globals(self):
r = self.call_cast("walker run init")
self.assertEqual(len(r["report"]), 8)

def test_jsctl_import_recursive(self):
self.call(
"sentinel register "
"jaseci/jsctl/tests/base5.jac -code_dir jaseci/jsctl/tests/ "
"-set_active true"
)
r = self.call_cast("walker run init")
self.assertEqual(r["report"][0], "plain")

def test_jsctl_run_tests(self):
self.call("sentinel register " "jaseci/jsctl/tests/teststest.jac")
r = self.call_split("sentinel test")
Expand Down
2 changes: 1 addition & 1 deletion jaseci_core/jaseci/jsctl/tests/teststest.jir

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jaseci_core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="jaseci",
version="1.3.3.14",
version="1.3.3.15",
packages=find_packages(include=["jaseci", "jaseci.*"]),
install_requires=[
"click>=8.1.0,<8.2.0",
Expand Down
2 changes: 1 addition & 1 deletion jaseci_kit/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="jaseci_kit",
version="1.3.3.14",
version="1.3.3.15",
packages=find_packages(include=["jaseci_kit", "jaseci_kit.*"]),
install_requires=[
"jaseci",
Expand Down
2 changes: 1 addition & 1 deletion jaseci_serv/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="jaseci_serv",
version="1.3.3.14",
version="1.3.3.15",
packages=find_packages(include=["jaseci_serv", "jaseci_serv.*"]),
install_requires=[
"jaseci",
Expand Down

0 comments on commit 9c4b0b3

Please sign in to comment.