Skip to content

Throw python exceptions#579

Merged
lan496 merged 20 commits intospglib:developfrom
LecrisUT:feat/python-checks
Nov 20, 2025
Merged

Throw python exceptions#579
lan496 merged 20 commits intospglib:developfrom
LecrisUT:feat/python-checks

Conversation

@LecrisUT
Copy link
Copy Markdown
Collaborator

@LecrisUT LecrisUT commented May 10, 2025

TODO:

  • Make the library throw exceptions
  • Add a compatibility for the old error handling
  • Add more checks in the C++ code

Depends-on: #578
Closes #582

@codecov
Copy link
Copy Markdown

codecov bot commented May 10, 2025

Codecov Report

❌ Patch coverage is 56.25000% with 84 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.05%. Comparing base (cb11bf2) to head (4bd37ad).
⚠️ Report is 52 commits behind head on develop.

Files with missing lines Patch % Lines
python/py_bindings.cpp 46.66% 74 Missing and 6 partials ⚠️
python/py_bindings.h 25.00% 3 Missing ⚠️
python/_spglib.cpp 97.29% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #579      +/-   ##
===========================================
- Coverage    74.51%   74.05%   -0.46%     
===========================================
  Files           26       27       +1     
  Lines         7899     8018     +119     
  Branches      1635     1646      +11     
===========================================
+ Hits          5886     5938      +52     
- Misses        1534     1603      +69     
+ Partials       479      477       -2     
Flag Coverage Δ
c_api 69.45% <100.00%> (ø)
fortran_api 52.96% <0.00%> (ø)
python_api 67.18% <55.72%> (-0.54%) ⬇️
unit_tests 11.68% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LecrisUT LecrisUT force-pushed the feat/python-checks branch 3 times, most recently from 9a8373e to df4be1d Compare May 12, 2025 11:50
@LecrisUT LecrisUT added this to the 2.7 milestone Jun 2, 2025
@LecrisUT LecrisUT force-pushed the feat/python-checks branch from df4be1d to 41c6c8a Compare July 22, 2025 12:37
@atztogo atztogo mentioned this pull request Oct 30, 2025
@LecrisUT LecrisUT force-pushed the feat/python-checks branch 2 times, most recently from 8c22839 to 80aa052 Compare November 9, 2025 21:24
@LecrisUT LecrisUT marked this pull request as ready for review November 9, 2025 21:45
@LecrisUT LecrisUT changed the title WIP: Throw python exceptions Throw python exceptions Nov 9, 2025
@LecrisUT
Copy link
Copy Markdown
Collaborator Author

LecrisUT commented Nov 9, 2025

There were still some areas that I didn't manage to add proper checks on the cpp side, but it should be a good enough approach for now.

@lan496 lan496 added the breaking-changes Changes that are incompatible with previous release label Nov 16, 2025
@LecrisUT LecrisUT requested a review from lan496 November 17, 2025 17:22
@lan496
Copy link
Copy Markdown
Member

lan496 commented Nov 19, 2025

Some existing tests start to raise SpglibError and result in CI failure

@lan496
Copy link
Copy Markdown
Member

lan496 commented Nov 19, 2025

@atztogo, can you also take a look at this PR?

@lan496 lan496 requested a review from atztogo November 19, 2025 00:46
@LecrisUT
Copy link
Copy Markdown
Collaborator Author

Some existing tests start to raise SpglibError and result in CI failure

Ah, it's trivial. We have changed what the exception was being raised in that test and I forgot to adapt it

Signed-off-by: Cristian Le <[email protected]>
Signed-off-by: Cristian Le <[email protected]>
Encountered implicit conversion issues. This can probably be relaxed when all arguments are typed accordingly

Signed-off-by: Cristian Le <[email protected]>
- Simplifies the conversions
- Embeds the array size checks

Signed-off-by: Cristian Le <[email protected]>
For some reason it doesn't pick it up when trying to use it
Copy link
Copy Markdown
Collaborator

@atztogo atztogo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @LecrisUT!

Copy link
Copy Markdown
Member

@lan496 lan496 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lan496 lan496 merged commit 170ff8c into spglib:develop Nov 20, 2025
47 of 50 checks passed
@siteshwar
Copy link
Copy Markdown

There were some deprecation warnings reported by OpenScanHub that might be good to fix:

