Skip to content

Commit

Permalink
Ensure XML files are opened with UTF-8 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwthompson committed Aug 23, 2024
1 parent 3bb4063 commit 2707210
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()

Check warning on line 77 in foyer/forcefield.py

View check run for this annotation

Codecov / codecov/patch

foyer/forcefield.py#L77

Added line #L77 was not covered by tests
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 2707210

Please sign in to comment.