Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #68 from webscopeio/fix/treeExitCode
Browse files Browse the repository at this point in the history
Fix/tree exit code
  • Loading branch information
jvorcak authored Jan 21, 2020
2 parents ab20eb3 + 25abde7 commit d525d61
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
7 changes: 5 additions & 2 deletions license_sh/commands/run_license_sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ def run_license_sh(arguments):
dep_tree, license_map = runner.check()
ignored_packages = ignored_packages_map[ProjectType.YARN.value]

filtered_dep_tree, licenses_not_found = get_dependency_tree_with_licenses(
(
filtered_dep_tree,
licenses_not_found,
has_issues,
) = get_dependency_tree_with_licenses(
dep_tree, whitelist, ignored_packages=ignored_packages, get_full_tree=tree
)

Expand Down Expand Up @@ -98,5 +102,4 @@ def run_license_sh(arguments):
get_full_tree=tree,
)

has_issues: bool = filtered_dep_tree.height > 0
exit(1 if has_issues else 0)
15 changes: 9 additions & 6 deletions license_sh/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Tuple, Set, List

from anytree import PreOrderIter, LevelOrderIter, AnyNode
from anytree.exporter import DictExporter
from anytree.importer import DictImporter
from license_expression import Licensing

try:
Expand Down Expand Up @@ -180,13 +182,14 @@ def filter_dep_tree(tree: AnyNode) -> AnyNode:
Returns:
AnyNode -- Filtered tree
"""
for node in LevelOrderIter(tree):
treeCopy = DictImporter().import_(DictExporter().export(tree))
for node in LevelOrderIter(treeCopy):
node.children = filter(
lambda subnode: subnode.subtree_problem or subnode.license_problem,
node.children,
)

return tree
return treeCopy


def get_dependency_tree_with_licenses(
Expand All @@ -206,7 +209,7 @@ def get_dependency_tree_with_licenses(
annotated_dep_tree, unknown_licenses = annotate_dep_tree(
dep_tree, whitelist=whitelist, ignored_packages=ignored_packages
)
filtered_dependency_tree = (
annotated_dep_tree if get_full_tree else filter_dep_tree(annotated_dep_tree)
)
return filtered_dependency_tree, unknown_licenses
filtered_dependency_tree = filter_dep_tree(annotated_dep_tree)
has_issues = filtered_dependency_tree.height > 0
dependency_tree = annotated_dep_tree if get_full_tree else filtered_dependency_tree
return dependency_tree, unknown_licenses, has_issues
2 changes: 1 addition & 1 deletion license_sh/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.14"
__version__ = "1.0.15"

0 comments on commit d525d61

Please sign in to comment.