static-php-py 0.1.5__tar.gz → 0.1.7__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.
- {static_php_py-0.1.5 → static_php_py-0.1.7}/PKG-INFO +3 -4
- {static_php_py-0.1.5 → static_php_py-0.1.7}/docs/design-api.md +4 -4
- {static_php_py-0.1.5 → static_php_py-0.1.7}/docs/design-modules.md +5 -5
- {static_php_py-0.1.5 → static_php_py-0.1.7}/docs/impl.md +5 -4
- {static_php_py-0.1.5 → static_php_py-0.1.7}/pyproject.toml +3 -4
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_sources/_discovery.py +2 -2
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_sources/_packaged.py +9 -2
- static_php_py-0.1.7/src/static_php_py/py.typed +0 -0
- static_php_py-0.1.7/tests/_sources/conftest.py +104 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/_sources/test_discovery.py +14 -19
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/_sources/test_integrity.py +10 -4
- static_php_py-0.1.7/tests/_sources/test_packaged.py +291 -0
- static_php_py-0.1.7/tests/_sources/test_packaged_selection.py +195 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/_sources/test_path.py +2 -59
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/_sources/test_remote_archive.py +15 -44
- static_php_py-0.1.7/tests/_sources/test_remote_checksum.py +157 -0
- static_php_py-0.1.7/tests/_sources/test_remote_containment.py +151 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/_sources/test_remote_download.py +57 -131
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/test_exceptions.py +16 -0
- static_php_py-0.1.7/tests/test_init.py +48 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/test_integration_exec.py +2 -42
- static_php_py-0.1.7/tests/test_integration_factory.py +50 -0
- static_php_py-0.1.7/tests/test_manifest.py +117 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/test_php_exec.py +47 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/test_php_factory.py +14 -2
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/test_php_require.py +29 -1
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/test_types.py +19 -14
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/test_version_fallback.py +16 -1
- static_php_py-0.1.5/src/static_php_py/_sources/_entrypoints.py +0 -22
- static_php_py-0.1.5/tests/_sources/test_entrypoints.py +0 -25
- static_php_py-0.1.5/tests/_sources/test_packaged.py +0 -294
- static_php_py-0.1.5/tests/_sources/test_remote_containment.py +0 -82
- static_php_py-0.1.5/tests/test_integration_factory.py +0 -116
- static_php_py-0.1.5/tests/test_manifest.py +0 -45
- {static_php_py-0.1.5 → static_php_py-0.1.7}/.gitignore +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/LICENSE +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/README.md +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/docs/concept.md +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/docs/design-discovery.md +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/docs/design-extraction.md +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/docs/design-packaged.md +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/docs/design-providers.md +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/docs/index.md +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/__init__.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_exceptions.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_execution.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_manifest.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_php.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_sources/__init__.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_sources/_cache.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_sources/_extraction.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_sources/_integrity.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_sources/_path.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_sources/_publishing.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_sources/_remote.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_types.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/src/static_php_py/_version.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/_sources/test_cache.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/_sources/test_remote_search.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/conftest.py +0 -0
- {static_php_py-0.1.5 → static_php_py-0.1.7}/tests/test_php_inspect.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: static-php-py
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
4
4
|
Summary: Python wrapper library for static PHP binaries; code-only execution library
|
|
5
5
|
Project-URL: Homepage, https://github.com/samhsu-dev/static-php-py
|
|
6
6
|
Project-URL: Repository, https://github.com/samhsu-dev/static-php-py
|
|
@@ -351,16 +351,15 @@ Classifier: Development Status :: 3 - Alpha
|
|
|
351
351
|
Classifier: Intended Audience :: Developers
|
|
352
352
|
Classifier: License :: OSI Approved :: GNU General Public License v2 (GPLv2)
|
|
353
353
|
Classifier: Programming Language :: Python :: 3
|
|
354
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
355
354
|
Classifier: Programming Language :: Python :: 3.10
|
|
356
355
|
Classifier: Programming Language :: Python :: 3.11
|
|
357
356
|
Classifier: Programming Language :: Python :: 3.12
|
|
358
357
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
359
|
-
Requires-Python: >=3.
|
|
358
|
+
Requires-Python: >=3.10
|
|
360
359
|
Requires-Dist: packaging>=21.0
|
|
361
360
|
Requires-Dist: platformdirs>=4.0.0
|
|
362
361
|
Provides-Extra: bundled
|
|
363
|
-
Requires-Dist: static-php-py-binary==0.1.
|
|
362
|
+
Requires-Dist: static-php-py-binary==0.1.5; extra == 'bundled'
|
|
364
363
|
Description-Content-Type: text/markdown
|
|
365
364
|
|
|
366
365
|
# static-php-py
|
|
@@ -95,17 +95,17 @@ php = PHP.remote("https://example.com/php-8.4.tar.gz", checksum="sha256:9f86d08.
|
|
|
95
95
|
- **Behavior**: Execute PHP script file. `ini` entries render as `-d key=value` options placed before the script path (after the script they would land in `$argv`); `input` is delivered as the process's standard-input text.
|
|
96
96
|
- **Input**: `script` - Path to PHP script, `args` - Script arguments, `input` - Standard-input text (None inherits the parent's stdin), `ini` - Per-invocation ini overrides, `timeout` - Execution timeout.
|
|
97
97
|
- **Output**: ExecutionResult with execution outcome.
|
|
98
|
-
- **Raises**: `FileNotFoundError` if script not found.
|
|
98
|
+
- **Raises**: `FileNotFoundError` if script not found. `ExecutionError` on execution timeout or when the binary cannot be launched.
|
|
99
99
|
- **[eval(code: str, *, input: str | None = None, ini: Mapping[str, str] | None = None, timeout: float | None = None) -> ExecutionResult]**
|
|
100
100
|
- **Behavior**: Execute PHP code string via php -r. `ini` entries render as `-d key=value` options placed before `-r`; `input` is delivered as the process's standard-input text.
|
|
101
101
|
- **Input**: `code` - PHP code to execute, `input` - Standard-input text (None inherits the parent's stdin), `ini` - Per-invocation ini overrides, `timeout` - Execution timeout.
|
|
102
102
|
- **Output**: ExecutionResult with execution outcome.
|
|
103
|
-
- **Raises**:
|
|
103
|
+
- **Raises**: `ExecutionError` on execution timeout or when the binary cannot be launched.
|
|
104
104
|
- **[version() -> str]**
|
|
105
|
-
- **Behavior**: Get PHP version string.
|
|
105
|
+
- **Behavior**: Get PHP version string, parsed from the binary's `--version` output in either reported format (`PHP X.Y.Z` or `static-php-cli X.Y.Z`).
|
|
106
106
|
- **Input**: None
|
|
107
107
|
- **Output**: Version string (e.g., "8.3.0").
|
|
108
|
-
- **Raises**:
|
|
108
|
+
- **Raises**: `ExecutionError` when the version query fails or reports an unparseable format.
|
|
109
109
|
- **[path -> Path]** (Property)
|
|
110
110
|
- **Behavior**: Path to the PHP executable.
|
|
111
111
|
- **Output**: Path to PHP executable.
|
|
@@ -25,7 +25,6 @@ distribution.
|
|
|
25
25
|
| `_sources/_integrity.py` | Checksum parsing and file digest verification |
|
|
26
26
|
| `_sources/_cache.py` | Cache root location and remote cache-entry keying |
|
|
27
27
|
| `_sources/_discovery.py` | `_BundledDiscovery`, companion exception mirroring |
|
|
28
|
-
| `_sources/_entrypoints.py` | Entry-point group reading (3.9/3.10 compatibility) |
|
|
29
28
|
|
|
30
29
|
All modules except `__init__.py` are internal (`_`-prefixed); the public API
|
|
31
30
|
is re-exported from `__init__.py`, whose `__all__` is the single source of
|
|
@@ -58,13 +57,14 @@ discovery is by group name, so the module path is companion-internal.
|
|
|
58
57
|
`tests/` mirrors modules as `test_<module>.py`, split by responsibility as
|
|
59
58
|
`test_<module>_<responsibility>.py` when oversized:
|
|
60
59
|
|
|
60
|
+
- `__init__.py` → `test_init.py`
|
|
61
61
|
- `_php.py` → `test_php_factory.py`, `test_php_exec.py`, `test_php_inspect.py`, `test_php_require.py`
|
|
62
62
|
- `_execution.py` → exercised through `PHP` delegation in `test_php_exec.py`, `test_php_inspect.py`
|
|
63
63
|
- `_sources/_path.py` → `_sources/test_path.py`
|
|
64
|
-
- `_sources/_remote.py` → `_sources/test_remote_download.py`
|
|
65
|
-
- `_sources/_packaged.py` → `_sources/test_packaged.py`; `_sources/_publishing.py` → exercised through `_sources/test_packaged.py`, `_sources/test_remote_download.py`
|
|
66
|
-
- `_sources/_extraction.py` + `_RemoteProvider` archive flow → `_sources/test_remote_archive.py`, `_sources/test_remote_search.py`, `_sources/test_remote_containment.py`
|
|
67
|
-
- `_sources/_discovery.py` → `_sources/test_discovery.py`; `_sources/_integrity.py` → `_sources/test_integrity.py`; `_sources/_cache.py` → `_sources/test_cache.py
|
|
64
|
+
- `_sources/_remote.py` → `_sources/test_remote_download.py`, `_sources/test_remote_checksum.py`
|
|
65
|
+
- `_sources/_packaged.py` → `_sources/test_packaged.py`, `_sources/test_packaged_selection.py`; `_sources/_publishing.py` → exercised through `_sources/test_packaged.py`, `_sources/test_remote_download.py`
|
|
66
|
+
- `_sources/_extraction.py` full-tree model + `_RemoteProvider` archive flow → `_sources/test_remote_archive.py`, `_sources/test_remote_search.py`, `_sources/test_remote_containment.py`; single-member model → exercised through `_sources/test_packaged.py`
|
|
67
|
+
- `_sources/_discovery.py` → `_sources/test_discovery.py`; `_sources/_integrity.py` → `_sources/test_integrity.py`; `_sources/_cache.py` → `_sources/test_cache.py`
|
|
68
68
|
- `_manifest.py` → `test_manifest.py`; `_types.py` → `test_types.py`; `_exceptions.py` → `test_exceptions.py`; `_version.py` → `test_version_fallback.py`
|
|
69
69
|
- Companion: `_php.py` → `test_php.py`; `_exceptions.py` → `test_exceptions.py`
|
|
70
70
|
- Cross-module integration: `test_integration_exec.py`, `test_integration_factory.py`
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
- **[stdlib]** `subprocess.run([php, "-m"], capture_output=True, text=True)` — lists loaded extensions (`PHP.extensions`).
|
|
6
6
|
- **[stdlib]** `subprocess.run(cmd, input="héllo", capture_output=True, encoding="utf-8", errors="replace")` — `input` takes str when `encoding` is set and reaches PHP's STDIN as UTF-8; `input=None` inherits the parent's stdin while `input=""` delivers an EOF-only stdin (distinct behaviors, verified with the 8.4 binary).
|
|
7
7
|
- **[php-cli]** `php -d key=value` — must precede the script path or `-r`; placed after the script path it lands in `$argv` instead of applying as ini. Multiple `-d` options compose. Script args after the script path and stdin are readable simultaneously (all verified with the 8.4 binary).
|
|
8
|
+
- **[php-cli]** `php --version` output — standard binaries report `PHP X.Y.Z (cli) ...`; static-php-cli builds can report `static-php-cli X.Y.Z`; version parsing tries both patterns and returns the bare `X.Y.Z`.
|
|
8
9
|
- **[stdlib]** `php -m` output parse — drop the `[PHP Modules]` / `[Zend Modules]` header lines and blank lines; lowercase each remaining name (output is mixed case, e.g. `Core`, `tokenizer`, `SPL`).
|
|
9
|
-
- **[stdlib]** `importlib.metadata.entry_points(group="static_php_py.binary")` — `PHP.bundled` discovers the companion's binary resolver; empty group → companion not installed → `BinaryNotFoundError` naming the `[bundled]` extra; for the multiple-registration error message use `EntryPoint.name` + `.value
|
|
10
|
+
- **[stdlib]** `importlib.metadata.entry_points(group="static_php_py.binary")` — `PHP.bundled` discovers the companion's binary resolver; empty group → companion not installed → `BinaryNotFoundError` naming the `[bundled]` extra; for the multiple-registration error message use `EntryPoint.name` + `.value`.
|
|
10
11
|
- **[stdlib]** `importlib.resources.files(pkg)` returns a `Traversable`, not a `Path`; binaries must be exec'd from a real path, so use `with as_file(files("static_php_py_binary") / name) as p:` — the package name is the companion package, not a bare `"resources"`.
|
|
11
12
|
- **[stdlib]** `files(package) / "_resources" / name` — traverses into `_resources/` without it being importable as a package; `as_file` yields a usable real path even for a not-yet-existing member, so the same call names the extraction target (`PackagedBinary`).
|
|
12
|
-
- **[stdlib]** `Traversable.__truediv__` — join one segment per `/` call; a multi-level `directory` like `"assets/php"` is split on `/` and joined part by part (multi-arg `joinpath` is 3.12+; package supports 3.
|
|
13
|
+
- **[stdlib]** `Traversable.__truediv__` — join one segment per `/` call; a multi-level `directory` like `"assets/php"` is split on `/` and joined part by part (multi-arg `joinpath` is 3.12+; package supports 3.10).
|
|
13
14
|
- **[stdlib]** `zipfile.ZipFile(path)` + `archive.open(info.filename)` — streams a zip member (`PackagedBinary` Windows archives); zip does not preserve the execute bit, so the publish step always chmods; directories via `info.is_dir()`, member basename via `info.filename.rsplit("/", 1)[-1]` (zip names always use `/`).
|
|
14
15
|
- **[stdlib]** `platform.machine()` + `sys.platform` — host OS/arch detection; the companion selects its PHP tar.gz with it.
|
|
15
16
|
- **[stdlib]** `tarfile.open(path, "r:gz")` + `archive.extractfile(member)` — the companion streams its PHP binary out of a bundled tar.gz in source/editable installs; tar.gz preserves the Unix execute bit (zip does not), so `chmod` is only a fallback. Member names carry a `./` prefix — match by `member.name.rsplit("/", 1)[-1]`; `extractfile` returns None for non-regular members.
|
|
@@ -63,10 +64,10 @@ Design decided (2026-07): signature, verification points, and cache keying live
|
|
|
63
64
|
- **[pip]** hash-checking mode — requirement-file convention `pkg==1.0 --hash=sha256:<hex>`, repeatable per requirement; `STRONG_HASHES = ["sha256", "sha384", "sha512"]`, `FAVORITE_HASH = "sha256"`, md5/sha1 rejected; `Hashes.check_against_chunks` streams `hashlib.new(name).update(chunk)` during download, unknown name → `InstallationError`; mismatch → `HashMismatch` and a previously downloaded file is unlinked. Source: `pip/_internal/utils/hashes.py`.
|
|
64
65
|
- **[huggingface_hub]** `hf_hub_download` — no user-supplied hash; `http_get` checks byte count from `X-Linked-Size`/`Content-Length` after download, mismatch → `EnvironmentError`; sha256 (`sha_fileobj`) compared against the LFS etag only to validate an existing local file; writes to a `.incomplete` temp then moves. Source: `huggingface_hub/file_download.py`.
|
|
65
66
|
- **[playwright]** (binary-in-wheel peer) — no checksum verification of downloaded browser archives; `curl` over HTTPS from cdn.playwright.dev only. Peers ship without verification; opt-in verification exceeds peer practice.
|
|
66
|
-
- **[stdlib]** `hashlib.new(name)` — raises `ValueError` on unknown name; incremental `h.update(chunk)` supports stream hashing; `hashlib.file_digest` is 3.11+ only (package is `requires-python >=3.
|
|
67
|
+
- **[stdlib]** `hashlib.new(name)` — raises `ValueError` on unknown name; incremental `h.update(chunk)` supports stream hashing; `hashlib.file_digest` is 3.11+ only (package is `requires-python >=3.10`); portable set = `hashlib.algorithms_guaranteed`.
|
|
67
68
|
|
|
68
69
|
Implementation facts:
|
|
69
70
|
|
|
70
|
-
- **[hashlib]** `hashlib.new(name)` after a frozenset gate on `{sha256, sha384, sha512}` (pip's `STRONG_HASHES`); `hashlib.file_digest` is 3.11+ only — stream with `h.update(chunk)` loops instead (package is `requires-python >=3.
|
|
71
|
+
- **[hashlib]** `hashlib.new(name)` after a frozenset gate on `{sha256, sha384, sha512}` (pip's `STRONG_HASHES`); `hashlib.file_digest` is 3.11+ only — stream with `h.update(chunk)` loops instead (package is `requires-python >=3.10`).
|
|
71
72
|
- **[hashlib]** digest lengths for hex validation: sha256=64, sha384=96, sha512=128 — `hashlib.new(name).digest_size * 2`.
|
|
72
73
|
- The hashed artifact is always the pre-extraction `downloaded` file, never the extracted binary; the checksum a user supplies is the published digest of the URL's artifact.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "static-php-py"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.7"
|
|
4
4
|
description = "Python wrapper library for static PHP binaries; code-only execution library"
|
|
5
5
|
readme = "README.md"
|
|
6
|
-
requires-python = ">=3.
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
7
|
license = { file = "LICENSE" }
|
|
8
8
|
authors = [
|
|
9
9
|
{ name = "static-php-py contributors" }
|
|
@@ -14,7 +14,6 @@ classifiers = [
|
|
|
14
14
|
"Intended Audience :: Developers",
|
|
15
15
|
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
|
|
16
16
|
"Programming Language :: Python :: 3",
|
|
17
|
-
"Programming Language :: Python :: 3.9",
|
|
18
17
|
"Programming Language :: Python :: 3.10",
|
|
19
18
|
"Programming Language :: Python :: 3.11",
|
|
20
19
|
"Programming Language :: Python :: 3.12",
|
|
@@ -26,7 +25,7 @@ dependencies = [
|
|
|
26
25
|
]
|
|
27
26
|
|
|
28
27
|
[project.optional-dependencies]
|
|
29
|
-
bundled = ["static-php-py-binary==0.1.
|
|
28
|
+
bundled = ["static-php-py-binary==0.1.5"]
|
|
30
29
|
|
|
31
30
|
[project.urls]
|
|
32
31
|
Homepage = "https://github.com/samhsu-dev/static-php-py"
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import importlib.metadata
|
|
5
6
|
from pathlib import Path
|
|
6
7
|
|
|
7
8
|
from .._exceptions import BinaryNotFoundError, InvalidArchiveError, PHPError
|
|
8
|
-
from ._entrypoints import entries_for_group
|
|
9
9
|
|
|
10
10
|
_BINARY_GROUP = "static_php_py.binary"
|
|
11
11
|
|
|
@@ -41,7 +41,7 @@ class _BundledDiscovery:
|
|
|
41
41
|
InvalidArchiveError: When the companion's platform archive holds
|
|
42
42
|
no PHP executable member.
|
|
43
43
|
"""
|
|
44
|
-
entries =
|
|
44
|
+
entries = list(importlib.metadata.entry_points(group=_BINARY_GROUP))
|
|
45
45
|
if not entries:
|
|
46
46
|
raise BinaryNotFoundError(
|
|
47
47
|
"No bundled PHP binary found. Install the companion "
|
|
@@ -14,7 +14,7 @@ import os
|
|
|
14
14
|
import platform
|
|
15
15
|
import re
|
|
16
16
|
import sys
|
|
17
|
-
from pathlib import Path
|
|
17
|
+
from pathlib import Path, PureWindowsPath
|
|
18
18
|
|
|
19
19
|
from .._exceptions import BinaryNotFoundError
|
|
20
20
|
from ._extraction import _extract_php_member
|
|
@@ -152,7 +152,14 @@ def _validate_directory(directory: str) -> None:
|
|
|
152
152
|
"""Reject directory values that leave the package."""
|
|
153
153
|
if not directory:
|
|
154
154
|
raise ValueError("Empty archive directory: pass a package-relative path.")
|
|
155
|
-
|
|
155
|
+
# PureWindowsPath.drive catches drive-letter absolutes ("C:/x") that
|
|
156
|
+
# carry no backslash and no empty segment on any host platform.
|
|
157
|
+
if (
|
|
158
|
+
"\\" in directory
|
|
159
|
+
or "" in directory.split("/")
|
|
160
|
+
or ".." in directory.split("/")
|
|
161
|
+
or PureWindowsPath(directory).drive
|
|
162
|
+
):
|
|
156
163
|
raise ValueError(
|
|
157
164
|
f"Archive directory {directory!r} must be a package-relative path "
|
|
158
165
|
"with '/' separators and no '..' segments."
|
|
File without changes
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Shared fixtures for _sources provider tests.
|
|
2
|
+
|
|
3
|
+
Fixtures:
|
|
4
|
+
- fake_response -- factory building context-manager mocks mimicking urlopen's response.
|
|
5
|
+
- packaged_stub -- stub binary bytes the packaged archive builders embed by default.
|
|
6
|
+
- make_packaged_targz -- builder writing a one-member tar.gz stub archive (test_packaged*.py).
|
|
7
|
+
- make_packaged_zip -- builder writing a one-member zip stub archive (test_packaged*.py).
|
|
8
|
+
- patch_packaged_host -- context-manager factory patching the packaged module's host probes.
|
|
9
|
+
- resolve_packaged -- resolver running PackagedBinary against a directory on a patched host.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import tarfile
|
|
15
|
+
import zipfile
|
|
16
|
+
from collections.abc import Callable, Iterator
|
|
17
|
+
from contextlib import AbstractContextManager, contextmanager
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from unittest.mock import MagicMock, Mock, patch
|
|
20
|
+
|
|
21
|
+
import pytest
|
|
22
|
+
from static_php_py._sources._packaged import PackagedBinary
|
|
23
|
+
|
|
24
|
+
_PACKAGED_MODULE = "static_php_py._sources._packaged"
|
|
25
|
+
_PACKAGED_STUB = b"#!/bin/sh\n"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@pytest.fixture
|
|
29
|
+
def fake_response() -> Callable[[bytes], MagicMock]:
|
|
30
|
+
"""Return a factory building context-manager mocks mimicking urlopen's response."""
|
|
31
|
+
|
|
32
|
+
def build(body: bytes) -> MagicMock:
|
|
33
|
+
response = MagicMock()
|
|
34
|
+
response.read.return_value = body
|
|
35
|
+
response.__enter__ = Mock(return_value=response)
|
|
36
|
+
response.__exit__ = Mock(return_value=None)
|
|
37
|
+
return response
|
|
38
|
+
|
|
39
|
+
return build
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@pytest.fixture
|
|
43
|
+
def packaged_stub() -> bytes:
|
|
44
|
+
"""Stub binary bytes the packaged archive builders embed by default."""
|
|
45
|
+
return _PACKAGED_STUB
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@pytest.fixture
|
|
49
|
+
def make_packaged_targz() -> Callable[..., Path]:
|
|
50
|
+
"""Return a builder writing a one-member tar.gz stub archive."""
|
|
51
|
+
|
|
52
|
+
def _make(path: Path, member: str, content: bytes = _PACKAGED_STUB) -> Path:
|
|
53
|
+
stub = path.parent / f".stub-{member}"
|
|
54
|
+
stub.write_bytes(content)
|
|
55
|
+
with tarfile.open(path, "w:gz") as archive:
|
|
56
|
+
archive.add(stub, arcname=member)
|
|
57
|
+
stub.unlink()
|
|
58
|
+
return path
|
|
59
|
+
|
|
60
|
+
return _make
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@pytest.fixture
|
|
64
|
+
def make_packaged_zip() -> Callable[..., Path]:
|
|
65
|
+
"""Return a builder writing a one-member zip stub archive."""
|
|
66
|
+
|
|
67
|
+
def _make(path: Path, member: str, content: bytes = _PACKAGED_STUB) -> Path:
|
|
68
|
+
with zipfile.ZipFile(path, "w") as archive:
|
|
69
|
+
archive.writestr(member, content)
|
|
70
|
+
return path
|
|
71
|
+
|
|
72
|
+
return _make
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@pytest.fixture
|
|
76
|
+
def patch_packaged_host() -> Callable[[str, str], AbstractContextManager[None]]:
|
|
77
|
+
"""Return a context-manager factory patching the packaged module's host probes."""
|
|
78
|
+
|
|
79
|
+
@contextmanager
|
|
80
|
+
def _patched(system: str, machine: str) -> Iterator[None]:
|
|
81
|
+
with (
|
|
82
|
+
patch(f"{_PACKAGED_MODULE}.sys.platform", system),
|
|
83
|
+
patch(f"{_PACKAGED_MODULE}.platform.machine", return_value=machine),
|
|
84
|
+
):
|
|
85
|
+
yield
|
|
86
|
+
|
|
87
|
+
return _patched
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@pytest.fixture
|
|
91
|
+
def resolve_packaged(
|
|
92
|
+
patch_packaged_host: Callable[[str, str], AbstractContextManager[None]],
|
|
93
|
+
) -> Callable[..., Path]:
|
|
94
|
+
"""Return a resolver running PackagedBinary against a real archive directory."""
|
|
95
|
+
|
|
96
|
+
def _resolve(directory: Path, host: tuple[str, str], series: str | None = None) -> Path:
|
|
97
|
+
binary = PackagedBinary(package="my_lib", series=series)
|
|
98
|
+
with (
|
|
99
|
+
patch(f"{_PACKAGED_MODULE}._resource_directory", return_value=directory),
|
|
100
|
+
patch_packaged_host(*host),
|
|
101
|
+
):
|
|
102
|
+
return binary.resolve()
|
|
103
|
+
|
|
104
|
+
return _resolve
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"""Tests for _BundledDiscovery — companion binary entry-point resolution.
|
|
2
2
|
|
|
3
3
|
Test cases:
|
|
4
|
+
- test_binary_group_registers_companion_resolver -- the installed companion's resolver is the sole static_php_py.binary registration.
|
|
4
5
|
- TestBundledDiscovery::test_resolve_returns_companion_path -- resolve() returns the path from the single entry point's resolver.
|
|
5
6
|
- TestBundledDiscovery::test_resolve_raises_when_group_empty -- resolve() raises BinaryNotFoundError naming the [bundled] extra when the group is empty.
|
|
6
7
|
- TestBundledDiscovery::test_resolve_raises_on_multiple_registrations -- resolve() raises plain PHPError (not BinaryNotFoundError) naming every registration when the group holds more than one entry point.
|
|
7
|
-
- TestBundledDiscovery::test_resolve_propagates_resolver_failure -- resolve() propagates BinaryNotFoundError when the companion resolver cannot locate its binary.
|
|
8
8
|
- TestBundledDiscovery::test_resolve_translates_companion_binary_not_found -- a companion-local BinaryNotFoundError is translated to the execution library's PHPError subclass, chained to the original.
|
|
9
9
|
- TestBundledDiscovery::test_resolve_translates_companion_invalid_archive -- a companion-local InvalidArchiveError is translated to the execution library's PHPError subclass, chained to the original.
|
|
10
10
|
- TestBundledDiscovery::test_resolve_propagates_unmirrored_resolver_error -- an exception whose class name is not mirrored propagates untranslated.
|
|
@@ -12,6 +12,7 @@ Test cases:
|
|
|
12
12
|
|
|
13
13
|
from __future__ import annotations
|
|
14
14
|
|
|
15
|
+
import importlib.metadata
|
|
15
16
|
from pathlib import Path
|
|
16
17
|
from unittest.mock import Mock, patch
|
|
17
18
|
|
|
@@ -45,10 +46,16 @@ def _registration(name: str, value: str) -> Mock:
|
|
|
45
46
|
return entry
|
|
46
47
|
|
|
47
48
|
|
|
49
|
+
def test_binary_group_registers_companion_resolver() -> None:
|
|
50
|
+
"""The installed companion's resolver is the sole binary-group registration."""
|
|
51
|
+
entries = importlib.metadata.entry_points(group="static_php_py.binary")
|
|
52
|
+
assert [entry.name for entry in entries] == ["resolver"]
|
|
53
|
+
|
|
54
|
+
|
|
48
55
|
class TestBundledDiscovery:
|
|
49
56
|
"""Test _BundledDiscovery.resolve()."""
|
|
50
57
|
|
|
51
|
-
@patch("
|
|
58
|
+
@patch("importlib.metadata.entry_points")
|
|
52
59
|
def test_resolve_returns_companion_path(self, mock_eps: Mock, tmp_path: Path) -> None:
|
|
53
60
|
"""resolve() returns the path from the single registered resolver."""
|
|
54
61
|
binary = tmp_path / "php"
|
|
@@ -61,7 +68,7 @@ class TestBundledDiscovery:
|
|
|
61
68
|
|
|
62
69
|
assert _BundledDiscovery().resolve() == binary
|
|
63
70
|
|
|
64
|
-
@patch("
|
|
71
|
+
@patch("importlib.metadata.entry_points")
|
|
65
72
|
def test_resolve_raises_when_group_empty(self, mock_eps: Mock) -> None:
|
|
66
73
|
"""resolve() raises BinaryNotFoundError naming the extra when the group is empty."""
|
|
67
74
|
mock_eps.return_value = []
|
|
@@ -69,7 +76,7 @@ class TestBundledDiscovery:
|
|
|
69
76
|
with pytest.raises(BinaryNotFoundError, match=r"static-php-py\[bundled\]"):
|
|
70
77
|
_BundledDiscovery().resolve()
|
|
71
78
|
|
|
72
|
-
@patch("
|
|
79
|
+
@patch("importlib.metadata.entry_points")
|
|
73
80
|
def test_resolve_raises_on_multiple_registrations(self, mock_eps: Mock) -> None:
|
|
74
81
|
"""resolve() fails loudly, naming every registration, when the group holds >1."""
|
|
75
82
|
mock_eps.return_value = [
|
|
@@ -85,19 +92,7 @@ class TestBundledDiscovery:
|
|
|
85
92
|
assert "'bundled' -> static_php_py_binary._resource:_RESOLVER" in message
|
|
86
93
|
assert "'rogue' -> rogue_pkg._impl:_RESOLVER" in message
|
|
87
94
|
|
|
88
|
-
@patch("
|
|
89
|
-
def test_resolve_propagates_resolver_failure(self, mock_eps: Mock) -> None:
|
|
90
|
-
"""resolve() propagates BinaryNotFoundError raised by the companion resolver."""
|
|
91
|
-
resolver = Mock()
|
|
92
|
-
resolver.resolve.side_effect = BinaryNotFoundError("companion binary missing")
|
|
93
|
-
entry = Mock()
|
|
94
|
-
entry.load.return_value = resolver
|
|
95
|
-
mock_eps.return_value = [entry]
|
|
96
|
-
|
|
97
|
-
with pytest.raises(BinaryNotFoundError, match="companion binary missing"):
|
|
98
|
-
_BundledDiscovery().resolve()
|
|
99
|
-
|
|
100
|
-
@patch("static_php_py._sources._discovery.entries_for_group")
|
|
95
|
+
@patch("importlib.metadata.entry_points")
|
|
101
96
|
def test_resolve_translates_companion_binary_not_found(self, mock_eps: Mock) -> None:
|
|
102
97
|
"""A companion-local BinaryNotFoundError becomes this library's PHPError subclass."""
|
|
103
98
|
original = _Companion.BinaryNotFoundError("no matching archive")
|
|
@@ -110,7 +105,7 @@ class TestBundledDiscovery:
|
|
|
110
105
|
assert isinstance(exc_info.value, PHPError)
|
|
111
106
|
assert exc_info.value.__cause__ is original
|
|
112
107
|
|
|
113
|
-
@patch("
|
|
108
|
+
@patch("importlib.metadata.entry_points")
|
|
114
109
|
def test_resolve_translates_companion_invalid_archive(self, mock_eps: Mock) -> None:
|
|
115
110
|
"""A companion-local InvalidArchiveError becomes this library's PHPError subclass."""
|
|
116
111
|
original = _Companion.InvalidArchiveError("no PHP member")
|
|
@@ -123,7 +118,7 @@ class TestBundledDiscovery:
|
|
|
123
118
|
assert isinstance(exc_info.value, PHPError)
|
|
124
119
|
assert exc_info.value.__cause__ is original
|
|
125
120
|
|
|
126
|
-
@patch("
|
|
121
|
+
@patch("importlib.metadata.entry_points")
|
|
127
122
|
def test_resolve_propagates_unmirrored_resolver_error(self, mock_eps: Mock) -> None:
|
|
128
123
|
"""An exception whose class name is not mirrored propagates untranslated."""
|
|
129
124
|
resolver = Mock()
|
|
@@ -9,7 +9,7 @@ Test cases:
|
|
|
9
9
|
- test_parse_wrong_digest_length_raises_value_error -- a digest of the wrong length is rejected.
|
|
10
10
|
- test_parse_non_hex_digest_raises_value_error -- non-hex characters in the digest are rejected.
|
|
11
11
|
- test_verify_matching_file_passes -- a file matching the expected digest verifies silently.
|
|
12
|
-
- test_verify_mismatching_file_raises_download_error -- a mismatch raises with expected and actual digests.
|
|
12
|
+
- test_verify_mismatching_file_raises_download_error -- a mismatch raises with the path, algorithm, expected, and actual digests.
|
|
13
13
|
"""
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
@@ -79,12 +79,18 @@ def test_verify_matching_file_passes(tmp_path: Path) -> None:
|
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
def test_verify_mismatching_file_raises_download_error(tmp_path: Path) -> None:
|
|
82
|
-
"""A mismatch raises with expected and actual digests.
|
|
82
|
+
"""A mismatch raises with the path, algorithm, expected, and actual digests.
|
|
83
|
+
|
|
84
|
+
The error carries all four fields (design-providers.md _verify_file).
|
|
85
|
+
"""
|
|
83
86
|
artifact = tmp_path / "downloaded"
|
|
84
87
|
artifact.write_bytes(b"tampered content")
|
|
85
88
|
actual = hashlib.sha256(b"tampered content").hexdigest()
|
|
86
89
|
|
|
87
90
|
with pytest.raises(DownloadError) as exc_info:
|
|
88
91
|
_verify_file(artifact, "sha256", _SHA256_DIGEST)
|
|
89
|
-
|
|
90
|
-
assert
|
|
92
|
+
message = str(exc_info.value)
|
|
93
|
+
assert str(artifact) in message
|
|
94
|
+
assert "sha256" in message
|
|
95
|
+
assert _SHA256_DIGEST in message
|
|
96
|
+
assert actual in message
|