Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat all YAML templates files as UTF-8 encoded #449

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ setup_requires =
pytest-runner
setuptools_git
install_requires =
chardet
pillow
pyyaml
dateparser
Expand Down
7 changes: 1 addition & 6 deletions src/invoice2data/extract/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
import logging
from .invoice_template import InvoiceTemplate
import codecs
import chardet

logger = logging.getLogger(__name__)

logging.getLogger("chardet").setLevel(logging.WARNING)


# borrowed from http://stackoverflow.com/a/21912744
def ordered_load(stream, Loader=yaml.Loader, object_pairs_hook=OrderedDict):
Expand Down Expand Up @@ -86,10 +83,8 @@ def read_templates(folder=None):
for path, subdirs, files in os.walk(folder):
for name in sorted(files):
if name.endswith(".yml"):
with open(os.path.join(path, name), "rb") as f:
encoding = chardet.detect(f.read())["encoding"]
with codecs.open(
os.path.join(path, name), encoding=encoding
os.path.join(path, name), encoding="utf-8"
) as template_file:
try:
tpl = ordered_load(template_file.read())
Expand Down
1 change: 0 additions & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging

# Reduce log level of various modules
logging.getLogger('chardet').setLevel(logging.WARNING)
logging.getLogger('pdfminer').setLevel(logging.WARNING)


Expand Down