Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions pypandoc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Union
from typing import Generator

import logging
import os
import re
import subprocess
Expand All @@ -14,12 +13,13 @@
import glob
from pathlib import Path

from .handler import _check_log_handler
from .handler import logger, _check_log_handler
from .pandoc_download import DEFAULT_TARGET_FOLDER, download_pandoc
from .py3compat import cast_bytes, cast_unicode, string_types, url2path, urlparse

__author__ = u'Juho Vepsäläinen'
__author_email__ = "bebraw@gmail.com"
__maintainer__ = u'Jessica Tegner'
__url__ = 'https://github.com/JessicaTegner/pypandoc'
__version__ = '1.10'
__license__ = 'MIT'
Expand Down Expand Up @@ -51,9 +51,6 @@
'get_pandoc_formats', 'get_pandoc_version', 'get_pandoc_path',
'download_pandoc']

# Set up the module level logger
logger = logging.getLogger(__name__)

def convert_text(source:str, to:str, format:str, extra_args:Iterable=(), encoding:str='utf-8',
outputfile:Union[None, str, Path]=None, filters:Union[Iterable, None]=None, verify_format:bool=True,
sandbox:bool=False, cworkdir:Union[str, None]=None) -> str:
Expand Down Expand Up @@ -322,14 +319,18 @@ def _convert_input(source, format, input_type, to, extra_args=(),
sandbox=False, cworkdir=None):

_check_log_handler()

logger.debug("Ensuring pandoc path...")
_ensure_pandoc_path()

if verify_format:
logger.debug("Verifying format...")
format, to = _validate_formats(format, to, outputfile)
else:
format = normalize_format(format)
to = normalize_format(to)

logger.debug("Identifying input type...")
string_input = input_type == 'string'
if not string_input:
if isinstance(source, str):
Expand All @@ -351,7 +352,10 @@ def _convert_input(source, format, input_type, to, extra_args=(),

if sandbox:
if ensure_pandoc_minimal_version(2,15): # sandbox was introduced in pandoc 2.15, so only add if we are using 2.15 or above.
logger.debug("Adding sandbox argument...")
args.append("--sandbox")
else:
logger.warning("Sandbox argument was used, but pandoc version is too low. Ignoring argument.")

args.extend(extra_args)

Expand All @@ -373,6 +377,7 @@ def _convert_input(source, format, input_type, to, extra_args=(),
if cworkdir and old_wd != cworkdir:
os.chdir(cworkdir)

logger.debug("Running pandoc...")
p = subprocess.Popen(
args,
stdin=subprocess.PIPE if string_input else None,
Expand Down Expand Up @@ -702,7 +707,7 @@ def _ensure_pandoc_path() -> None:
# path exist but is not useable -> not executable?
log_msg = ("Found {}, but not using it because of an "
"error:".format(path))
logging.exception(log_msg)
logger.exception(log_msg)
continue
version = [int(x) for x in version_string.split(".")]
while len(version) < len(curr_version):
Expand Down
4 changes: 2 additions & 2 deletions pypandoc/handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import logging

logger = logging.getLogger(__name__.split('.')[0])
logger = logging.getLogger(__name__.split(".")[0])



def _check_log_handler():
Expand All @@ -12,7 +13,6 @@ def _check_log_handler():
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
logging.root.setLevel(logging.DEBUG)

# create formatter
formatter = logging.Formatter('[%(levelname)s] %(message)s')
Expand Down
4 changes: 1 addition & 3 deletions pypandoc/pandoc_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
except ImportError:
from urllib import urlopen

from .handler import _check_log_handler

logger = logging.getLogger(__name__.split('.')[0])
from .handler import logger, _check_log_handler

DEFAULT_TARGET_FOLDER = {
"win32": "~\\AppData\\Local\\Pandoc",
Expand Down