Repository navigation
Make OutputBuffer._chmod_readonly work on read-only file systems - #43035
Merged
Merged
Conversation
_chmod_readonly() ignored only PermissionError from os.chmod. On a read-only file system chmod fails with EROFS instead, so loading a rich output file raised even when it was already read-only. Skip chmod when the file has no write bits, and ignore any OSError otherwise. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 of 13 tasks
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Oct 23, 2026
sagemathgh-43035: Make OutputBuffer._chmod_readonly work on read-only file systems `OutputBuffer.from_file()` calls `_chmod_readonly()` to make the file read-only. `_chmod_readonly()` skips the bundled rich-output example files under `SAGE_SRC`, and otherwise calls `os.chmod`, ignoring only `PermissionError`. That isn't enough when Sage is installed on a read-only file system. There, `chmod` fails with `EROFS`, which is an `OSError` but not a `PermissionError`, so the exception propagates, even though the file is already read-only and there's nothing to change. We hit this downstream in Nixpkgs. Sage is installed in the read-only Nix store, so the example files aren't under `SAGE_SRC`. On build machines that mount the store read-only, 49 doctests in `repl/rich_output/{backend_doctest,output_graphics3d,output_video}.py` fail with `OSError: [Errno 30] Read-only file system`. They pass on machines where `chmod` fails with `EPERM` instead. This PR: - returns early when the file has no write bits, so a file that's already read-only isn't touched at all; - otherwise ignores any `OSError` from `chmod`, not just `PermissionError`. The function is best effort, as the original `except PermissionError` (from sagemath#33256) already treats it. New doctests in a `TESTS` block cover both cases. I ran the full doctest suite (`sage -t --long`, all 4206 files) with this change applied to 10.9, on a machine where the install is read-only. Everything passed, including the 49 doctests that failed before. Suggested labels (I can't set them): `t: bug`, `c: user interface`, `p: minor / 4`. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies None. 🤖 Generated with [Claude Code](https://claude.com/claude-code) URL: sagemath#43035 Reported by: Connor Baker Reviewer(s): Frédéric Chapoton
ConnorBaker
marked this pull request as ready for review
October 23, 2026 22:03
Contributor
Author
|
Should be ready to merge, assuming everything looks okay. |
Contributor
|
do not touch this anymore. Justy be very patient |
vbraun
pushed a commit
to vbraun/sage
that referenced
this pull request
Oct 27, 2026
sagemathgh-43035: Make OutputBuffer._chmod_readonly work on read-only file systems `OutputBuffer.from_file()` calls `_chmod_readonly()` to make the file read-only. `_chmod_readonly()` skips the bundled rich-output example files under `SAGE_SRC`, and otherwise calls `os.chmod`, ignoring only `PermissionError`. That isn't enough when Sage is installed on a read-only file system. There, `chmod` fails with `EROFS`, which is an `OSError` but not a `PermissionError`, so the exception propagates, even though the file is already read-only and there's nothing to change. We hit this downstream in Nixpkgs. Sage is installed in the read-only Nix store, so the example files aren't under `SAGE_SRC`. On build machines that mount the store read-only, 49 doctests in `repl/rich_output/{backend_doctest,output_graphics3d,output_video}.py` fail with `OSError: [Errno 30] Read-only file system`. They pass on machines where `chmod` fails with `EPERM` instead. This PR: - returns early when the file has no write bits, so a file that's already read-only isn't touched at all; - otherwise ignores any `OSError` from `chmod`, not just `PermissionError`. The function is best effort, as the original `except PermissionError` (from sagemath#33256) already treats it. New doctests in a `TESTS` block cover both cases. I ran the full doctest suite (`sage -t --long`, all 4206 files) with this change applied to 10.9, on a machine where the install is read-only. Everything passed, including the 49 doctests that failed before. Suggested labels (I can't set them): `t: bug`, `c: user interface`, `p: minor / 4`. ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies None. 🤖 Generated with [Claude Code](https://claude.com/claude-code) URL: sagemath#43035 Reported by: Connor Baker Reviewer(s): Frédéric Chapoton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OutputBuffer.from_file()calls_chmod_readonly()to make the file read-only._chmod_readonly()skips the bundled rich-output example files underSAGE_SRC, and otherwise callsos.chmod, ignoring onlyPermissionError.That isn't enough when Sage is installed on a read-only file system. There,
chmodfails withEROFS, which is anOSErrorbut not aPermissionError, so the exception propagates, even though the file is already read-only and there's nothing to change.We hit this downstream in Nixpkgs. Sage is installed in the read-only Nix store, so the example files aren't under
SAGE_SRC. On build machines that mount the store read-only, 49 doctests inrepl/rich_output/{backend_doctest,output_graphics3d,output_video}.pyfail withOSError: [Errno 30] Read-only file system. They pass on machines wherechmodfails withEPERMinstead.This PR:
OSErrorfromchmod, not justPermissionError. The function is best effort, as the originalexcept PermissionError(from buffer.py: make files readonly only when possible #33256) already treats it.New doctests in a
TESTSblock cover both cases. I ran the full doctest suite (sage -t --long, all 4206 files) with this change applied to 10.9, on a machine where the install is read-only. Everything passed, including the 49 doctests that failed before.Suggested labels (I can't set them):
t: bug,c: user interface,p: minor / 4.📝 Checklist
⌛ Dependencies
None.
🤖 Generated with Claude Code