Skip to content

Make OutputBuffer._chmod_readonly work on read-only file systems - #43035

Merged
vbraun merged 1 commit into
sagemath:developfrom
ConnorBaker:rich-output-read-only-fs
Oct 28, 2026
Merged

vbraun merged 1 commit into
sagemath:developfrom
ConnorBaker:rich-output-read-only-fs

Conversation

@ConnorBaker

Copy link
Copy Markdown
Contributor

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 buffer.py: make files readonly only when possible #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

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

None.

🤖 Generated with Claude Code

_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>

@fchapoton fchapoton left a comment

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.

ok, looks good

vbraun pushed a commit to vbraun/sage that referenced this pull request Oct 23, 2026
Release Manager
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
ConnorBaker marked this pull request as ready for review October 23, 2026 22:03
@ConnorBaker

Copy link
Copy Markdown
Contributor Author

Should be ready to merge, assuming everything looks okay.

@fchapoton

Copy link
Copy Markdown
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
Release Manager
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
@vbraun
vbraun merged commit e81d21b into sagemath:develop Oct 28, 2026
13 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants