Skip to content

Commit

Permalink
MAINT: Use logger instead of logging directly
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Oct 27, 2019
1 parent 35b89be commit 74fe623
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
10 changes: 9 additions & 1 deletion edapy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

# Core Library
import collections
import logging
import sys

# Third party
import click
Expand All @@ -20,6 +22,12 @@
import edapy.images
import edapy.pdf

logging.basicConfig(
format="%(asctime)s %(levelname)s %(message)s",
level=logging.DEBUG,
stream=sys.stdout,
)


def setup_yaml():
"""
Expand All @@ -40,7 +48,7 @@ def _represent_dict_order(self, data):
@click.group(help=__doc__)
@click.version_option(version=edapy.__version__)
def entry_point():
pass
"""Exploratory data analysis tool."""


entry_point.add_command(edapy.csv.entry_point)
Expand Down
7 changes: 6 additions & 1 deletion edapy/csv/describe.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""Describe a CSV."""

# Core Library
import logging
from typing import Any, Dict, List, Tuple

# Third party
import pandas as pd

logger = logging.getLogger(__name__)


def describe_pandas_df(
df: pd.DataFrame, dtype: Dict[str, Any] = None
Expand Down Expand Up @@ -140,6 +144,7 @@ def _generate_column_info(
df: pd.DataFrame, dtype: Dict[str, Any]
) -> Tuple[Dict[str, List], Dict[str, Any]]:
"""
Generate information about a column.
Parameters
----------
Expand Down Expand Up @@ -173,7 +178,7 @@ def _generate_column_info(
and column_name not in dtype
)
if is_suspicious_cat:
logging.warning(
logger.warning(
"Column '{}' has only {} different values ({}). "
"You might want to make it a 'category'".format(
column_name, value_count, value_list
Expand Down
4 changes: 3 additions & 1 deletion edapy/images/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# First party
import edapy.images.exif

logger = logging.getLogger(__name__)


###############################################################################
# CLI #
Expand Down Expand Up @@ -102,7 +104,7 @@ def get_image_info(image_path):
elif key in cfg["ignore_keys"]:
continue
else:
logging.debug("Key '{}' is unknown.".format(key))
logger.debug("Key '{}' is unknown.".format(key))

return info

Expand Down
23 changes: 9 additions & 14 deletions edapy/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import logging
import os
import shutil
import sys
from collections import OrderedDict
from difflib import SequenceMatcher
from tempfile import mkstemp
Expand All @@ -19,11 +18,7 @@
import PyPDF2.utils
from PyPDF2 import PdfFileReader

logging.basicConfig(
format="%(asctime)s %(levelname)s %(message)s",
level=logging.DEBUG,
stream=sys.stdout,
)
logger = logging.getLogger(__name__)


###############################################################################
Expand Down Expand Up @@ -100,30 +95,30 @@ def get_pdf_info(pdf_path):
info["is_errornous"] = True
return info
except KeyError as e:
logging.warning(
logger.warning(
"https://github.com/mstamy2/PyPDF2/issues/388 for "
f" PDF '{pdf_path}': {e}"
)
return info
except OSError as e:
logging.warning(f"OSError for PDF '{pdf_path}': {e}")
logger.warning(f"OSError for PDF '{pdf_path}': {e}")
return info
except AssertionError as e:
logging.warning(f"AssertionError for PDF '{pdf_path}': {e}")
logger.warning(f"AssertionError for PDF '{pdf_path}': {e}")
return info
except TypeError as e:
logging.warning(f"TypeError for PDF '{pdf_path}': {e}")
logger.warning(f"TypeError for PDF '{pdf_path}': {e}")
return info

try:
tl_toc = [el for el in pdf_toread.outlines if not isinstance(el, list)]
info["nb_toc_top_level"] = len(tl_toc)
except PyPDF2.utils.PdfReadError as e:
logging.error(f"{pdf_path}: PyPDF2.utils.PdfReadError {e}")
logger.error(f"{pdf_path}: PyPDF2.utils.PdfReadError {e}")
except ValueError as e:
logging.error(f"{pdf_path}: ValueError {e}")
logger.error(f"{pdf_path}: ValueError {e}")
except TypeError as e:
logging.error(f"{pdf_path}: TypeError {e}")
logger.error(f"{pdf_path}: TypeError {e}")

info = enhance_pdf_info(info, pdf_toread, pdf_path, keys, ignore_keys)
return info
Expand Down Expand Up @@ -171,7 +166,7 @@ def enhance_pdf_info(
and not key.startswith("/FL#")
)
if log:
logging.error(
logger.error(
"Unknown key '{key}' "
"(Value: {value}) for PDF '{pdf}'".format(
pdf=pdf_path, key=key, value=pdf_info[key]
Expand Down

0 comments on commit 74fe623

Please sign in to comment.