From a5c50c988941cc2e31fb88a8ef3a62baa8f158d0 Mon Sep 17 00:00:00 2001 From: jdt Date: Tue, 17 Feb 2026 15:04:04 +0100 Subject: [PATCH 1/4] Attempt at handling unicode test in headers and unicode filenames in written anymcr files. --- anypytools/pytest_plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/anypytools/pytest_plugin.py b/anypytools/pytest_plugin.py index 8f5b30e..d058b75 100644 --- a/anypytools/pytest_plugin.py +++ b/anypytools/pytest_plugin.py @@ -108,7 +108,7 @@ def _read_header(fpath): The function remvoes any leading '//' comments. """ code = "" - with open(fpath) as f: + with open(fpath, encoding='utf8') as f: for line in f.readlines(): if line.startswith("//"): line = line.strip("//") @@ -200,7 +200,7 @@ def _parse_header(header, test_file): def _write_macro_file(path, name, macro): filename = os.path.join(path, name + ".anymcr") - with open(filename, "w") as f: + with open(filename, "w", encoding='utf8') as f: f.writelines([str(mcr) + "\n" for mcr in macro]) return filename From 2df5a608bc605c057408f13156ecbe47c9555e83 Mon Sep 17 00:00:00 2001 From: Morten Enemark Lund Date: Tue, 17 Feb 2026 19:02:50 +0100 Subject: [PATCH 2/4] fix: ensure UTF-8 encoding when opening files for AMMR version retrieval --- anypytools/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/anypytools/tools.py b/anypytools/tools.py index 6d39d31..86bb007 100644 --- a/anypytools/tools.py +++ b/anypytools/tools.py @@ -205,7 +205,7 @@ def _anybodycon_version(anybodyconpath): def _ammr_any_version(fpath): - with open(fpath) as f: + with open(fpath, encoding='utf8') as f: out = f.read() match = AMMR_VERSION_RE.search(out) if match: @@ -1168,7 +1168,7 @@ def get_bm_constants(ammr_path=None, ammr_version=2): ammr_path, "Body/AAUHuman/Documentation/bm_constants.py" ) with suppress(IOError): - with open(filename) as fh: + with open(filename, encoding='utf8') as fh: bm_constants = literal_eval(fh.read()) if not isinstance(bm_constants, dict): bm_constants = _BM_CONSTANTS if ammr_version >= 2 else _BM_CONSTANTS_AMMR1 From d23194878f3fbe839cd8a5194e158ce747bd170c Mon Sep 17 00:00:00 2001 From: Morten Enemark Lund Date: Tue, 17 Feb 2026 19:06:19 +0100 Subject: [PATCH 3/4] chore: update version to 1.20.5 and update changelog for pytest plugin fix --- CHANGELOG.md | 5 +++++ anypytools/__init__.py | 2 +- pixi.lock | 2 +- pixi.toml | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67a9efe..0d392e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # AnyPyTools Change Log +## v1.20.5 + +* Fix issue with pytest plugin assuming `.any` files to be encode with default + system encoding instead of UTF8. + ## v1.20.4 * Fix crash with pytest plugin when saving output to h5 files. diff --git a/anypytools/__init__.py b/anypytools/__init__.py index df57f7b..e369cef 100644 --- a/anypytools/__init__.py +++ b/anypytools/__init__.py @@ -36,7 +36,7 @@ "NORMAL_PRIORITY_CLASS", ] -__version__ = "1.20.4" +__version__ = "1.20.5" def print_versions(): diff --git a/pixi.lock b/pixi.lock index b032f48..d3b0117 100644 --- a/pixi.lock +++ b/pixi.lock @@ -2150,7 +2150,7 @@ packages: timestamp: 1767719033569 - conda: . name: anypytools - version: 1.20.4 + version: 1.20.5 build: pyh4616a5c_0 subdir: noarch variants: diff --git a/pixi.toml b/pixi.toml index 6448313..7eaf9ef 100644 --- a/pixi.toml +++ b/pixi.toml @@ -20,7 +20,7 @@ anypytools = {path= "."} [package] name = "anypytools" -version="1.20.4" +version="1.20.5" [package.build] backend = { name = "pixi-build-python", version = "*" } From 3de46aa4af5d16414b46f3820884c9093ed04574 Mon Sep 17 00:00:00 2001 From: Morten Enemark Lund Date: Tue, 17 Feb 2026 19:23:42 +0100 Subject: [PATCH 4/4] black formatting --- anypytools/__init__.py | 3 ++- anypytools/datautils.py | 3 ++- anypytools/h5py_wrapper.py | 1 + anypytools/macroutils.py | 6 ++---- anypytools/pytest_plugin.py | 5 +++-- anypytools/tools.py | 4 ++-- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/anypytools/__init__.py b/anypytools/__init__.py index e369cef..d045a01 100644 --- a/anypytools/__init__.py +++ b/anypytools/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- """AnyPyTools library.""" + import logging import os import platform @@ -49,7 +50,7 @@ def print_versions(): print(f"NumPy version: {np.__version__}") print(f"SciPy version: {sp.__version__}") print(f"Python version: {sys.version}") - (sysname, _, release, version, machine, processor) = platform.uname() + sysname, _, release, version, machine, processor = platform.uname() print(f"Platform: {sysname}-{release}-{machine} ({version})") if not processor: processor = "not recognized" diff --git a/anypytools/datautils.py b/anypytools/datautils.py index c1009c7..1a1b690 100644 --- a/anypytools/datautils.py +++ b/anypytools/datautils.py @@ -4,6 +4,7 @@ @author: mel """ + import os import re import logging @@ -184,7 +185,7 @@ def _parse_anyoutputfile_constants(strvar): value = None varname = None if strvar.count("=") == 1 and strvar.startswith("Main"): - (first, last) = strvar.split("=") + first, last = strvar.split("=") varname = first.strip() last = last.strip() value = None diff --git a/anypytools/h5py_wrapper.py b/anypytools/h5py_wrapper.py index 808693b..69f6cd8 100644 --- a/anypytools/h5py_wrapper.py +++ b/anypytools/h5py_wrapper.py @@ -4,6 +4,7 @@ @author: mel """ + import logging import h5py diff --git a/anypytools/macroutils.py b/anypytools/macroutils.py index c021984..564ede4 100644 --- a/anypytools/macroutils.py +++ b/anypytools/macroutils.py @@ -292,10 +292,8 @@ def __init__(self, var, frozen_distribution, default_lower_tail_probability=0.5) self.var = var if not isinstance(frozen_distribution, rv_frozen): - raise TypeError( - "frozen_distribution must be frozen distribtuion from \ - scipy.stats.distributions" - ) + raise TypeError("frozen_distribution must be frozen distribtuion from \ + scipy.stats.distributions") self.rv = frozen_distribution diff --git a/anypytools/pytest_plugin.py b/anypytools/pytest_plugin.py index d058b75..21da9f9 100644 --- a/anypytools/pytest_plugin.py +++ b/anypytools/pytest_plugin.py @@ -5,6 +5,7 @@ @author: Morten """ + import os import re import ast @@ -108,7 +109,7 @@ def _read_header(fpath): The function remvoes any leading '//' comments. """ code = "" - with open(fpath, encoding='utf8') as f: + with open(fpath, encoding="utf8") as f: for line in f.readlines(): if line.startswith("//"): line = line.strip("//") @@ -200,7 +201,7 @@ def _parse_header(header, test_file): def _write_macro_file(path, name, macro): filename = os.path.join(path, name + ".anymcr") - with open(filename, "w", encoding='utf8') as f: + with open(filename, "w", encoding="utf8") as f: f.writelines([str(mcr) + "\n" for mcr in macro]) return filename diff --git a/anypytools/tools.py b/anypytools/tools.py index 86bb007..15c792c 100644 --- a/anypytools/tools.py +++ b/anypytools/tools.py @@ -205,7 +205,7 @@ def _anybodycon_version(anybodyconpath): def _ammr_any_version(fpath): - with open(fpath, encoding='utf8') as f: + with open(fpath, encoding="utf8") as f: out = f.read() match = AMMR_VERSION_RE.search(out) if match: @@ -1168,7 +1168,7 @@ def get_bm_constants(ammr_path=None, ammr_version=2): ammr_path, "Body/AAUHuman/Documentation/bm_constants.py" ) with suppress(IOError): - with open(filename, encoding='utf8') as fh: + with open(filename, encoding="utf8") as fh: bm_constants = literal_eval(fh.read()) if not isinstance(bm_constants, dict): bm_constants = _BM_CONSTANTS if ammr_version >= 2 else _BM_CONSTANTS_AMMR1