Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
  • Loading branch information
jkowalleck committed Dec 13, 2022
1 parent c4dc214 commit 957f5ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
46 changes: 29 additions & 17 deletions cyclonedx_py/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,10 @@ def _error_and_exit(message: str, *args: Any, exit_code: int = 1, **kwargs: Any)

def _get_input_parser(self) -> BaseParser:
if self._arguments.input_from_environment:
return EnvironmentParser(use_purl_bom_ref=self._arguments.use_purl_bom_ref,
debug_message=lambda m, *a, **k: self._debug_message(f'EnvironmentParser - {m}', *a, **k))
return EnvironmentParser(
use_purl_bom_ref=self._arguments.use_purl_bom_ref,
debug_message=lambda m, *a, **k: self._debug_message(f'EnvironmentParser - {m}', *a, **k)
)

# All other Parsers will require some input - grab it now!
if not self._arguments.input_source:
Expand Down Expand Up @@ -288,25 +290,35 @@ def _get_input_parser(self) -> BaseParser:
input_data_fh.close()

if self._arguments.input_from_conda_explicit:
return CondaListExplicitParser(conda_data=input_data,
use_purl_bom_ref=self._arguments.use_purl_bom_ref,
debug_message=lambda m, *a, **k: self._debug_message(f'CondaListExplicitParser - {m}', *a, **k))
return CondaListExplicitParser(
conda_data=input_data,
use_purl_bom_ref=self._arguments.use_purl_bom_ref,
debug_message=lambda m, *a, **k: self._debug_message(f'CondaListExplicitParser - {m}', *a, **k)
)
elif self._arguments.input_from_conda_json:
return CondaListJsonParser(conda_data=input_data,
use_purl_bom_ref=self._arguments.use_purl_bom_ref,
debug_message=lambda m, *a, **k: self._debug_message(f'CondaListJsonParser - {m}', *a, **k))
return CondaListJsonParser(
conda_data=input_data,
use_purl_bom_ref=self._arguments.use_purl_bom_ref,
debug_message=lambda m, *a, **k: self._debug_message(f'CondaListJsonParser - {m}', *a, **k)
)
elif self._arguments.input_from_pip:
return PipEnvParser(pipenv_contents=input_data,
use_purl_bom_ref=self._arguments.use_purl_bom_ref,
debug_message=lambda m, *a, **k: self._debug_message(f'PipEnvParser - {m}', *a, **k))
return PipEnvParser(
pipenv_contents=input_data,
use_purl_bom_ref=self._arguments.use_purl_bom_ref,
debug_message=lambda m, *a, **k: self._debug_message(f'PipEnvParser - {m}', *a, **k)
)
elif self._arguments.input_from_poetry:
return PoetryParser(poetry_lock_contents=input_data,
use_purl_bom_ref=self._arguments.use_purl_bom_ref,
debug_message=lambda m, *a, **k: self._debug_message(f'PoetryParser - {m}', *a, **k))
return PoetryParser(
poetry_lock_contents=input_data,
use_purl_bom_ref=self._arguments.use_purl_bom_ref,
debug_message=lambda m, *a, **k: self._debug_message(f'PoetryParser - {m}', *a, **k)
)
elif self._arguments.input_from_requirements:
return RequirementsParser(requirements_content=input_data,
use_purl_bom_ref=self._arguments.use_purl_bom_ref,
debug_message=lambda m, *a, **k: self._debug_message(f'RequirementsParser - {m}', *a, **k))
return RequirementsParser(
requirements_content=input_data,
use_purl_bom_ref=self._arguments.use_purl_bom_ref,
debug_message=lambda m, *a, **k: self._debug_message(f'RequirementsParser - {m}', *a, **k)
)
else:
raise CycloneDxCmdException('Parser type could not be determined.')

Expand Down
6 changes: 3 additions & 3 deletions cyclonedx_py/parser/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

DebugMessageCallback = Callable[[Arg(str, 'message'), VarArg(Any), KwArg(Any)], None]
"""Callback for debug messaging.
:param message: the format string,
:Parameter message: the format string
:Other Parameters: the *args: to :func:`str.forma()`
:Keyword Arguments: the **kwargs to :func:`str.format()`.
:Keyword Arguments: the **kwargs to :func:`str.format()`
"""
else:
DebugMessageCallback = Callable[..., None]
Expand Down
1 change: 0 additions & 1 deletion cyclonedx_py/parser/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import os
import os.path
from tempfile import NamedTemporaryFile, _TemporaryFileWrapper # Weak error
from typing import Any, Optional

from cyclonedx.model import HashType
from cyclonedx.model.component import Component
Expand Down

0 comments on commit 957f5ae

Please sign in to comment.