Error: COMPILER_WARNING ([CWE-477](https://cwe.mitre.org/data/definitions/477.html)): [[#def1]](https://openscanhub.fedoraproject.org/task/82755/log/added.html#def1)
spglib-2.6.0/python/py_bindings.cpp: scope_hint: In function ‘pybind11::dict spglib::layer_dataset(const Lattice&, const Positions&, const AtomTypes&, pybind11::int_, pybind11::float_)’
spglib-2.6.0/python/py_bindings.cpp:366:41: warning[-Wdeprecated-declarations]: ‘SpglibDataset* spg_get_layer_dataset(const double (*)[3], const double (*)[3], const int*, int, int, double)’ is deprecated: Experimental interface. May be removed in next major release.
#  366 |     auto dataset = spg_get_layer_dataset(lattice.data(), positions.data(),
#      |                    ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  367 |                                          atom_types.data(), atom_types.n_atoms,
#      |                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  368 |                                          aperiodic_dir, symprec);
#      |                                          ~~~~~~~~~~~~~~~~~~~~~~~
spglib-2.6.0/python/py_bindings.cpp:4: included_from: Included from here.
spglib-2.6.0/include/spglib.h:212:24: note: declared here
#  212 | SPG_API SpglibDataset *spg_get_layer_dataset(
#      |                        ^~~~~~~~~~~~~~~~~~~~~
#  364|                                  AtomTypes const &atom_types,
#  365|                                  py::int_ aperiodic_dir, py::float_ symprec) {
#  366|->     auto dataset = spg_get_layer_dataset(lattice.data(), positions.data(),
#  367|                                            atom_types.data(), atom_types.n_atoms,
#  368|                                            aperiodic_dir, symprec);

Error: COMPILER_WARNING ([CWE-477](https://cwe.mitre.org/data/definitions/477.html)): [[#def2]](https://openscanhub.fedoraproject.org/task/82755/log/added.html#def2)
spglib-2.6.0/python/py_bindings.cpp: scope_hint: In function ‘pybind11::int_ spglib::symmetry(Rotations&, Translations&, const Lattice&, const Positions&, const AtomTypes&, pybind11::float_, pybind11::float_)’
spglib-2.6.0/python/py_bindings.cpp:492:34: warning[-Wdeprecated-declarations]: ‘int spgat_get_symmetry(int (*)[3][3], double (*)[3], int, const double (*)[3], const double (*)[3], const int*, int, double, double)’ is deprecated: Use the variables from SpglibDataset (rotations, translations)
#  492 |     auto val = spgat_get_symmetry(rotations.data(), translations.data(),
#      |                ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  493 |                                   rotations.n_operations, lattice.data(),
#      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  494 |                                   positions.data(), atom_types.data(),
#      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  495 |                                   atom_types.n_atoms, symprec, angle_tolerance);
#      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
spglib-2.6.0/include/spglib.h:254:13: note: declared here
#  254 | SPG_API int spgat_get_symmetry(int rotation[][3][3], double translation[][3],
#      |             ^~~~~~~~~~~~~~~~~~
#  490|                             AtomTypes const &atom_types, py::float_ symprec,
#  491|                             py::float_ angle_tolerance) {
#  492|->     auto val = spgat_get_symmetry(rotations.data(), translations.data(),
#  493|                                     rotations.n_operations, lattice.data(),
#  494|                                     positions.data(), atom_types.data(),

Error: COMPILER_WARNING ([CWE-477](https://cwe.mitre.org/data/definitions/477.html)): [[#def3]](https://openscanhub.fedoraproject.org/task/82755/log/added.html#def3)
spglib-2.6.0/python/py_bindings.cpp: scope_hint: In function ‘pybind11::int_ spglib::hall_number_from_symmetry(const Rotations&, const Translations&, pybind11::float_)’
spglib-2.6.0/python/py_bindings.cpp:658:49: warning[-Wdeprecated-declarations]: ‘int spg_get_hall_number_from_symmetry(const int (*)[3][3], const double (*)[3], int, double)’ is deprecated: Use the variable from SpglibSpacegroupType instead (hall_number)
#  658 |     auto val = spg_get_hall_number_from_symmetry(
#      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
#  659 |         rotations.data(), translations.data(), rotations.n_operations, symprec);
#      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
spglib-2.6.0/include/spglib.h:327:13: note: declared here
#  327 | SPG_API int spg_get_hall_number_from_symmetry(int const rotation[][3][3],
#      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  656|                                              Translations const &translations,
#  657|                                              py::float_ symprec) {
#  658|->     auto val = spg_get_hall_number_from_symmetry(
#  659|           rotations.data(), translations.data(), rotations.n_operations, symprec);
#  660|       if (val == 0) throw Spglib_classic_exception();

@LecrisUT LecrisUT deleted the feat/python-checks branch November 20, 2025 13:52
@LecrisUT
Copy link
Copy Markdown
Collaborator Author

Those are first-party deprecations (stuff we deprecated but we still offer the python interface).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-changes Changes that are incompatible with previous release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incompatible function arguments in develop version

4 participants