Skip to content

Conversation

@nanxstats
Copy link
Collaborator

@nanxstats nanxstats commented Dec 26, 2025

This PR improves the DOCX export and LibreOffice integration by making conversion configuration explicit and reusable.

write_docx changes:

  • Refactors RTFDocument.write_docx to accept a keyword-only converter= instance instead of an executable_path argument. This enables passing a pre-configured LibreOfficeConverter (custom executable path, reuse across conversions).

Converter changes:

  • Enhances LibreOfficeConverter(executable_path=...) to accept Path objects and resolve executable names via PATH.
  • LibreOfficeConverter() also now checks PATH for soffice/libreoffice before platform default paths.

- Refactor `write_docx` to take a keyword-only `converter=` instead of an `executable_path` string.
- Keep LibreOffice-specific configuration on `LibreOfficeConverter` and prevent signature bloat as more converter knobs show up.
…ecutable via `PATH`

- Update `LibreOfficeConverter(executable_path=...)` to accept `str | Path`, normalize via `os.fspath`, and store a `Path`.
- Also made `executable_path="soffice"/"libreoffice"` resolve via `PATH` using `shutil.which` (and `LibreOfficeConverter()` now checks `PATH` before platform default paths).
- Added non-LibreOffice-dependent tests covering Path inputs + `PATH` resolution.
Copy link
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 refactors the DOCX export API to make LibreOffice converter configuration more explicit and flexible by accepting a converter instance parameter instead of an executable_path string.

Key Changes

  • API Breaking Change: RTFDocument.write_docx() now accepts a keyword-only converter= parameter instead of executable_path argument
  • Enhanced Executable Resolution: LibreOfficeConverter can now accept Path objects, resolve executable names via PATH, and checks PATH before falling back to platform-specific default paths
  • Test Updates: Tests refactored to verify the new converter parameter behavior and executable path resolution logic

Reviewed changes

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

Show a summary per file
File Description
src/rtflite/encode.py Refactored write_docx() to accept converter= instance parameter and moved converter instantiation inside the method
src/rtflite/convert.py Enhanced LibreOfficeConverter.__init__() to accept Path objects, resolve executable names via shutil.which, and check PATH before default platform paths
tests/test_write_docx_args.py Updated tests to verify new converter parameter API - one for provided converter instance, one for default converter creation
tests/test_convert_executable_path.py Added new tests for executable path resolution including Path objects, shutil.which resolution, and error cases
docs/changelog.md Added version 2.4.0 changelog documenting API changes and converter enhancements
CHANGELOG.md Added version 2.4.0 changelog documenting API changes and converter enhancements

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

@elong0527 elong0527 merged commit abdc9d5 into main Dec 26, 2025
9 checks passed
@nanxstats nanxstats deleted the custom-libreoffice-path branch December 26, 2025 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants