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

Feat/no check error #95

Merged
merged 3 commits into from
Feb 12, 2020
Merged
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
52 changes: 24 additions & 28 deletions license_sh/commands/run_license_sh.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import questionary

import sys
from . import config_cmd
from ..config import get_config, whitelist_licenses
from ..helpers import get_dependency_tree_with_licenses
from ..project_identifier import ProjectType, get_project_types
from ..reporters.ConsoleReporter import ConsoleReporter
from ..reporters.JSONConsoleReporter import JSONConsoleReporter
from ..runners.maven import MavenRunner
from ..runners.npm import NpmRunner
from ..runners.python import PythonRunner
from ..runners.yarn import YarnRunner
from ..runners import run_check

try:
from license_sh_private.licenses import COMMERCIAL_LICENSES as WHITELIST
Expand Down Expand Up @@ -45,30 +42,29 @@ def run_license_sh(arguments):
# docopt guarantees that output variable contains either console or json
Reporter = {"console": ConsoleReporter, "json": JSONConsoleReporter}[output]

project_types = get_project_types(path)
ignored_packages = []

dep_tree = None

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.NPM.value]

if ProjectType.MAVEN in project_types:
runner = MavenRunner(path, silent, debug)
dep_tree, license_map = runner.check()
ignored_packages = ignored_packages_map[ProjectType.MAVEN.value]

if ProjectType.YARN in project_types:
runner = YarnRunner(path, silent, debug)
dep_tree, license_map = runner.check()
ignored_packages = ignored_packages_map[ProjectType.YARN.value]
project_list = [e.value for e in get_project_types(path)]

if len(project_list) == 0:
supported_projects = [e.value for e in ProjectType]
print(
f"None of currently supported projects found. Supported {supported_projects}",
file=sys.stderr,
)
exit(2)

if len(project_list) > 1:
print(
f"Curretly there is no support for multi project/language repositories. Found {project_types}. Only '{project_types[0]}' will be checked.",
file=sys.stderr,
)

project_to_check = project_list[0]
dep_tree = run_check(project_to_check, path, silent, debug)
ignored_packages = ignored_packages_map.get(project_to_check, [])
if not dep_tree:
print(f"Unexpected issue, couldn't create dependency tree", file=sys.stderr)
exit(3)

(
filtered_dep_tree,
Expand Down
20 changes: 20 additions & 0 deletions license_sh/runners/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from ..runners.maven import MavenRunner
from ..runners.npm import NpmRunner
from ..runners.python import PythonRunner
from ..runners.yarn import YarnRunner
from ..project_identifier import ProjectType

RUNNERS = {
ProjectType.PYTHON_PIPENV.value: PythonRunner,
ProjectType.YARN.value: YarnRunner,
ProjectType.NPM.value: NpmRunner,
ProjectType.MAVEN.value: MavenRunner,
}


def run_check(project_to_check: str, path: str, silent: bool, debug: bool):
runner = RUNNERS.get(project_to_check)
if not runner:
return None

return runner(path, silent, debug).check()
2 changes: 1 addition & 1 deletion license_sh/runners/maven/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,4 @@ def check(self):
for node in PreOrderIter(dep_tree):
node.license = license_map.get(f"{node.name}@{node.version}", "")

return dep_tree, license_map
return dep_tree
2 changes: 1 addition & 1 deletion license_sh/runners/npm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,4 @@ def check(self):
hasattr(node, "version_request") and delattr(node, "version_request")
node.license = license_map.get(f"{node.name}@{node.version}", None)

return dep_tree, license_map
return dep_tree
2 changes: 1 addition & 1 deletion license_sh/runners/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ def check(self):
for node in PreOrderIter(root):
node.license = license_map.get(f"{node.name}@{node.version}", None)

return root, license_map
return root
2 changes: 1 addition & 1 deletion license_sh/runners/yarn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,4 @@ def check(self):
for node in PreOrderIter(dep_tree):
node.license = license_map.get(f"{node.name}@{node.version}", None)

return dep_tree, license_map
return dep_tree