Skip to content

Commit 2bd6adf

Browse files
scottrogowskiScott
andauthored
December fixes (scottrogowski#35)
* improve dependency robustness. Fix Python import bug. Small text improvements * include acorn dependency * add acorn package * add python test for relative paths * fix eof newlines Co-authored-by: Scott <scott@Scotts-MacBook-Pro.local>
1 parent bded7b4 commit 2bd6adf

20 files changed

Lines changed: 1278 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ pip3 install code2flow
3131

3232
If you don't have it already, you will also need to install graphviz. Installation instructions can be found [here](https://graphviz.org/download/).
3333

34+
Additionally, depending on the language you want to parse, you may need to install additional dependencies:
35+
- Javascript: [Acorn](https://www.npmjs.com/package/acorn)
36+
- Ruby: [Parser](https://github.com/whitequark/parser)
37+
- PHP: [PHP-Parser](https://github.com/nikic/PHP-Parser)
38+
- Python: No extra dependencies needed
39+
3440
Usage
3541
-----
3642

@@ -142,6 +148,15 @@ Unrelated projects
142148
The name, "code2flow", has been used for several unrelated projects. Specifically, the domain, code2flow.com, has no association with this project. I've never heard anything from them and it doesn't appear like they use anything from here.
143149

144150

151+
Unit tests
152+
------------------
153+
154+
Test coverage is 100%. To run:
155+
156+
pip install -r requirements_dev.txt
157+
make test
158+
159+
145160
Feedback / Contact
146161
-----------------------------
147162

‎code2flow/engine.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def make_file_group(tree, filename, extension):
197197
token = os.path.split(filename)[-1].rsplit('.' + extension, 1)[0]
198198
line_number = 0
199199
display_name = 'File'
200-
import_tokens = []
200+
import_tokens = language.file_import_tokens(filename)
201201

202202
file_group = Group(token, group_type, display_name, import_tokens,
203203
line_number, parent=None)

‎code2flow/javascript.py‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,13 @@ def get_acorn_version():
234234
Get the version of installed acorn
235235
:rtype: str
236236
"""
237-
outp = subprocess.check_output(['node', '-p', 'require(\'acorn/package.json\').version'])
238-
return outp.decode().strip()
237+
proc = subprocess.Popen(['node', '-p', 'require(\'acorn/package.json\').version'],
238+
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
239+
cwd=os.path.dirname(os.path.realpath(__file__)))
240+
assert proc.wait() == 0, "Acorn is required to parse javascript files. " \
241+
"It was found on the path but could not be imported " \
242+
"in node.\n" + proc.stderr.read().decode()
243+
return proc.stdout.read().decode().strip()
239244

240245

241246
class Javascript(BaseLanguage):
@@ -398,3 +403,13 @@ def make_class_group(tree, parent):
398403
class_group.add_node(new_node)
399404

400405
return class_group
406+
407+
@staticmethod
408+
def file_import_tokens(filename):
409+
"""
410+
Returns the token(s) we would use if importing this file from another.
411+
412+
:param filename str:
413+
:rtype: list[str]
414+
"""
415+
return []

‎code2flow/node_modules/.bin/acorn‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎code2flow/node_modules/.package-lock.json‎

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)