Skip to content

Commit

Permalink
Bear.py: Implement check_prerequisites
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrianzatreanu committed Dec 28, 2016
1 parent df65fd6 commit 746a730
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
25 changes: 21 additions & 4 deletions coalib/bears/Bear.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
from coala_utils.decorators import (enforce_signature, classproperty,
get_public_members)

from coalib.bears.requirements.PackageRequirement import PackageRequirement
from coalib.bears.requirements.PipRequirement import PipRequirement
from dependency_management.requirements.PackageRequirement import (
PackageRequirement)
from dependency_management.requirements.PipRequirement import PipRequirement
from coalib.output.printers.LogPrinter import LogPrinterMixin
from coalib.results.Result import Result
from coalib.settings.FunctionMetadata import FunctionMetadata
Expand Down Expand Up @@ -323,14 +324,30 @@ def check_prerequisites(cls):
"""
Checks whether needed runtime prerequisites of the bear are satisfied.
This function gets executed at construction and returns True by
default.
This function gets executed at construction.
Section value requirements shall be checked inside the ``run`` method.
>>> class SomeBear(Bear):
... REQUIREMENTS = {PipRequirement('pip')}
>>> SomeBear.check_prerequisites()
True
>>> class SomeOtherBear(Bear):
... REQUIREMENTS = {PipRequirement('really_bad_package')}
>>> SomeOtherBear.check_prerequisites()
'really_bad_package is not installed. You can install it using ...'
:return: True if prerequisites are satisfied, else False or a string
that serves a more detailed description of what's missing.
"""
for requirement in cls.REQUIREMENTS:
if not requirement.is_installed():
return requirement.package + ' is not installed. You can ' + (
'install it using ') + (
' '.join(requirement.install_command()))
return True

def get_config_dir(self):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
appdirs~=1.4
coala_utils~=0.5.1
colorlog~=2.7
dependency_management~=0.1.7
# libclang-py3 version numbering maps to the clang releases
libclang-py3~=3.4.0
Pygments~=2.1
Expand Down

0 comments on commit 746a730

Please sign in to comment.