Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add file_version property to XML writers#8190

Draft
tkoyama010 wants to merge 12 commits intomainpyvista/pyvista:mainfrom
feat/add-setfileversion-optionpyvista/pyvista:feat/add-setfileversion-optionCopy head branch name to clipboard
Draft

Add file_version property to XML writers#8190
tkoyama010 wants to merge 12 commits intomainpyvista/pyvista:mainfrom
feat/add-setfileversion-optionpyvista/pyvista:feat/add-setfileversion-optionCopy head branch name to clipboard

Conversation

@tkoyama010
Copy link
Copy Markdown
Member

Overview

This PR adds a file_version property to XML writers that allows users to get and set the VTK XML file format version (major and minor).

Different VTK XML file versions may support different features or compression methods. This property provides a convenient way to control the file version when writing XML files.

Details

  • Add file_version property (getter and setter) to _XMLWriter base class
  • Validate input: must be a tuple of two integers (major, minor)
  • Gracefully handle VTK versions that don't support these methods (returns (None, None) for getter, raises AttributeError for setter)
  • Add comprehensive tests for both normal usage and validation of invalid inputs

This adds a file_version property to the _XMLWriter base class that allows
users to get and set the VTK XML file format version (major and minor).

The property includes proper version checking and gracefully handles cases
where the underlying VTK methods (SetDataSetMajorVersion and
SetDataSetMinorVersion) are not available in the VTK version being used.

Returns (None, None) when getting the version if methods are not available,
and raises AttributeError with a helpful message when trying to set the
version without VTK support.
Add comprehensive tests for the file_version property in XMLPolyDataWriter:
- Test normal cases: setting valid file_version tuples like (2, 2) and (1, 0)
- Test validation: verify proper exceptions for invalid inputs
  - TypeError for non-tuple inputs (list)
  - ValueError for wrong tuple length
  - TypeError for non-int values in tuple
- Gracefully skip tests when VTK doesn't support file_version methods

The test uses pytest.parametrize to test multiple invalid input scenarios
and properly handles VTK builds that don't have SetDataSetMajorVersion/
SetDataSetMinorVersion methods.
Copilot AI review requested due to automatic review settings December 25, 2025 14:19
@pyvista-bot pyvista-bot added the enhancement Changes that enhance the library label Dec 25, 2025
Comment thread pyvista/core/utilities/writer.py
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a file_version property to the _XMLWriter base class, enabling users to get and set the VTK XML file format version (major and minor version numbers). This provides control over which VTK XML file format features and compression methods are available when writing files.

  • Added property getter/setter with comprehensive input validation
  • Gracefully handles older VTK versions that don't support file version methods
  • Includes extensive tests for both valid inputs and validation of various invalid input types

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
pyvista/core/utilities/writer.py Implements file_version property in _XMLWriter base class with getter, setter, validation logic, and VTK version compatibility handling
tests/core/test_utilities.py Adds parametrized test covering valid file version values and validation of multiple invalid input types

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pyvista/core/utilities/writer.py
Comment thread tests/core/test_utilities.py
Comment thread tests/core/test_utilities.py
Comment thread pyvista/core/utilities/writer.py
Comment thread pyvista/core/utilities/writer.py
Comment thread pyvista/core/utilities/writer.py Outdated
Comment thread pyvista/core/utilities/writer.py
tkoyama010 and others added 2 commits December 25, 2025 23:26
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Fix mypy error: change type annotation from tuple[int, int] to tuple[int, ...]
  to allow runtime validation of tuple length
- Move pyvista import out of TYPE_CHECKING block since it's used at runtime
- Fix pytest.parametrize to use tuple for parameter names
- Apply code formatting fixes (ruff, trailing whitespace)
@tkoyama010 tkoyama010 marked this pull request as draft December 25, 2025 14:49
@pyvista-bot
Copy link
Copy Markdown
Contributor

