-
Notifications
You must be signed in to change notification settings - Fork 4
Windows support preparation #1 #56
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
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 prepares the hapless library for Windows support by introducing an alternative process spawning mechanism. The primary goal is to provide a non-fork-based approach for running background processes, which is necessary since Windows doesn't support fork().
Key changes include:
- Added a new wrapper-based process spawning mechanism as an alternative to fork
- Introduced configuration option to disable forking via environment variable
- Updated status handling to properly report unbound haps
- Refactored CLI utilities into a shared module
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
tools/create_hap.py |
Added simple tool for creating test haps |
tests/test_lib_usage.py |
Updated test to expect UNBOUND status instead of FAILED |
tests/test_hapless.py |
Updated test method names from _run_hap_subprocess to _wrap_subprocess |
tests/test_hap.py |
Fixed test to expect UNBOUND status and import Status enum |
pyproject.toml |
Added new hapwrap CLI entry point |
hapless/wrapper.py |
New wrapper module for spawning processes without fork |
hapless/main.py |
Refactored to support both fork and spawn-based process creation |
hapless/hap.py |
Added UNBOUND status detection logic |
hapless/config.py |
Added NO_FORK configuration option |
hapless/cli_utils.py |
Extracted shared CLI utilities into separate module |
hapless/cli.py |
Refactored to use shared CLI utilities |
| with open(hap.stderr_path, "a") as f: | ||
| f.write(f"Hap {hap} has to be unbound, found instead {hap.status}\n") | ||
| return | ||
| hapless._wrap_subprocess(hap) |
Copilot
AI
Aug 12, 2025
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.
Accessing a private method _wrap_subprocess from outside the class violates encapsulation. Consider making this method public or providing a public API for this functionality.
| hapless._wrap_subprocess(hap) | |
| hapless.wrap_subprocess(hap) |
| sys.exit(1) | ||
|
|
||
| proc = subprocess.Popen( | ||
| [f"{exec_path}", f"{hap.hid}"], |
Copilot
AI
Aug 12, 2025
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.
The f-string formatting is unnecessary here since exec_path and hap.hid are already strings. This should be simplified to [exec_path, hap.hid].
| [f"{exec_path}", f"{hap.hid}"], | |
| [exec_path, hap.hid], |
| TRUNCATE_LENGTH = 36 | ||
| RESTART_DELIM = "@" | ||
|
|
||
| NO_FORK = bool(os.getenv("HAPLESS_NO_FORK", default="")) |
Copilot
AI
Aug 12, 2025
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.
The default="" parameter is redundant since os.getenv already returns None by default, and bool(None) is False. This should be simplified to bool(os.getenv("HAPLESS_NO_FORK")).
| NO_FORK = bool(os.getenv("HAPLESS_NO_FORK", default="")) | |
| NO_FORK = bool(os.getenv("HAPLESS_NO_FORK")) |
hapless/main.py
Outdated
| self._wrap_subprocess(hap) | ||
| return | ||
|
|
||
| # TODO: or os.platform == win32 |
Copilot
AI
Aug 12, 2025
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.
The comment has a typo - win32 should be quoted as a string: "win32".
| # TODO: or os.platform == win32 | |
| # TODO: or os.platform == "win32" |
Description
unboundstatusrun_via_spawnmethod to support non-forking environments