Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pycycle/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def cli(ctx, verbose=False, help=False, source=None, here=False, ignore='', enco

if check_if_cycles_exist(root_node):
click.echo(crayons.red('Cycle Found :('))
click.echo(crayons.red(get_cycle_path(root_node)))
click.echo(crayons.red(get_cycle_path(root_node, verbose=verbose)))
click.echo(crayons.green("Finished."))
sys.exit(1)
else:
Expand Down
9 changes: 7 additions & 2 deletions pycycle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ def format_path(path):
:param path:
:return: str
"""
if len(path) > 1:
if len(path) == 1:
# print the node path if it recursively import itself
return str(path[0].full_path)
elif len(path) > 1:
result = [crayons.yellow(path[0].name)]

previous = path[0]
Expand All @@ -231,8 +234,10 @@ def format_path(path):
return ''


def get_cycle_path(root, acc=[], seen=set()):
def get_cycle_path(root, acc=[], seen=set(), verbose=False):
for item in root:
if verbose:
click.echo(crayons.yellow('Checking root: {} item: {}'.format(root.name, item.full_path)))
if item.full_path in seen:
return format_path(acc)
seen.add(item.full_path)
Expand Down