PyCG 0.0.4__tar.gz → 0.0.5__tar.gz

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.
Files changed (68) hide show
  1. pycg-0.0.5/LICENCE +201 -0
  2. pycg-0.0.5/PKG-INFO +151 -0
  3. {pycg-0.0.4 → pycg-0.0.5}/pycg/formats/fasten.py +45 -18
  4. {pycg-0.0.4 → pycg-0.0.5}/pycg/machinery/definitions.py +10 -3
  5. {pycg-0.0.4 → pycg-0.0.5}/pycg/processing/base.py +5 -4
  6. pycg-0.0.5/pycg.egg-info/PKG-INFO +151 -0
  7. {pycg-0.0.4 → pycg-0.0.5}/pycg.egg-info/SOURCES.txt +1 -6
  8. {pycg-0.0.4 → pycg-0.0.5}/setup.py +1 -1
  9. pycg-0.0.4/PKG-INFO +0 -148
  10. pycg-0.0.4/micro-benchmark-key-errs/assignments_test.py +0 -16
  11. pycg-0.0.4/micro-benchmark-key-errs/classes_test.py +0 -25
  12. pycg-0.0.4/micro-benchmark-key-errs/dicts_test.py +0 -34
  13. pycg-0.0.4/micro-benchmark-key-errs/kwargs_test.py +0 -13
  14. pycg-0.0.4/micro-benchmark-key-errs/lists_test.py +0 -13
  15. pycg-0.0.4/micro-benchmark-key-errs/parameters_test.py +0 -16
  16. pycg-0.0.4/pycg.egg-info/PKG-INFO +0 -148
  17. {pycg-0.0.4 → pycg-0.0.5}/README.md +0 -0
  18. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/__init__.py +0 -0
  19. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/args_test.py +0 -0
  20. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/assignments_test.py +0 -0
  21. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/base.py +0 -0
  22. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/builtins_test.py +0 -0
  23. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/classes_test.py +0 -0
  24. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/create_pytests.py +0 -0
  25. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/decorators_test.py +0 -0
  26. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/dicts_test.py +0 -0
  27. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/direct_calls_test.py +0 -0
  28. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/dynamic_test.py +0 -0
  29. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/exceptions_test.py +0 -0
  30. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/external_test.py +0 -0
  31. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/functions_test.py +0 -0
  32. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/generators_test.py +0 -0
  33. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/imports_test.py +0 -0
  34. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/kwargs_test.py +0 -0
  35. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/lambdas_test.py +0 -0
  36. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/lists_test.py +0 -0
  37. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/mro_test.py +0 -0
  38. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark/returns_test.py +0 -0
  39. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark-key-errs/__init__.py +0 -0
  40. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark-key-errs/base.py +0 -0
  41. {pycg-0.0.4 → pycg-0.0.5}/micro-benchmark-key-errs/create_pytests.py +0 -0
  42. {pycg-0.0.4 → pycg-0.0.5}/pycg/__init__.py +0 -0
  43. {pycg-0.0.4 → pycg-0.0.5}/pycg/__main__.py +0 -0
  44. {pycg-0.0.4 → pycg-0.0.5}/pycg/formats/__init__.py +0 -0
  45. {pycg-0.0.4 → pycg-0.0.5}/pycg/formats/as_graph.py +0 -0
  46. {pycg-0.0.4 → pycg-0.0.5}/pycg/formats/base.py +0 -0
  47. {pycg-0.0.4 → pycg-0.0.5}/pycg/formats/simple.py +0 -0
  48. {pycg-0.0.4 → pycg-0.0.5}/pycg/machinery/__init__.py +0 -0
  49. {pycg-0.0.4 → pycg-0.0.5}/pycg/machinery/callgraph.py +0 -0
  50. {pycg-0.0.4 → pycg-0.0.5}/pycg/machinery/classes.py +0 -0
  51. {pycg-0.0.4 → pycg-0.0.5}/pycg/machinery/imports.py +0 -0
  52. {pycg-0.0.4 → pycg-0.0.5}/pycg/machinery/key_err.py +0 -0
  53. {pycg-0.0.4 → pycg-0.0.5}/pycg/machinery/modules.py +0 -0
  54. {pycg-0.0.4 → pycg-0.0.5}/pycg/machinery/pointers.py +0 -0
  55. {pycg-0.0.4 → pycg-0.0.5}/pycg/machinery/scopes.py +0 -0
  56. {pycg-0.0.4 → pycg-0.0.5}/pycg/processing/__init__.py +0 -0
  57. {pycg-0.0.4 → pycg-0.0.5}/pycg/processing/cgprocessor.py +0 -0
  58. {pycg-0.0.4 → pycg-0.0.5}/pycg/processing/keyerrprocessor.py +0 -0
  59. {pycg-0.0.4 → pycg-0.0.5}/pycg/processing/postprocessor.py +0 -0
  60. {pycg-0.0.4 → pycg-0.0.5}/pycg/processing/preprocessor.py +0 -0
  61. {pycg-0.0.4 → pycg-0.0.5}/pycg/pycg.py +0 -0
  62. {pycg-0.0.4 → pycg-0.0.5}/pycg/utils/__init__.py +0 -0
  63. {pycg-0.0.4 → pycg-0.0.5}/pycg/utils/common.py +0 -0
  64. {pycg-0.0.4 → pycg-0.0.5}/pycg/utils/constants.py +0 -0
  65. {pycg-0.0.4 → pycg-0.0.5}/pycg.egg-info/dependency_links.txt +0 -0
  66. {pycg-0.0.4 → pycg-0.0.5}/pycg.egg-info/entry_points.txt +0 -0
  67. {pycg-0.0.4 → pycg-0.0.5}/pycg.egg-info/top_level.txt +0 -0
  68. {pycg-0.0.4 → pycg-0.0.5}/setup.cfg +0 -0
