Skip to content

Commit c70ee89

Browse files
authored
Merge pull request #422 from OEG-Clark/dev_clark
Data Flow Fix
2 parents 21da57d + 9c090f0 commit c70ee89

5 files changed

Lines changed: 40 additions & 5 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ Make sure you have tree-sitter installed, C complier is needed, more [info](http
7070
```
7171
pip install tree-sitter
7272
```
73+
Note that if the ".so" file is not working properly, it is recommended that run the following commeds to generate a so file for your OS:
74+
```
75+
git clone https://github.com/tree-sitter/tree-sitter-python
76+
77+
python inspect4py/build.py
78+
```
7379

7480
Make sure you have graphviz installed:
7581

inspect4py/build.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from tree_sitter import Language
2+
3+
Language.build_library(
4+
# Store the library in the `build` directory
5+
'my-languages.so',
6+
7+
# Include one or more languages
8+
[
9+
'tree-sitter-python'
10+
]
11+
)

inspect4py/cli.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,8 @@ def _f_definitions(self, functions_definitions):
595595
if self.source_code:
596596
funcs_info[f.name]["source_code"] = ast_to_source_code(f)
597597
if self.data_flow:
598-
code_tokens, dfg = extract_dataflow(funcs_info[f.name]["source_code"], self.parser, "python")
598+
temp_source_code = ast_to_source_code(f)
599+
code_tokens, dfg = extract_dataflow(temp_source_code, self.parser, "python")
599600
funcs_info[f.name]["data_flow"] = dfg
600601
funcs_info[f.name]["code_tokens"] = code_tokens
601602
return funcs_info
@@ -1263,6 +1264,8 @@ def main(input_path, output_dir, ignore_dir_pattern, ignore_file_pattern, requir
12631264
path_to_languages = str(Path(__file__).parent / "resources")
12641265
if sys.platform.startswith("win") or sys.platform.startswith("cygwin"):
12651266
language = Language(path_to_languages + os.path.sep + "python_win.so", "python")
1267+
elif sys.platform.startswith("darwin"):
1268+
language = Language(path_to_languages + os.path.sep + "python_mac.so", "python")
12661269
else:
12671270
language = Language(path_to_languages + os.path.sep + "python_unix.so", "python")
12681271
else:
@@ -1311,22 +1314,37 @@ def main(input_path, output_dir, ignore_dir_pattern, ignore_file_pattern, requir
13111314
except:
13121315
print("Readme not found at root level")
13131316
for subdir, dirs, files in os.walk(input_path):
1314-
1317+
# print(subdir, dirs, files)
13151318
for ignore_d in ignore_dir_pattern:
13161319
dirs[:] = [d for d in dirs if not d.startswith(ignore_d)]
13171320
for ignore_f in ignore_file_pattern:
13181321
files[:] = [f for f in files if not f.startswith(ignore_f)]
13191322
for f in files:
13201323
if ".py" in f and not f.endswith(".pyc"):
1324+
# path = os.path.join(subdir, f)
1325+
# # print(path)
1326+
# relative_path = Path(subdir).relative_to(Path(input_path).parent)
1327+
# out_dir = str(Path(output_dir) / relative_path)
1328+
# cf_dir, json_dir = create_output_dirs(out_dir, control_flow)
1329+
# code_info = CodeInspection(path, cf_dir, json_dir, control_flow, abstract_syntax_tree, source_code,
1330+
# data_flow, parser)
1331+
#
1332+
# if code_info.fileJson:
1333+
# print(code_info.fileJson[0])
1334+
# if out_dir not in dir_info:
1335+
# dir_info[out_dir] = [code_info.fileJson[0]]
1336+
# else:
1337+
# dir_info[out_dir].append(code_info.fileJson[0])
13211338
try:
1322-
13231339
path = os.path.join(subdir, f)
1340+
# print(path)
13241341
relative_path = Path(subdir).relative_to(Path(input_path).parent)
13251342
out_dir = str(Path(output_dir) / relative_path)
13261343
cf_dir, json_dir = create_output_dirs(out_dir, control_flow)
13271344
code_info = CodeInspection(path, cf_dir, json_dir, control_flow, abstract_syntax_tree, source_code, data_flow, parser)
1328-
# print(parsers)
1345+
13291346
if code_info.fileJson:
1347+
# print(code_info.fileJson[0])
13301348
if out_dir not in dir_info:
13311349
dir_info[out_dir] = [code_info.fileJson[0]]
13321350
else:

inspect4py/resources/python_mac.so

536 KB
Binary file not shown.

test/test_inspect4py.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def test_data_flow(self):
481481
output_dir = test_out_path + os.path.sep + "output_dir"
482482
control_flow = False
483483
abstract_syntax_tree = False
484-
source_code = True
484+
source_code = False
485485
data_flow = True
486486
path_to_languages = str(Path(__file__).parent.parent / "inspect4py" / "resources")
487487
if sys.platform.startswith("win") or sys.platform.startswith("cygwin"):

0 commit comments

Comments
 (0)