Skip to content

Commit

Permalink
Added coloredlogs
Browse files Browse the repository at this point in the history
Pimlico now always tries to install and load coloredlogs, so that the
extensive logging output it produces is a bit easier to read.

If it fails, it doesn't worry about it.
  • Loading branch information
markgw committed Aug 6, 2020
1 parent 4b808f4 commit fdc557a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/python/pimlico/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
reload(site)

from pimlico.core.dependencies.base import check_and_install
from pimlico.core.dependencies.core import CORE_PIMLICO_DEPENDENCIES
from pimlico.core.dependencies.core import CORE_PIMLICO_DEPENDENCIES, coloredlogs_dependency

PIMLICO_ROOT = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", ".."))

Expand Down Expand Up @@ -74,6 +74,18 @@ def install_core_dependencies():
print("Unable to install all core dependencies: exiting", file=sys.stderr)
sys.exit(1)

# Special procedure for coloredlogs
# This is nice to have, but if we can't install it or load it, it's not a problem
try:
if not coloredlogs_dependency.available({}):
print("Installing coloredlogs")
coloredlogs_dependency.install({})
# Load coloredlogs and start using it for all logging formatters
import coloredlogs
coloredlogs.install()
except Exception as e:
print("Error installing and loading colorlogs. Logs will not be coloured. {}".format(e))


def get_jupyter_pipeline():
"""
Expand Down
5 changes: 4 additions & 1 deletion src/python/pimlico/core/dependencies/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from future.utils import PY2

from pimlico.core.dependencies.python import PythonPackageOnPip, PythonPackageSystemwideInstall
from pimlico.core.dependencies.python import PythonPackageOnPip

#: Core dependencies required by the basic Pimlico installation, regardless of what pipeline is being processed.
#: These will be checked when Pimlico is run, using the same dependency-checking mechanism that Pimlico modules
Expand Down Expand Up @@ -34,3 +34,6 @@
# Provides a backport of Py3's updated and renamed configparser package
PythonPackageOnPip("configparser"),
])


coloredlogs_dependency = PythonPackageOnPip("coloredlogs")
5 changes: 5 additions & 0 deletions src/python/pimlico/test/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
from pimlico.test.pipeline import run_test_suite
from pimlico.utils.logging import get_console_logger

if __name__ == "__main__":
from pimlico import install_core_dependencies
install_core_dependencies()


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Pipeline test suite runner")
parser.add_argument("suite_file", help="CSV file in which each line contains a path to a pipeline config file "
Expand Down

0 comments on commit fdc557a

Please sign in to comment.