pycg-0.0.5/LICENCE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
pycg-0.0.5/PKG-INFO ADDED
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.1
2
+ Name: pycg
3
+ Version: 0.0.5
4
+ Summary: Practical Python Call Graphs
5
+ Home-page: https://github.com/vitsalis/pycg
6
+ Author: Vitalis Salis
7
+ Author-email: vitsalis@gmail.com
8
+ License: Apache Software License
9
+ Platform: UNKNOWN
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENCE
14
+
15
+ # PyCG - Practical Python Call Graphs
16
+
17
+ PyCG generates call graphs for Python code using static analysis.
18
+ It efficiently supports
19
+ * Higher order functions
20
+ * Twisted class inheritance schemes
21
+ * Automatic discovery of imported modules for further analysis
22
+ * Nested definitions
23
+
24
+ You can read the full methodology as well as a complete evaluation on the
25
+ [ICSE 2021 paper](https://vitsalis.com/papers/pycg.pdf).
26
+
27
+ You can cite PyCG as follows.
28
+ Vitalis Salis, Thodoris Sotiropoulos, Panos Louridas, Diomidis Spinellis and Dimitris Mitropoulos.
29
+ PyCG: Practical Call Graph Generation in Python.
30
+ In _43rd International Conference on Software Engineering, ICSE '21_,
31
+ 25–28 May 2021.
32
+
33
+ # Installation
34
+
35
+ PyCG is implemented in Python3 and has no dependencies. Simply:
36
+ ```
37
+ pip install pycg
38
+ ```
39
+
40
+ # Usage
41
+
42
+ ```
43
+ ~ >>> pycg -h
44
+ usage: __main__.py [-h] [--package PACKAGE] [--fasten] [--product PRODUCT]
45
+ [--forge FORGE] [--version VERSION] [--timestamp TIMESTAMP]
46
+ [--max-iter MAX_ITER] [--operation {call-graph,key-error}]
47
+ [--as-graph-output AS_GRAPH_OUTPUT] [-o OUTPUT]
48
+ [entry_point ...]
49
+
50
+ positional arguments:
51
+ entry_point Entry points to be processed
52
+
53
+ optional arguments:
54
+ -h, --help show this help message and exit
55
+ --package PACKAGE Package containing the code to be analyzed
56
+ --fasten Produce call graph using the FASTEN format
57
+ --product PRODUCT Package name
58
+ --forge FORGE Source the product was downloaded from
59
+ --version VERSION Version of the product
60
+ --timestamp TIMESTAMP
61
+ Timestamp of the package's version
62
+ --max-iter MAX_ITER Maximum number of iterations through source code. If not specified a fix-point iteration will be performed.
63
+ --operation {call-graph,key-error}
64
+ Operation to perform. Choose call-graph for call graph generation (default) or key-error for key error detection on dictionaries.
65
+ --as-graph-output AS_GRAPH_OUTPUT
66
+ Output for the assignment graph
67
+ -o OUTPUT, --output OUTPUT
68
+ Output path
69
+ ```
70
+
71
+ The following command line arguments should used only when `--fasten` is
72
+ provied:
73
+
74
+ - `--product`: The name of the package.
75
+ - `--forge`: Source the package was downloaded from.
76
+ - `--version`: The version of the package.
77
+ - `--timestamp` : The timestamp of the package's version.
78
+
79
+ # Call Graph Output
80
+
81
+ ## Simple JSON format
82
+
83
+ The call edges are in the form of an adjacency list where an edge `(src, dst)`
84
+ is represented as an entry of `dst` in the list assigned to key `src`:
85
+
86
+ ```
87
+ {
88
+ "node1": ["node2", "node3"],
89
+ "node2": ["node3"],
90
+ "node3": []
91
+ }
92
+ ```
93
+
94
+ ## FASTEN Format
95
+
96
+ For an up-to-date description of the FASTEN format refer to the
97
+ [FASTEN
98
+ wiki](https://github.com/fasten-project/fasten/wiki/Extended-Revision-Call-Graph-format#python).
99
+
100
+ # Key Errors Output
101
+
102
+ We are currently experimenting on identifying potential invalid dictionary
103
+ accesses on Python dictionaries (key errors).
104
+ The output format for key errors is a list of dictionaries containing:
105
+ - The file name in which the key error was identified
106
+ - The line number inside the file
107
+ - The namespace of the accessed dictionary
108
+ - The key used to access the dictionary
109
+
110
+ ```
111
+ [{
112
+ "filename": "mod.py",
113
+ "lineno": 2,
114
+ "namespace": "mod.<dict1>",
115
+ "key": "key2"
116
+ },
117
+ {
118
+ "filename": "mod.py",
119
+ "lineno": 8,
120
+ "namespace": "mod.<dict1>",
121
+ "key": "nokey"
122
+ }]
123
+ ```
124
+
125
+ # Examples
126
+
127
+ All the entry points are known and we want the simple JSON format
128
+ ```
129
+ ~ >>> pycg --package pkg_root pkg_root/module1.py pkg_root/subpackage/module2.py -o cg.json
130
+ ```
131
+
132
+ All entry points are not known and we want the simple JSON format
133
+ ```
134
+ ~ >>> pycg --package django $(find django -type f -name "*.py") -o django.json
135
+ ```
136
+
137
+ We want the FASTEN format:
138
+ ```
139
+ ~ >>> pycg --package pypi_pkg --fasten --product "pypipkg" --forge "PyPI" \
140
+ --version "0.1" --timestamp 42 \
141
+ pypi_pkg/module1.py pkg_root/subpackage/module2.py -o cg.json
142
+ ```
143
+
144
+ # Running Tests
145
+
146
+ From the root directory:
147
+ ```
148
+ make test
149
+ ```
150
+
151
+
@@ -153,7 +153,7 @@ class Fasten(BaseFormatter):
153
153
 
154
154
  return res
155
155
 
156
- def get_modules(self):
156
+ def get_internal_modules(self):
157
157
  mods = {}
158
158
 
159
159
  for modname, module in self.internal_mods.items():
@@ -174,28 +174,27 @@ class Fasten(BaseFormatter):
174
174
  namespace=namespace_uri,
175
175
  metadata=dict(first=info['first'], last=info['last']))
176
176
  self.namespace_map[namespace_uri] = unique
177
+ mods = self.add_superclasses(mods)
177
178
 
178
179
  return mods
179
180
 
180
- def class_hiearchy(self):
181
- hierarchy = {}
181
+ def add_superclasses(self, mods):
182
182
  for cls_name, cls in self.classes.items():
183
183
  cls_uri = self.namespace_map.get(self.to_uri(cls["module"], cls_name))
184
- hierarchy[cls_uri] = []
184
+ mods[self.to_uri(cls["module"])]["namespaces"][cls_uri]["metadata"]["superClasses"] = []
185
185
  for parent in cls["mro"]:
186
186
  if parent == cls_name:
187
187
  continue
188
188
 
189
189
  if self.classes.get(parent):
190
190
  parent_uri = self.to_uri(self.classes[parent]["module"], parent)
191
- parent_uri = self.namespace_map.get(parent_uri, parent_uri)
192
191
  else:
193
192
  parent_mod = parent.split(".")[0]
194
193
  parent_uri = self.to_external_uri(parent_mod, parent)
195
194
 
196
- hierarchy[cls_uri].append(parent_uri)
195
+ mods[self.to_uri(cls["module"])]["namespaces"][cls_uri]["metadata"]["superClasses"].append(parent_uri)
197
196
 
198
- return hierarchy
197
+ return mods
199
198
 
200
199
  def create_namespaces_map(self):
201
200
  namespaces_maps = [{}, {}]
@@ -206,10 +205,34 @@ class Fasten(BaseFormatter):
206
205
 
207
206
  return namespaces_maps
208
207
 
208
+ def get_external_modules(self):
209
+ mods = {}
210
+ for modname, module in self.external_mods.items():
211
+ name = self.to_external_uri(modname).split("/")[2]
212
+ namespaces = module["methods"]
213
+
214
+ mods[name] = {
215
+ "sourceFile": "",
216
+ "namespaces": {}
217
+ }
218
+
219
+ for namespace, info in namespaces.items():
220
+ # We avoid saving the external module as external method
221
+ if info['name'] != modname:
222
+ namespace_uri = self.to_external_uri(modname, info['name'])
223
+
224
+ unique = self.get_unique_and_increment()
225
+ mods[name]["namespaces"][str(unique)] = dict(
226
+ namespace=namespace_uri,
227
+ metadata={})
228
+ self.namespace_map[namespace_uri] = unique
229
+ return mods
230
+
209
231
  def get_graph(self):
210
232
  graph = {
211
233
  "internalCalls": [],
212
- "externalCalls": []
234
+ "externalCalls": [],
235
+ "resolvedCalls": []
213
236
  }
214
237
 
215
238
  internal, external = self.create_namespaces_map()
@@ -223,19 +246,20 @@ class Fasten(BaseFormatter):
223
246
  uris.append(self.namespace_map.get(uri, uri))
224
247
  elif node in external:
225
248
  mod = external[node]
226
- uris.append(self.to_external_uri(mod, node))
249
+ uris.append(self.namespace_map.get(self.to_external_uri(mod, node)))
227
250
 
228
251
  if len(uris) == 2:
229
- # internal uris have been converted to ints
230
- if type(uris[1]) == str and uris[1].startswith("//"):
252
+ if dst in external:
231
253
  graph["externalCalls"].append([
232
- uris[0],
233
- uris[1]
254
+ str(uris[0]),
255
+ str(uris[1]),
256
+ {}
234
257
  ])
235
258
  else:
236
259
  graph["internalCalls"].append([
237
- uris[0],
238
- uris[1]
260
+ str(uris[0]),
261
+ str(uris[1]),
262
+ {}
239
263
  ])
240
264
  return graph
241
265
 
@@ -247,7 +271,10 @@ class Fasten(BaseFormatter):
247
271
  "depset": self.find_dependencies(self.package),
248
272
  "version": self.version,
249
273
  "timestamp": self.timestamp,
250
- "modules": self.get_modules(),
251
- "cha": self.class_hiearchy(),
252
- "graph": self.get_graph()
274
+ "modules": {
275
+ "internal": self.get_internal_modules(),
276
+ "external": self.get_external_modules()
277
+ },
278
+ "graph": self.get_graph(),
279
+ "nodes": self.get_unique_and_increment()
253
280
  }