pyvista-bot commented Dec 25, 2025

@pyvista-bot pyvista-bot temporarily deployed to pull request December 25, 2025 15:07 Inactive
Comment thread pyvista/core/utilities/writer.py Outdated
Comment thread pyvista/core/utilities/writer.py Outdated
@tkoyama010 tkoyama010 marked this pull request as ready for review December 25, 2025 20:17
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 25, 2025

Codecov Report

❌ Patch coverage is 52.94118% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.60%. Comparing base (574b7fe) to head (b2a4e6d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8190      +/-   ##
==========================================
- Coverage   96.62%   96.60%   -0.03%     
==========================================
  Files         161      161              
  Lines       34908    34925      +17     
  Branches     4418     4419       +1     
==========================================
+ Hits        33729    33738       +9     
- Misses        574      581       +7     
- Partials      605      606       +1     

@pyvista-bot pyvista-bot temporarily deployed to pull request December 25, 2025 20:48 Inactive
@tkoyama010 tkoyama010 enabled auto-merge (squash) March 3, 2026 18:00
Comment thread pyvista/core/utilities/writer.py Outdated
Comment thread pyvista/core/utilities/writer.py Outdated
Comment thread pyvista/core/utilities/writer.py Outdated
Comment thread pyvista/core/utilities/writer.py Outdated
@pyvista-bot pyvista-bot temporarily deployed to pull request March 3, 2026 18:40 Inactive
Copy link
Copy Markdown
Contributor

@user27182 user27182 left a comment

Choose a reason for hiding this comment

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

Seems like this feature is a bit broken and isn't currently working as expected.

Comment on lines +532 to +533
>>> writer.file_version = (2, 2) # doctest:+SKIP
>>> writer.file_version # doctest:+SKIP
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why skip? When I run this example locally with VTK 9.6, I get (None, None), seems something isn't working?

import pyvista as pv
writer = pv.XMLPolyDataWriter('sphere.vtp', pv.Sphere())
print(writer.file_version)  # (None, None)
writer.writer.GetDataSetMajorVersion()  # AttributeError

Comment on lines +557 to +560
hasattr(self.writer, 'SetDataSetMajorVersion')
and hasattr(self.writer, 'SetDataSetMinorVersion')
): # pragma: no cover
msg = (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why no cover? We should have coverage for this automatically for both older vtk (< 9.3) and newer if it's only missing for < 9.3.

Recommend also using pv.vtk_version_info < 9.3 instead, since that will automatically raise an error when < 9.3 is no longer support and hence will help us remove this version branch later.

Comment on lines +546 to +547
@file_version.setter
def file_version(self, version: tuple[int, ...]) -> None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems odd to me that users can set this to any arbitrary value. Surely this should be restricted to specific values supported by VTK? Otherwise it seems users can set version to (42, 99) if they want?

Moreover, looking at the class members for "S" https://vtk.org/doc/nightly/html/functions_s.html#index_s, we can see that only the hyper tree grid writer supports this, so this setter basically doesn't work at all for any of our writers.

Image

Comment on lines +3144 to +3150
try:
writer.file_version = (2, 2)
assert writer.file_version == (2, 2)
writer.file_version = (1, 0)
assert writer.file_version == (1, 0)
except AttributeError:
# Skip if VTK version doesn't support file_version setter
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When I run this test locally with VTK 9.6, everything is skipped. This would explain the missing coverage.
Image

We should not unconditionally skip this test on attribute error. We should instead use @pytest.mark.needs_vtk_version(9,3,0), and then test the attribute error being raised with a separate test.

Or, include vtk version-specific branches inside the test.

@banesullivan banesullivan marked this pull request as draft April 15, 2026 01:31
auto-merge was automatically disabled April 15, 2026 01:31

Pull request was converted to draft

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

Labels

enhancement Changes that enhance the library

Development

Successfully merging this pull request may close these issues.

4 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.