-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor write_docx to accept LibreOfficeConverter + improve executable path handling
#172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- 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.
There was a problem hiding this 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-onlyconverter=parameter instead ofexecutable_pathargument - Enhanced Executable Resolution:
LibreOfficeConvertercan now acceptPathobjects, resolve executable names viaPATH, and checksPATHbefore 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.
Co-authored-by: Copilot <[email protected]>
This PR improves the DOCX export and LibreOffice integration by making conversion configuration explicit and reusable.
write_docxchanges:RTFDocument.write_docxto accept a keyword-onlyconverter=instance instead of anexecutable_pathargument. This enables passing a pre-configuredLibreOfficeConverter(custom executable path, reuse across conversions).Converter changes:
LibreOfficeConverter(executable_path=...)to acceptPathobjects and resolve executable names viaPATH.LibreOfficeConverter()also now checksPATHforsoffice/libreofficebefore platform default paths.