@@ -111,13 +111,15 @@ class DefinitionManager(object):
111
111
  def complete_definitions(self):
112
112
  # THE MOST expensive part of this tool's process
113
113
  # TODO: IMPROVE COMPLEXITY
114
- def update_pointsto_args(pointsto_args, arg):
114
+ def update_pointsto_args(pointsto_args, arg, name):
115
115
  changed_something = False
116
116
  if arg == pointsto_args:
117
117
  return False
118
118
  for pointsto_arg in pointsto_args:
119
119
  if not self.defs.get(pointsto_arg, None):
120
120
  continue
121
+ if pointsto_arg == name:
122
+ continue
121
123
  pointsto_arg_def = self.defs[pointsto_arg].get_name_pointer()
122
124
  if pointsto_arg_def == pointsto_args:
123
125
  continue
@@ -146,10 +148,15 @@ class DefinitionManager(object):
146
148
  # the name pointer of the definition we're currently iterating
147
149
  current_name_pointer = current_def.get_name_pointer()
148
150
  # iterate the names the current definition points to items
149
- for name in current_name_pointer.get():
151
+ # for name in current_name_pointer.get():
152
+ for name in current_name_pointer.get().copy():
153
+
150
154
  # get the name pointer of the points to name
151
155
  if not self.defs.get(name, None):
