Fix the Windows check in the man page lookup - #1937
Conversation
`is_available()` guarded on `os.system == 'nt'`, comparing the built-in function to a string, so the branch was never taken. On Windows the lookup fell through to running `man` and only returned False because the resulting FileNotFoundError was swallowed -- where a `man` is on PATH, from Git Bash or WSL, HTTPie went on to render man pages. Use `is_windows` from `httpie.compat`, which the rest of the codebase already uses for this.
|
Heads-up for whoever reviews this: the failing The same failures are present on Every This PR touches one line in |
Closes #1898.
Problem
httpie/output/ui/man_pages.pyguards onos.system == 'nt', which compares the built-in functionos.systemto a string. That is never true, so the Windows branch is dead code.I happened to be on Windows, so I could check the actual behaviour rather than just read it. Simulating a
manonPATH, which is what you get with Git Bash or WSL installed:So it isn't only that the comparison is wrong — HTTPie really does go on to shell out to
manon Windows and, if one is present, renders man pages. Where nomanexists the function still returnsFalse, but only because theFileNotFoundErroris caught by the bareexcept Exception, which is accidental rather than intended.After the change, on the same machine:
Fix
httpie/compat.pyalready definesis_windows, andconfig.py,context.py,uploads.py,internal/daemons.pyandoutput/writer.pyall use it. Reusing it keeps the platform check in one place:The issue suggested
sys.platform == 'win32', which is whatis_windowsis defined as — this just routes through the existing constant instead of adding a second spelling.httpie.contextalready imports fromhttpie.compat, so this introduces no new dependency or import cycle.Tests
There were no tests for this module, which is how the guard stayed broken. Added
tests/test_man_pages.pycovering the Windows short-circuit, theHTTPIE_NO_MAN_PAGESshort-circuit, and the three outcomes of themancall — found, not found, andmannot installed. The two short-circuit cases assert thatsubprocess.runis never reached, since that is the actual point of the guard.The tests patch the module-level flags rather than the real platform, so they exercise the Windows path on any OS.
flake8is clean on both files.I also ran
tests/test_cli_ui.py,tests/test_cli_utils.pyand the doctests underhttpie/outputandhttpie/cli. One unrelated failure,test_cli_utils.py::test_lazy_choices_help, is pre-existing — it fails identically with this change stashed, and is a Python 3.14 argparse behaviour change (the lazygetteris now called during help formatting). I did not run the full suite, as thedevextra pinswerkzeug<2.1.0, which will not install on 3.14.Changelog
Added an entry under a new
3.2.5-dev (unreleased)heading, following the format of the3.3.0-devsection used before the 3.2.2 release. I guessed the version number sincemasterhad no unreleased section — happy to renumber or drop it.