Repository: webscopeio/license.sh

Issue:
Ignore packages
One should be able to ignore packages.

Lets say test is not able to resolve certain license. However, I am able to find online its license and confirm that it is ok for my scenario. I should be able to add it to config file to prevent further fails.

```
ignore: [
'package-utils@1.0.0',
'random@1.2.3'
]
```

Discussion:

Patch:
diff --git a/.license-sh.json b/.license-sh.json
index 75baf49..50cf58d 100644
--- a/.license-sh.json
+++ b/.license-sh.json
@@ -8,4 +8,4 @@
   "whitelist": [
     "MIT"
   ]
-}
+}
\ No newline at end of file
diff --git a/license-sh b/license-sh
index 018cb99..91d162c 100755
--- a/license-sh
+++ b/license-sh
@@ -44,10 +44,10 @@ except ImportError:
 
 
 def print_dependency_tree_with_licenses(
-    dep_tree: AnyNode, whitelist: List[str]
+    dep_tree: AnyNode, whitelist: List[str], ignored_packages: List[str]
 ) -> Tuple[AnyNode, Set[str]]:
     annotated_dep_tree, unknown_licenses = annotate_dep_tree(
-        dep_tree, whitelist=whitelist
+        dep_tree, whitelist=whitelist, ignored_packages=ignored_packages
     )
     filtered_dependency_tree = (
         annotated_dep_tree if tree else filter_dep_tree(annotated_dep_tree)
@@ -66,6 +66,13 @@ if __name__ == "__main__":
     debug = arguments["--debug"]
 
     config = get_config(path)
+
+    # TODO test this data transformation
+    config_ignored_packages = config.get("ignored_packages", {})
+    ignored_packages_map = {
+        e.value: config_ignored_packages.get(e.value, {}) for e in ProjectType
+    }
+
     WHITELIST += config.get("whitelist", [])
 
     if config_mode:
@@ -85,21 +92,25 @@ if __name__ == "__main__":
     if ProjectType.PYTHON_PIPENV in project_types:
         runner = PythonRunner(path, silent, debug)
         dep_tree, license_map = runner.check()
+        ignored_packages = ignored_packages_map[ProjectType.PYTHON_PIPENV.value]
 
     if ProjectType.NPM in project_types:
         runner = NpmRunner(path, silent, debug)
         dep_tree, license_map = runner.check()
+        ignored_packages = ignored_packages_map[ProjectType.PYTHON_PIPENV.value]
 
     if ProjectType.MAVEN in project_types:
         runner = MavenRunner(path, silent, debug)
         dep_tree, license_map = runner.check()
+        ignored_packages = ignored_packages_map[ProjectType.PYTHON_PIPENV.value]
 
     if ProjectType.YARN in project_types:
         runner = YarnRunner(path, silent, debug)
         dep_tree, license_map = runner.check()
+        ignored_packages = ignored_packages_map[ProjectType.PYTHON_PIPENV.value]
 
     filtered_dep_tree, licenses_not_found = print_dependency_tree_with_licenses(
-        dep_tree, WHITELIST
+        dep_tree, WHITELIST, ignored_packages
     )
 
     if licenses_not_found and output != "json":
diff --git a/license_sh/helpers.py b/license_sh/helpers.py
index 014ea8b..d89a47c 100644
--- a/license_sh/helpers.py
+++ b/license_sh/helpers.py
@@ -78,12 +78,15 @@ def normalize_license_expression(license_text):
     )
 
 
-def annotate_dep_tree(tree, whitelist: [str]) -> Tuple[AnyNode, Set[str]]:
+def annotate_dep_tree(
+    tree, whitelist: [str], ignored_packages: [str]
+) -> Tuple[AnyNode, Set[str]]:
     """
   An idea of this function is to go through elements from the bottom -> up and
   mark subtree_problem if any of the children has a license_problem or a subtree_problem
   :param tree:
   :param whitelist:
+  :param ignored_packages:
   :return: list of licenses not found in a whitelist
   """
 
@@ -92,7 +95,10 @@ def annotate_dep_tree(tree, whitelist: [str]) -> Tuple[AnyNode, Set[str]]:
 
     licenses_not_found = set()
     for node in PreOrderIter(tree):
-        node.license_problem = not is_license_ok(node.license_normalized, whitelist)
+        node.license_problem = (
+            not is_license_ok(node.license_normalized, whitelist)
+            and node.name not in ignored_packages
+        )
         if node.license_problem and node.license:
             licenses_not_found.add(str(node.license_normalized))
 


Test patch:
diff --git a/tests/runners/test_helpers.py b/tests/runners/test_helpers.py
index 52edd54..6016151 100644
--- a/tests/runners/test_helpers.py
+++ b/tests/runners/test_helpers.py
@@ -73,14 +73,14 @@ class NpmRunnerTestCase(unittest.TestCase):
         tree = get_tree()
 
         whitelist = ["MIT", "Apache-2.0"]
-        _, unknown_licenses = annotate_dep_tree(tree, whitelist)
+        _, unknown_licenses = annotate_dep_tree(tree, whitelist, [])
         self.assertSetEqual(set({"GPL"}), unknown_licenses)
 
     def test_annotate_dependency_tree(self):
         tree = get_tree()
 
         whitelist = ["MIT", "Apache-2.0"]
-        annotated_tree, _ = annotate_dep_tree(tree, whitelist)
+        annotated_tree, _ = annotate_dep_tree(tree, whitelist, [])
 
         expected_tree = AnyNode(
             name="Name",