Skip to content

Commit f095b88

Browse files
JDThomsenmelund
andauthored
Fix for unicode in test Any file headers (#140)
* Attempt at handling unicode test in headers and unicode filenames in written anymcr files. * fix: ensure UTF-8 encoding when opening files for AMMR version retrieval * chore: update version to 1.20.5 and update changelog for pytest plugin fix * black formatting --------- Co-authored-by: Morten Enemark Lund <melund@gmail.com>
1 parent d2747ee commit f095b88

9 files changed

Lines changed: 20 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# AnyPyTools Change Log
22

3+
## v1.20.5
4+
5+
* Fix issue with pytest plugin assuming `.any` files to be encode with default
6+
system encoding instead of UTF8.
7+
38
## v1.20.4
49

510
* Fix crash with pytest plugin when saving output to h5 files.

anypytools/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
"""AnyPyTools library."""
3+
34
import logging
45
import os
56
import platform
@@ -36,7 +37,7 @@
3637
"NORMAL_PRIORITY_CLASS",
3738
]
3839

39-
__version__ = "1.20.4"
40+
__version__ = "1.20.5"
4041

4142

4243
def print_versions():
@@ -49,7 +50,7 @@ def print_versions():
4950
print(f"NumPy version: {np.__version__}")
5051
print(f"SciPy version: {sp.__version__}")
5152
print(f"Python version: {sys.version}")
52-
(sysname, _, release, version, machine, processor) = platform.uname()
53+
sysname, _, release, version, machine, processor = platform.uname()
5354
print(f"Platform: {sysname}-{release}-{machine} ({version})")
5455
if not processor:
5556
processor = "not recognized"

anypytools/datautils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
@author: mel
66
"""
7+
78
import os
89
import re
910
import logging
@@ -184,7 +185,7 @@ def _parse_anyoutputfile_constants(strvar):
184185
value = None
185186
varname = None
186187
if strvar.count("=") == 1 and strvar.startswith("Main"):
187-
(first, last) = strvar.split("=")
188+
first, last = strvar.split("=")
188189
varname = first.strip()
189190
last = last.strip()
190191
value = None

anypytools/h5py_wrapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
@author: mel
66
"""
7+
78
import logging
89

910
import h5py

anypytools/macroutils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,8 @@ def __init__(self, var, frozen_distribution, default_lower_tail_probability=0.5)
292292

293293
self.var = var
294294
if not isinstance(frozen_distribution, rv_frozen):
295-
raise TypeError(
296-
"frozen_distribution must be frozen distribtuion from \
297-
scipy.stats.distributions"
298-
)
295+
raise TypeError("frozen_distribution must be frozen distribtuion from \
296+
scipy.stats.distributions")
299297

300298
self.rv = frozen_distribution
301299

anypytools/pytest_plugin.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
66
@author: Morten
77
"""
8+
89
import os
910
import re
1011
import ast
@@ -108,7 +109,7 @@ def _read_header(fpath):
108109
The function remvoes any leading '//' comments.
109110
"""
110111
code = ""
111-
with open(fpath) as f:
112+
with open(fpath, encoding="utf8") as f:
112113
for line in f.readlines():
113114
if line.startswith("//"):
114115
line = line.strip("//")
@@ -200,7 +201,7 @@ def _parse_header(header, test_file):
200201

201202
def _write_macro_file(path, name, macro):
202203
filename = os.path.join(path, name + ".anymcr")
203-
with open(filename, "w") as f:
204+
with open(filename, "w", encoding="utf8") as f:
204205
f.writelines([str(mcr) + "\n" for mcr in macro])
205206
return filename
206207

anypytools/tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def _anybodycon_version(anybodyconpath):
205205

206206

207207
def _ammr_any_version(fpath):
208-
with open(fpath) as f:
208+
with open(fpath, encoding="utf8") as f:
209209
out = f.read()
210210
match = AMMR_VERSION_RE.search(out)
211211
if match:
@@ -1168,7 +1168,7 @@ def get_bm_constants(ammr_path=None, ammr_version=2):
11681168
ammr_path, "Body/AAUHuman/Documentation/bm_constants.py"
11691169
)
11701170
with suppress(IOError):
1171-
with open(filename) as fh:
1171+
with open(filename, encoding="utf8") as fh:
11721172
bm_constants = literal_eval(fh.read())
11731173
if not isinstance(bm_constants, dict):
11741174
bm_constants = _BM_CONSTANTS if ammr_version >= 2 else _BM_CONSTANTS_AMMR1

pixi.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixi.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ anypytools = {path= "."}
2020

2121
[package]
2222
name = "anypytools"
23-
version="1.20.4"
23+
version="1.20.5"
2424

2525
[package.build]
2626
backend = { name = "pixi-build-python", version = "*" }

0 commit comments

Comments
 (0)