Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bmwant
Copy link
Owner

@bmwant bmwant commented Aug 12, 2025

Description

  • Implement proper unbound status
  • Add inactive run_via_spawn method to support non-forking environments

Copy link

Copilot AI left a 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)
Copy link

Copilot AI Aug 12, 2025

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.

Suggested change
hapless._wrap_subprocess(hap)
hapless.wrap_subprocess(hap)

Copilot uses AI. Check for mistakes.
sys.exit(1)

proc = subprocess.Popen(
[f"{exec_path}", f"{hap.hid}"],
Copy link

Copilot AI Aug 12, 2025

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].

Suggested change
[f"{exec_path}", f"{hap.hid}"],
[exec_path, hap.hid],

Copilot uses AI. Check for mistakes.
TRUNCATE_LENGTH = 36
RESTART_DELIM = "@"

NO_FORK = bool(os.getenv("HAPLESS_NO_FORK", default=""))
Copy link

Copilot AI Aug 12, 2025

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")).

Suggested change
NO_FORK = bool(os.getenv("HAPLESS_NO_FORK", default=""))
NO_FORK = bool(os.getenv("HAPLESS_NO_FORK"))

Copilot uses AI. Check for mistakes.
hapless/main.py Outdated
self._wrap_subprocess(hap)
return

# TODO: or os.platform == win32
Copy link

Copilot AI Aug 12, 2025

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".

Suggested change
# TODO: or os.platform == win32
# TODO: or os.platform == "win32"

Copilot uses AI. Check for mistakes.
@bmwant bmwant merged commit bd49e37 into main Aug 12, 2025
8 checks passed
@bmwant bmwant deleted the add-spawn-wrapper branch August 15, 2025 12:32
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.

2 participants