hostdev 0.2.0__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hostdev",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Serve local development servers at https://<name>.localhost and on the LAN, through Caddy, with no port to remember.",
5
5
  "author": {
6
6
  "name": "Giovanni Porcari"
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.1] - 2026-12-03
11
+
12
+ ### Fixed
13
+
14
+ - `start` gives an error when the application stops in the 3 seconds after its port
15
+ listens. Before, it gave the link and Caddy answered 502.
16
+
17
+ ### Changed
18
+
19
+ - A `start` that succeeds takes 3 seconds more.
20
+
10
21
  ## [0.2.0] - 2026-12-03
11
22
 
12
23
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: hostdev
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Serve local development servers at https://<name>.localhost and on the LAN, through Caddy.
5
5
  Project-URL: Repository, https://github.com/genro/hostdev
6
6
  Author: Giovanni Porcari
@@ -60,9 +60,11 @@ Requirements: macOS, Homebrew, Python 3.9 or later.
60
60
  As a command:
61
61
 
62
62
  ```bash
63
- uv tool install git+https://github.com/genro/hostdev
63
+ uv tool install hostdev
64
64
  ```
65
65
 
66
+ `pipx install hostdev` gives the same result.
67
+
66
68
  As a Claude Code plugin:
67
69
 
68
70
  ```bash
@@ -41,9 +41,11 @@ Requirements: macOS, Homebrew, Python 3.9 or later.
41
41
  As a command:
42
42
 
43
43
  ```bash
44
- uv tool install git+https://github.com/genro/hostdev
44
+ uv tool install hostdev
45
45
  ```
46
46
 
47
+ `pipx install hostdev` gives the same result.
48
+
47
49
  As a Claude Code plugin:
48
50
 
49
51
  ```bash
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "hostdev"
7
- version = "0.2.0"
7
+ version = "0.2.1"
8
8
  description = "Serve local development servers at https://<name>.localhost and on the LAN, through Caddy."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -27,6 +27,7 @@ from pathlib import Path
27
27
  DEFAULT_STATE_DIR = Path.home() / ".local" / "state" / "hostdev"
28
28
  PORT_RANGE = range(8100, 8200)
29
29
  START_TIMEOUT = 90 # seconds until the port must listen
30
+ SETTLE_TIME = 3 # seconds that the application must stay alive after the port listens
30
31
  CADDY_ADMIN_PORT = 2019
31
32
  SITE = "{names} {{\n\ttls internal\n\treverse_proxy 127.0.0.1:{port}\n}}\n"
32
33
  IMPORT_COMMENT = "# Local sites of hostdev: one file per host, written by hostdev.\n"
@@ -86,14 +87,19 @@ def listening(port):
86
87
  class HostDev:
87
88
  """The local applications of one state folder."""
88
89
 
89
- def __init__(self, state_dir=None, caddyfile=None):
90
+ def __init__(self, state_dir=None, caddyfile=None, settle_time=SETTLE_TIME):
90
91
  self._state_dir = Path(state_dir) if state_dir else DEFAULT_STATE_DIR
91
92
  self._caddyfile = Path(caddyfile) if caddyfile else None
93
+ self._settle_time = settle_time
92
94
 
93
95
  @property
94
96
  def state_dir(self):
95
97
  return self._state_dir
96
98
 
99
+ @property
100
+ def settle_time(self):
101
+ return self._settle_time
102
+
97
103
  @property
98
104
  def sites_dir(self):
99
105
  return self.state_dir / "sites"
@@ -242,6 +248,24 @@ class HostDev:
242
248
 
243
249
  # ---------------------------------------------------------- start / stop
244
250
 
