Skip to content

Commit eb7b2d1

Browse files
iroskammDuo13
authored andcommitted
v0.8.2: Fix file encoding issue on Windows
* Closes #41 Python uses system default encoding to open files. On Windows the default encoding is latin-1. As a result dactyl will crash on Windows. - added explicit utf-8 encoding parameter to all open() calls * Set version to 0.8.2
1 parent 62f0dde commit eb7b2d1

File tree

7 files changed

+13
-13
lines changed

7 files changed

+13
-13
lines changed

dactyl/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def guess_title_from_md_file(filepath):
4545
If the first two lines look like a Markdown header, use that.
4646
Otherwise, return the filename."""
4747
try:
48-
with open(filepath, "r") as f:
48+
with open(filepath, "r", encoding="utf-8") as f:
4949
line1 = f.readline()
5050
line2 = f.readline()
5151

dactyl/config.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def set_logging(self):
5151
def load_config_from_file(self, config_file):
5252
logger.debug("loading config file %s..." % config_file)
5353
try:
54-
with open(config_file, "r") as f:
54+
with open(config_file, "r", encoding="utf-8") as f:
5555
loaded_config = yaml.load(f)
5656
except FileNotFoundError as e:
5757
if config_file == DEFAULT_CONFIG_FILE:
@@ -165,14 +165,14 @@ def load_filters(self):
165165
def load_style_rules(self):
166166
"""Reads word and phrase substitution files into the config"""
167167
if "word_substitutions_file" in self.config:
168-
with open(self.config["word_substitutions_file"], "r") as f:
168+
with open(self.config["word_substitutions_file"], "r", endoding="utf-8") as f:
169169
self.config["disallowed_words"] = yaml.load(f)
170170
else:
171171
logger.warning("No 'word_substitutions_file' found in config.")
172172
self.config["disallowed_words"] = {}
173173

174174
if "phrase_substitutions_file" in self.config:
175-
with open(self.config["phrase_substitutions_file"], "r") as f:
175+
with open(self.config["phrase_substitutions_file"], "r", encoding="utf-8") as f:
176176
self.config["disallowed_phrases"] = yaml.load(f)
177177
else:
178178
logger.warning("No 'phrase_substitutions_file' found in config.")
@@ -210,7 +210,7 @@ def get_es_template(self, filename):
210210
"""Loads an ElasticSearch template (as JSON)"""
211211
template_path = os.path.join(self.config["template_path"], filename)
212212
try:
213-
with open(template_path) as f:
213+
with open(template_path, encoding="utf-8") as f:
214214
es_template = json.load(f)
215215
except (FileNotFoundError, json.decoder.JSONDecodeError) as e:
216216
if type(e) == FileNotFoundError:

dactyl/dactyl_build.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def preprocess_markdown(page, target=None, categories=[], page_filters=[],
314314
md = read_markdown_remote(page["md"])
315315
else:
316316
logger.info("... reading markdown from file")
317-
with open(page["md"], "r") as f:
317+
with open(page["md"], "r", encoding="utf-8") as f:
318318
md = f.read()
319319

320320
else:
@@ -887,7 +887,7 @@ def write_page(page_text, filepath, out_path):
887887
logger.info("creating output folder %s" % out_folder)
888888
os.makedirs(out_folder)
889889
fileout = os.path.join(out_path, filepath)
890-
with open(fileout, "w") as f:
890+
with open(fileout, "w", encoding="utf-8") as f:
891891
logger.info("writing to file: %s..." % fileout)
892892
f.write(page_text)
893893

@@ -1010,7 +1010,7 @@ def main(cli_args):
10101010
if cli_args.vars:
10111011
try:
10121012
if cli_args.vars[-5:] in (".json",".yaml"):
1013-
with open(cli_args.vars, "r") as f:
1013+
with open(cli_args.vars, "r", encoding="utf-8") as f:
10141014
custom_keys = yaml.load(f)
10151015
else:
10161016
custom_keys = yaml.load(cli_args.vars)

dactyl/dactyl_link_checker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def getSoup(fullPath):
1717
if fullPath in soupsCache.keys():
1818
soup = soupsCache[fullPath]
1919
else:
20-
with open(fullPath, 'r') as f:
20+
with open(fullPath, 'r', encoding="utf-8") as f:
2121
soup = BeautifulSoup(f.read(), "html.parser")
2222
soupsCache[fullPath] = soup
2323
return soup

dactyl/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.8.1'
1+
__version__ = '0.8.2'

examples/custom_filters/filter_include_code.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
def include_code(filename, lines="", mark_disjoint="", language=""):
22
#TO-DO: Add "start_after" and "end_before" as an alternative to lines
3-
with open(filename) as f:
3+
with open(filename, encoding="utf-8") as f:
44
s = f.read()
55

66
# mark_disjoint

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import pypandoc
1010
long_description = pypandoc.convert('README.md', 'rst')
1111
except ImportError:
12-
long_description = open('README.md').read()
12+
long_description = open('README.md', encoding="utf-8").read()
1313

14-
with open("dactyl/version.py") as versionfile:
14+
with open("dactyl/version.py", encoding="utf-8") as versionfile:
1515
exec(versionfile.read())
1616

1717
setup(

0 commit comments

Comments
 (0)