Skip to content

Commit ee8e71e

Browse files
Windows (#25)
* possible fix for windows cli problem * small change on Makefile * small merge fix * will come back to remaining unit tests * final changes
1 parent a7b775a commit ee8e71e

File tree

14 files changed

+151
-93
lines changed

14 files changed

+151
-93
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Code2flow CHANGELOG
22

3+
## [2.1.1] - 2021-06-15
4+
Updates to the CLI that allow code2flow to hypothetically run in Windows
5+
36
## [2.1.0] - 2021-06-15
47
Javascript support
58

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test:
2-
pytest --cov-report=html --cov=lib -x
2+
pytest --cov-report=html --cov=code2flow
33

44
clean:
55
rm -rf build

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![code2flow logo](assets/code2flowlogo.png)
22

3-
![Version 2.1.0](https://img.shields.io/badge/version-2.1.0-brightgreen) ![Build passing](https://img.shields.io/badge/build-passing-brightgreen) ![Coverage 100%](https://img.shields.io/badge/coverage-100%25-brightgreen) ![License MIT](https://img.shields.io/badge/license-MIT-green])
3+
![Version 2.1.1](https://img.shields.io/badge/version-2.1.1-brightgreen) ![Build passing](https://img.shields.io/badge/build-passing-brightgreen) ![Coverage 99%](https://img.shields.io/badge/coverage-99%25-brightgreen) ![License MIT](https://img.shields.io/badge/license-MIT-green])
44

55
> #### Updates from May 2021
66
> - I've entered into a contract with a generous sponsor, the [Sider Corporation](https://siderlabs.com), to update code2flow.

c2f

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
from code2flow.engine import main
5+
6+
if __name__ == "__main__":
7+
main(sys.argv[1:])

code2flow

Lines changed: 0 additions & 75 deletions
This file was deleted.
File renamed without changes.

lib/engine.py renamed to code2flow/engine.py

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import argparse
12
import collections
23
import json
34
import logging
45
import os
56
import subprocess
7+
import sys
68
import time
79

810
from .python import Python
@@ -12,7 +14,7 @@
1214
from .model import (TRUNK_COLOR, LEAF_COLOR, EDGE_COLOR, NODE_COLOR, GROUP_TYPE,
1315
Edge, Group, Node, Variable, is_installed, flatten)
1416

15-
VERSION = '2.1.0'
17+
VERSION = '2.1.1'
1618

1719
VALID_EXTENSIONS = {'png', 'svg', 'dot', 'gv', 'json'}
1820

@@ -496,7 +498,6 @@ def code2flow(raw_source_paths, output_file, language=None, hide_legend=True,
496498
:param int level: logging level
497499
:rtype: None
498500
"""
499-
500501
start_time = time.time()
501502

502503
if not isinstance(raw_source_paths, list):
@@ -555,3 +556,84 @@ def code2flow(raw_source_paths, output_file, language=None, hide_legend=True,
555556
# translate to an image if that was requested
556557
if final_img_filename:
557558
_generate_final_img(output_file, extension, final_img_filename, len(edges))
559+
560+
561+
def main(sys_argv=None):
562+
"""
563+
CLI interface. Sys_argv is a parameter for the sake of unittest coverage.
564+
:param sys_argv list:
565+
:rtype: None
566+
"""
567+
parser = argparse.ArgumentParser(
568+
description=DESCRIPTION,
569+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
570+
parser.add_argument(
571+
'sources', metavar='sources', nargs='+',
572+
help='source code file/directory paths.')
573+
parser.add_argument(
574+
'--output', '-o', default='out.png',
575+
help=f'output file path. Supported types are {VALID_EXTENSIONS}.')
576+
parser.add_argument(
577+
'--language', choices=['py', 'js'],
578+
help='process this language and ignore all other files.'
579+
'If omitted, use the suffix of the first source file.')
580+
parser.add_argument(
581+
'--exclude-functions',
582+
help='exclude functions from the output. Comma delimited.')
583+
parser.add_argument(
584+
'--exclude-namespaces',
585+
help='exclude namespaces (Classes, modules, etc) from the output. Comma delimited.')
586+
parser.add_argument(
587+
'--no-grouping', action='store_true',
588+
help='instead of grouping functions into namespaces, let functions float.')
589+
parser.add_argument(
590+
'--no-trimming', action='store_true',
591+
help='show all functions/namespaces whether or not they connect to anything.')
592+
parser.add_argument(
593+
'--hide-legend', action='store_true',
594+
help='by default, Code2flow generates a small legend. This flag hides it.')
595+
parser.add_argument(
596+
'--skip-parse-errors', action='store_true',
597+
help='skip files that the language parser fails on.')
598+
parser.add_argument(
599+
'--source-type', choices=['script', 'module'], default='script',
600+
help='js only. Parse the source as scripts (commonJS) or modules (es6)')
601+
parser.add_argument(
602+
'--ruby-version', default='27',
603+
help='ruby only. Which ruby version to parse? This is passed directly into ruby-parse. Use numbers like 25, 27, or 31.')
604+
parser.add_argument(
605+
'--quiet', '-q', action='store_true',
606+
help='suppress most logging')
607+
parser.add_argument(
608+
'--verbose', '-v', action='store_true',
609+
help='add more logging')
610+
parser.add_argument(
611+
'--version', action='version', version='%(prog)s ' + VERSION)
612+
613+
sys_argv = sys_argv or sys.argv[1:]
614+
args = parser.parse_args(sys_argv)
615+
level = logging.INFO
616+
if args.verbose and args.quiet:
617+
raise AssertionError("Passed both --verbose and --quiet flags")
618+
if args.verbose:
619+
level = logging.DEBUG
620+
if args.quiet:
621+
level = logging.WARNING
622+
623+
exclude_namespaces = list(filter(None, (args.exclude_namespaces or "").split(',')))
624+
exclude_functions = list(filter(None, (args.exclude_functions or "").split(',')))
625+
lang_params = LanguageParams(args.source_type, args.ruby_version)
626+
627+
code2flow(
628+
raw_source_paths=args.sources,
629+
output_file=args.output,
630+
language=args.language,
631+
hide_legend=args.hide_legend,
632+
exclude_namespaces=exclude_namespaces,
633+
exclude_functions=exclude_functions,
634+
no_grouping=args.no_grouping,
635+
no_trimming=args.no_trimming,
636+
skip_parse_errors=args.skip_parse_errors,
637+
lang_params=lang_params,
638+
level=level,
639+
)
File renamed without changes.
File renamed without changes.

lib/model.py renamed to code2flow/model.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,13 @@ def token_with_ownership(self):
289289
def label(self):
290290
"""
291291
Labels are what you see on the graph
292+
293+
TODO ruby branch
292294
"""
293-
if self.line_number is not None:
294-
return f"{self.line_number}: {self.token}()"
295-
return f"{self.token}()"
295+
# if self.line_number is not None:
296+
assert self.line_number is not None
297+
return f"{self.line_number}: {self.token}()"
298+
# return f"{self.token}()"
296299

297300
def remove_from_parent(self):
298301
"""
@@ -511,9 +514,11 @@ def get_variables(self, line_number=None):
511514
variables = (self.root_node.variables
512515
+ _wrap_as_variables(self.subgroups)
513516
+ _wrap_as_variables(n for n in self.nodes if n != self.root_node))
514-
if any(v.line_number for v in variables):
515-
return sorted(variables, key=lambda v: v.line_number, reverse=True)
516-
return variables
517+
# TODO ruby branch
518+
assert any(v.line_number for v in variables)
519+
# if any(v.line_number for v in variables):
520+
return sorted(variables, key=lambda v: v.line_number, reverse=True)
521+
# return variables
517522
else:
518523
return []
519524

0 commit comments

Comments
 (0)