Skip to content

Commit

Permalink
Merge pull request #580 from mattwthompson/utf-8-xml
Browse files Browse the repository at this point in the history
Ensure XML files are opened with UTF-8 encoding
  • Loading branch information
CalCraven committed Aug 30, 2024
2 parents 648d714 + 2707210 commit 469712f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- openmm
- parmed>=3.4.3
- ele
- openff-toolkit >=0.11
- openff-toolkit-base >=0.11
- pip
- pre-commit
- pytest
Expand Down
12 changes: 7 additions & 5 deletions foyer/forcefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ def preprocess_forcefield_files(forcefield_files=None):

for xml_file in forcefield_files:
if not hasattr(xml_file, "read"):
f = open(xml_file)
try:
f = open(xml_file, encoding="utf-8")
xml_contents = f.read()
finally:
f.close()

_, suffix = os.path.split(xml_file)
else:
f = xml_file
xml_contents = xml_file.read()
suffix = ""

# read and preprocess
xml_contents = f.read()
f.close()
xml_contents = re.sub(
r"(def\w*=\w*[\"\'])(.*)([\"\'])",
lambda m: m.group(1)
Expand Down

0 comments on commit 469712f

Please sign in to comment.