hostdev 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl

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.
hostdev/core.py CHANGED
@@ -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}
@@ -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
@@ -2,12 +2,12 @@ hostdev/__init__.py,sha256=iTdiN_UtMtX6sf2ktKMep16H6qVFYWI5W_GLy4YlaTk,89
2
2
  hostdev/__main__.py,sha256=nKqPCjXdmNIrEF7XYEFjhtxe21Vq9zRfQaHYtfJCPAQ,121
3
3
  hostdev/airdrop.swift,sha256=Mv98b83iDkuAfin8JTSmUm82XbpLx8St-RbccH--9ms,821
4
4
  hostdev/cli.py,sha256=OpALjsR9Rwd8FkBzA-u8KiAuGF0LwByJk8fBBi4nlK8,3126
5
- hostdev/core.py,sha256=nQbd35hI1ekxYlo2Cgk4HWqR5I34lH-UILr2_UgPZSI,14522
5
+ hostdev/core.py,sha256=F2Z6IAvPAnPNWRAq-vlK4qZKUw-xoJLm0D_0AddTWLQ,15335
6
6
  hostdev/interactive.py,sha256=jzRP0Df01Xmc_Kb496BbxEPVeAseQVgeILWtd2BzXso,4416
7
7
  hostdev/mdns.py,sha256=AGwIAQ-sAbr6vIMF6bHZ-9yGzRgMnTE-bX39v4ftCJ8,2564
8
8
  hostdev/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- hostdev-0.2.0.dist-info/METADATA,sha256=6aNu3-6DWiNggxme1zlFhNjwLbQVF6jFLPJngkJRXCE,5185
10
- hostdev-0.2.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
- hostdev-0.2.0.dist-info/entry_points.txt,sha256=4iUHoUm0irBjEhnsOywuKmisTvLEqeCJ_dRN2QSsTGQ,45
12
- hostdev-0.2.0.dist-info/licenses/LICENSE,sha256=cXHchnnJ1eh89mx5Q2bNPTJ0r9Mr3vpJNzUtOw59yPE,11339
13
- hostdev-0.2.0.dist-info/RECORD,,
9
+ hostdev-0.2.1.dist-info/METADATA,sha256=1QA-gmunE-JY_FBmX5bqhcXg0Csl1K5KICmB3qDNinU,5203
10
+ hostdev-0.2.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
+ hostdev-0.2.1.dist-info/entry_points.txt,sha256=4iUHoUm0irBjEhnsOywuKmisTvLEqeCJ_dRN2QSsTGQ,45
12
+ hostdev-0.2.1.dist-info/licenses/LICENSE,sha256=cXHchnnJ1eh89mx5Q2bNPTJ0r9Mr3vpJNzUtOw59yPE,11339
13
+ hostdev-0.2.1.dist-info/RECORD,,