152
156
  continue
157
+ if name == ns:
158
+ continue
159
+
153
160
  pointsto_name_pointer = self.defs[name].get_name_pointer()
154
161
  # iterate the arguments of the definition we're currently iterating
155
162
  for arg_name, arg in current_name_pointer.get_args().items():
@@ -164,7 +171,7 @@ class DefinitionManager(object):
164
171
  if not pointsto_args:
165
172
  pointsto_name_pointer.add_arg(arg_name, arg)
166
173
  continue
167
- changed_something = changed_something or update_pointsto_args(pointsto_args, arg)
174
+ changed_something = changed_something or update_pointsto_args(pointsto_args, arg, current_def.get_ns())
168
175
 
169
176
  if not changed_something:
170
177
  break
@@ -65,9 +65,10 @@ class ProcessingBase(ast.NodeVisitor):
65
65
  def visit_FunctionDef(self, node):
66
66
  self.name_stack.append(node.name)
67
67
  self.method_stack.append(node.name)
68
- self.scope_manager.get_scope(self.current_ns).reset_counters()
69
- for stmt in node.body:
70
- self.visit(stmt)
68
+ if self.scope_manager.get_scope(self.current_ns):
69
+ self.scope_manager.get_scope(self.current_ns).reset_counters()
70
+ for stmt in node.body:
71
+ self.visit(stmt)
71
72
  self.method_stack.pop()
72
73
  self.name_stack.pop()
73
74
 
@@ -181,7 +182,7 @@ class ProcessingBase(ast.NodeVisitor):
181
182
  self.visit(target)
182
183
  if isinstance(target, ast.Tuple):
183
184
  for pos, elt in enumerate(target.elts):
184
- if pos < len(decoded):
185
+ if not isinstance(decoded, Definition) and pos < len(decoded):
185
186
  do_assign(decoded[pos], elt)
186
187
  else:
187
188
  targetns = self._get_target_ns(target)