From 5c747a3dd4047486ceb338e169f1260b3a5a1b8c Mon Sep 17 00:00:00 2001 From: Yuchen Ethan Xiao Date: Wed, 23 Jul 2025 19:01:42 -0400 Subject: [PATCH 1/2] fix: catch `YappsSyntaxError` as `StructureFormatErrro` --- news/catch-YapsSyntaxError.rst | 23 +++++++++++++++++++++++ src/diffpy/structure/parsers/p_cif.py | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 news/catch-YapsSyntaxError.rst diff --git a/news/catch-YapsSyntaxError.rst b/news/catch-YapsSyntaxError.rst new file mode 100644 index 00000000..7e35ae76 --- /dev/null +++ b/news/catch-YapsSyntaxError.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Let ``diffpy.structure`` pass the tests with ``pycifrw`` installed from ``PyPI``. + +**Security:** + +* diff --git a/src/diffpy/structure/parsers/p_cif.py b/src/diffpy/structure/parsers/p_cif.py index cb2f3fa1..c1d32fff 100644 --- a/src/diffpy/structure/parsers/p_cif.py +++ b/src/diffpy/structure/parsers/p_cif.py @@ -36,6 +36,7 @@ from diffpy.structure import Atom, Lattice, Structure from diffpy.structure.parsers import StructureParser from diffpy.structure.structureerrors import StructureFormatError +from CifFile.yapps3_compiled_rt import YappsSyntaxError # ---------------------------------------------------------------------------- @@ -408,7 +409,7 @@ def _parseCifDataSource(self, datasource): # stop after reading the first structure if self.stru is not None: break - except (StarError, ValueError, IndexError) as err: + except (YappsSyntaxError, StarError, ValueError, IndexError) as err: exc_type, exc_value, exc_traceback = sys.exc_info() emsg = str(err).strip() e = StructureFormatError(emsg) From b910f8767bdbeb83c2fbcfe0ae48d363437621eb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 23 Jul 2025 23:17:18 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit hooks --- src/diffpy/structure/parsers/p_cif.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffpy/structure/parsers/p_cif.py b/src/diffpy/structure/parsers/p_cif.py index c1d32fff..3d0611ab 100644 --- a/src/diffpy/structure/parsers/p_cif.py +++ b/src/diffpy/structure/parsers/p_cif.py @@ -32,11 +32,11 @@ from contextlib import contextmanager import numpy +from CifFile.yapps3_compiled_rt import YappsSyntaxError from diffpy.structure import Atom, Lattice, Structure from diffpy.structure.parsers import StructureParser from diffpy.structure.structureerrors import StructureFormatError -from CifFile.yapps3_compiled_rt import YappsSyntaxError # ----------------------------------------------------------------------------