Skip to content

fix: add missing shutil import in setup.py (fixes #5060) - #5108

Closed
Sertug17 wants to merge 1 commit into
NousResearch:mainfrom
Sertug17:fix/shutil-import-setup-e2ee
Closed

fix: add missing shutil import in setup.py (fixes #5060)#5108
Sertug17 wants to merge 1 commit into
NousResearch:mainfrom
Sertug17:fix/shutil-import-setup-e2ee

Conversation

@Sertug17

@Sertug17 Sertug17 commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Problem

When running hermes setup with E2EE enabled, the setup wizard crashes at
line 2126 of setup.py with NameError: name 'shutil' is not defined.

This happens because:

  1. matrix-nio[e2e] fails to import (ModuleNotFoundError)
  2. The except handler tries to locate uv via shutil.which("uv")
  3. But shutil was never imported at the module level — only locally
    inside other functions (lines 951, 1397, 1513)

Fix

Add import shutil at the top of hermes_cli/setup.py alongside the
other standard library imports.

Fixes #5060

@trevorgordon981

Copy link
Copy Markdown
Contributor

Correct one-line fix for a real crash path — NameError: name 'shutil' is not defined when E2EE setup's except handler tries shutil.which("uv").

Two of the local import shutil calls inside other functions (lines 1121 and 1308 on current main) become redundant after this PR — Python resolves the module-level import first. Not a blocker, but worth cleaning up either now or in a follow-up so there's one import location and new contributors don't wonder why shutil is imported three times in one file.

# hermes_cli/setup.py now has:
# line ~17: import shutil   (this PR — good)
# line 1121: import shutil  (redundant, dead-ish import)
# line 1308: import shutil  (redundant, dead-ish import)

ruff's F811 (redefined-while-unused) catches this pattern if the linter config includes it.

Ship it — fixes the actual crash. The redundant-import cleanup can happen whenever someone touches those functions next.

@Sertug17

Sertug17 commented Apr 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Agreed on the redundant imports — happy to clean those up in this PR if preferred, rather than waiting for a follow-up.

@trevorgordon981 I see you've opened #5136 — should I incorporate that cleanup here, or would you prefer to keep them separate?

@teknium1

teknium1 commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #5271 using #5136's implementation (which includes a regression test). Your fix was identical and correct — both contributors credited. Thanks!

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.

NameError: name 'shutil' is not defined in setup.py when enabling E2EE

3 participants