251
+ def started(self, process, port):
252
+ """True when the application listens on ``port`` and still runs after ``settle_time``.
253
+
254
+ Some servers open the port first and load the application after. A failure of
255
+ that load stops the process a moment after the port listens.
256
+ """
257
+ deadline = time.monotonic() + START_TIMEOUT
258
+ while not listening(port):
259
+ if process.poll() is not None or time.monotonic() > deadline:
260
+ return False
261
+ time.sleep(0.5)
262
+ settled = time.monotonic() + self.settle_time
263
+ while time.monotonic() < settled:
264
+ if process.poll() is not None:
265
+ return False
266
+ time.sleep(0.1)
267
+ return listening(port)
268
+
245
269
  def start(self, cwd=".", name=None, instance=None, config=None, lan=False,
246
270
  command=None, port=None, path="/"):
247
271
  """Start one application. ``command`` with ``port`` replaces launch.json."""
@@ -266,14 +290,11 @@ class HostDev:
266
290
  process = subprocess.Popen(argv, cwd=cwd, stdout=output, stderr=subprocess.STDOUT,
267
291
  env={**os.environ, "PORT": str(chosen)},
268
292
  start_new_session=True)
269
- deadline = time.monotonic() + START_TIMEOUT
270
- while not listening(chosen):
271
- if process.poll() is not None or time.monotonic() > deadline:
272
- if process.poll() is None:
273
- os.killpg(process.pid, signal.SIGTERM)
274
- return {"error": "The application did not start.", "log": str(log),
275
- "tail": log.read_text()[-1500:]}
276
- time.sleep(0.5)
293
+ if not self.started(process, chosen):
294
+ if process.poll() is None:
295
+ os.killpg(process.pid, signal.SIGTERM)
296
+ return {"error": "The application did not start.", "log": str(log),
297
+ "tail": log.read_text()[-1500:]}
277
298
  entry = {"port": chosen, "pid": process.pid, "cwd": cwd, "log": str(log),
278
299
  "command": argv, "path": launch.get("path", "/"),
279
300
  "lan_pid": self.publish(host) if lan else None}
@@ -26,7 +26,7 @@ class LocalHostDev(HostDev):
26
26
  @pytest.fixture
27
27
  def hostdev(tmp_path):
28
28
  caddyfile = tmp_path / "Caddyfile"
29
- instance = LocalHostDev(state_dir=tmp_path / "state", caddyfile=caddyfile)
29
+ instance = LocalHostDev(state_dir=tmp_path / "state", caddyfile=caddyfile, settle_time=0.3)
30
30
  yield instance
31
31
  for host in list(instance.read_instances()):
32
32
  instance.stop(host)
@@ -1,6 +1,8 @@
1
1
  import json
2
+ import sys
2
3
 
3
4
  import pytest
5
+ from conftest import LocalHostDev
4
6
 
5
7
  from hostdev.core import PORT_RANGE, alive, listening
6
8
 
@@ -60,6 +62,21 @@ def test_start_reports_an_application_that_does_not_start(hostdev, tmp_path):
60
62
  assert hostdev.read_instances() == {}
61
63
 
62
64
 
65
+ def test_start_reports_an_application_that_stops_after_the_port_listens(tmp_path):
66
+ late = ("import socket, sys, time; s = socket.socket(); "
67
+ "s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1); "
68
+ "s.bind(('127.0.0.1', int(sys.argv[1]))); s.listen(); time.sleep(0.5); "
69
+ "print('late failure'); sys.exit(3)")
70
+ hostdev = LocalHostDev(state_dir=tmp_path / "state", caddyfile=tmp_path / "Caddyfile",
71
+ settle_time=2)
72
+ result = hostdev.start(cwd=str(tmp_path), name="late", port=8000,
73
+ command=[sys.executable, "-c", late, "8000"])
74
+ assert result["error"] == "The application did not start."
75
+ assert "late failure" in result["tail"]
76
+ assert hostdev.read_instances() == {}
77
+ assert not (hostdev.sites_dir / "late.localhost.caddy").exists()
78
+
79
+
63
80
  def test_start_with_lan_adds_the_lan_name_to_the_site(hostdev, project):
64
81
  result = hostdev.start(cwd=str(project), instance="v1", lan=True)
65
82
  assert result["lan_url"] == "https://v1-my-app.local/app/"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes