zuv 0.0.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.
- zuv-0.0.1/.gitignore +12 -0
- zuv-0.0.1/.python-version +1 -0
- zuv-0.0.1/LICENSE +21 -0
- zuv-0.0.1/PKG-INFO +106 -0
- zuv-0.0.1/pyproject.toml +39 -0
- zuv-0.0.1/uv.lock +8 -0
- zuv-0.0.1/zuv/__init__.py +3 -0
- zuv-0.0.1/zuv/__main__.py +4 -0
- zuv-0.0.1/zuv/__version__.py +1 -0
- zuv-0.0.1/zuv/_loader_template.py +106 -0
- zuv-0.0.1/zuv/builder.py +128 -0
- zuv-0.0.1/zuv/cli.py +57 -0
- zuv-0.0.1/zuv/constants.py +5 -0
zuv-0.0.1/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.14
|
zuv-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 HamzaYslmn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
zuv-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: zuv
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Bundle any uv project into a single runnable .py file.
|
|
5
|
+
Project-URL: Homepage, https://github.com/HamzaYslmn/zuv
|
|
6
|
+
Project-URL: Repository, https://github.com/HamzaYslmn/zuv
|
|
7
|
+
Project-URL: Issues, https://github.com/HamzaYslmn/zuv/issues
|
|
8
|
+
Author: HamzaYslmn
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: bundle,packaging,pep723,single-file,uv
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
17
|
+
Requires-Python: >=3.13
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# zuv
|
|
21
|
+
|
|
22
|
+
Bundle any `uv` project into a single runnable `.py` file. End users only need `uv` installed.
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
uv run app.py
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
That's it. The bundled script is a [PEP 723](https://peps.python.org/pep-0723/) self-contained script. On first run it creates a `.venv` next to itself, installs the project's dependencies into it via `uv pip install`, extracts the bundled source, and runs the entry point. Subsequent runs reuse the cache.
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
uv tool install zuv
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Project layout
|
|
37
|
+
|
|
38
|
+
Your project needs a `pyproject.toml` and a `src/main.py` with a `main()` function:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
my-project/
|
|
42
|
+
pyproject.toml # [project] dependencies = [...]
|
|
43
|
+
src/
|
|
44
|
+
main.py # def main(): ...
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Build
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
zuv build ./my-project
|
|
51
|
+
# -> ./dist/my-project.py
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`zuv build` wipes `./dist/` first, then writes a fresh single-file script. Override the path with `-o` and the entry point with `-e module:function` (default `main:main`).
|
|
55
|
+
|
|
56
|
+
### Build the included examples
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
zuv build examples/bigtest -o dist/bigtest.py
|
|
60
|
+
zuv build examples/fastapi -o dist/fastapi.py
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Then:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
uv run dist/bigtest.py
|
|
67
|
+
uv run dist/fastapi.py
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Sibling overrides
|
|
71
|
+
|
|
72
|
+
The script `chdir`s to its own folder before invoking your entry point, so any file you drop next to the `.py` is visible to user code as a cwd-relative path:
|
|
73
|
+
|
|
74
|
+
| File next to the bundle | Effect |
|
|
75
|
+
| --- | --- |
|
|
76
|
+
| `.env` | `load_dotenv(".env")` picks it up |
|
|
77
|
+
| `frontend/` | `Path("frontend")` resolves to the override |
|
|
78
|
+
| `.venv/` | shared dep cache (auto-created on first run) |
|
|
79
|
+
| `.zuv/` | extracted source cache (per build hash) |
|
|
80
|
+
|
|
81
|
+
This lets you ship a single `.py` and let users tweak config or assets next to it without rebuilding.
|
|
82
|
+
|
|
83
|
+
## How it works
|
|
84
|
+
|
|
85
|
+
The output `.py` is a normal Python script with three parts:
|
|
86
|
+
|
|
87
|
+
1. A `#!/usr/bin/env -S uv run --script` shebang plus a PEP 723 metadata block declaring the Python version.
|
|
88
|
+
2. An `_ZUV_ENV` dict with the entry point and the project's dependency list, and a `_ZUV_PAYLOAD` base85-encoded `tar.gz` of `src/`.
|
|
89
|
+
3. A small loader that bootstraps the venv, extracts the source, sets `ZUV_DIR` / `ZUV_CWD` / `ZUV_CACHE`, and imports the entry callable.
|
|
90
|
+
|
|
91
|
+
Deps are NOT bundled inside the `.py`. uv handles them at runtime, so the bundle stays tiny (under 15 KB even for a FastAPI app) and binary wheels work natively without extraction tricks.
|
|
92
|
+
|
|
93
|
+
## Layout
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
src/
|
|
97
|
+
pyproject.toml
|
|
98
|
+
zuv/
|
|
99
|
+
cli.py # zuv build CLI
|
|
100
|
+
builder.py # tar.gz + base85 + emit .py
|
|
101
|
+
_loader_template.py # runtime loader embedded in every output
|
|
102
|
+
constants.py
|
|
103
|
+
examples/
|
|
104
|
+
bigtest/ # rich + pydantic smoke test
|
|
105
|
+
fastapi/ # FastAPI + uvicorn web app
|
|
106
|
+
```
|
zuv-0.0.1/pyproject.toml
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "zuv"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "Bundle any uv project into a single runnable .py file."
|
|
5
|
+
requires-python = ">=3.13"
|
|
6
|
+
dependencies = []
|
|
7
|
+
dynamic = ["readme"]
|
|
8
|
+
license = "MIT"
|
|
9
|
+
authors = [{name = "HamzaYslmn"}]
|
|
10
|
+
keywords = ["uv", "bundle", "pep723", "packaging", "single-file"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"Operating System :: OS Independent",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Topic :: Software Development :: Build Tools",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://github.com/HamzaYslmn/zuv"
|
|
21
|
+
Repository = "https://github.com/HamzaYslmn/zuv"
|
|
22
|
+
Issues = "https://github.com/HamzaYslmn/zuv/issues"
|
|
23
|
+
|
|
24
|
+
[project.scripts]
|
|
25
|
+
zuv = "zuv.cli:main"
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["hatchling", "hatch-fancy-pypi-readme"]
|
|
29
|
+
build-backend = "hatchling.build"
|
|
30
|
+
|
|
31
|
+
[tool.hatch.build.targets.wheel]
|
|
32
|
+
packages = ["zuv"]
|
|
33
|
+
|
|
34
|
+
# README lives at repo root; pull it in at build time via a relative reference.
|
|
35
|
+
[tool.hatch.metadata.hooks.fancy-pypi-readme]
|
|
36
|
+
content-type = "text/markdown"
|
|
37
|
+
|
|
38
|
+
[[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
|
|
39
|
+
path = "../README.md"
|
zuv-0.0.1/uv.lock
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.1"
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Runtime loader embedded inside every .zuv file.
|
|
2
|
+
|
|
3
|
+
Built into the .zuv as plain source. uv executes the file via PEP 723 with an
|
|
4
|
+
empty dependency list, so this loader runs in a minimal env (stdlib only).
|
|
5
|
+
|
|
6
|
+
On first run, the loader:
|
|
7
|
+
1. Materializes a `.venv` next to the .zuv using `uv venv` + `uv pip install`.
|
|
8
|
+
2. Extracts the embedded user source tarball to `<dir>/.zuv/<name>_<hash>/`.
|
|
9
|
+
3. Writes a `.zuv-ready` marker.
|
|
10
|
+
On every run:
|
|
11
|
+
4. Prepends the venv's site-packages and the extracted source dir to sys.path.
|
|
12
|
+
5. chdirs to the .zuv's folder so user code can use cwd-relative paths
|
|
13
|
+
(e.g. `load_dotenv('.env')`, `open('frontend/index.html')`).
|
|
14
|
+
6. Exports ZUV_DIR / ZUV_CWD / ZUV_CACHE env vars.
|
|
15
|
+
7. Imports the entry callable and invokes it.
|
|
16
|
+
"""
|
|
17
|
+
import base64
|
|
18
|
+
import io
|
|
19
|
+
import os
|
|
20
|
+
import subprocess
|
|
21
|
+
import sys
|
|
22
|
+
import tarfile
|
|
23
|
+
from importlib import import_module
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
# Builder injects these literals above the loader body:
|
|
27
|
+
# _ZUV_ENV: dict (entry, build_id, build_tag, dependencies)
|
|
28
|
+
# _ZUV_PAYLOAD: bytes (base85 of the tar.gz of the user source tree)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _venv_site_packages(venv_dir: Path) -> Path:
|
|
32
|
+
if os.name == "nt":
|
|
33
|
+
return venv_dir / "Lib" / "site-packages"
|
|
34
|
+
py = f"python{sys.version_info.major}.{sys.version_info.minor}"
|
|
35
|
+
return venv_dir / "lib" / py / "site-packages"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _uv(*args: str) -> None:
|
|
39
|
+
proc = subprocess.run(["uv", *args], capture_output=True, text=True)
|
|
40
|
+
if proc.returncode != 0:
|
|
41
|
+
sys.stderr.write(proc.stdout + proc.stderr)
|
|
42
|
+
raise SystemExit(f"error: uv {' '.join(args)} failed (exit {proc.returncode})")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _ensure_venv(venv_dir: Path, deps: list[str]) -> None:
|
|
46
|
+
if not (venv_dir / "pyvenv.cfg").exists():
|
|
47
|
+
_uv("venv", str(venv_dir), "--python", sys.executable, "--quiet")
|
|
48
|
+
if deps:
|
|
49
|
+
py = venv_dir / ("Scripts/python.exe" if os.name == "nt" else "bin/python")
|
|
50
|
+
_uv("pip", "install", "--python", str(py), "--quiet", *deps)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _extract(payload: bytes, target: Path) -> None:
|
|
54
|
+
tmp = target.with_name(target.name + ".tmp")
|
|
55
|
+
if tmp.exists():
|
|
56
|
+
import shutil
|
|
57
|
+
shutil.rmtree(tmp)
|
|
58
|
+
tmp.mkdir(parents=True)
|
|
59
|
+
with tarfile.open(fileobj=io.BytesIO(payload), mode="r:gz") as tf:
|
|
60
|
+
tf.extractall(tmp, filter="data")
|
|
61
|
+
if target.exists():
|
|
62
|
+
import shutil
|
|
63
|
+
shutil.rmtree(target)
|
|
64
|
+
tmp.rename(target)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _import_callable(target: str):
|
|
68
|
+
module_name, _, attr = target.partition(":")
|
|
69
|
+
obj = import_module(module_name)
|
|
70
|
+
for part in attr.split(".") if attr else ():
|
|
71
|
+
obj = getattr(obj, part)
|
|
72
|
+
return obj
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _run() -> int:
|
|
76
|
+
env = _ZUV_ENV # noqa: F821 - injected by builder
|
|
77
|
+
archive_path = Path(sys.argv[0]).resolve()
|
|
78
|
+
arch_dir = archive_path.parent
|
|
79
|
+
|
|
80
|
+
venv_dir = arch_dir / ".venv"
|
|
81
|
+
cache = arch_dir / ".zuv" / f"{archive_path.stem}_{env['build_id'][:12]}"
|
|
82
|
+
marker = cache / ".zuv-ready"
|
|
83
|
+
deps = env.get("dependencies", [])
|
|
84
|
+
|
|
85
|
+
if not marker.exists():
|
|
86
|
+
_ensure_venv(venv_dir, deps)
|
|
87
|
+
_extract(base64.b85decode(_ZUV_PAYLOAD), cache) # noqa: F821 - injected by builder
|
|
88
|
+
marker.write_text("ok")
|
|
89
|
+
elif deps and not (venv_dir / "pyvenv.cfg").exists():
|
|
90
|
+
_ensure_venv(venv_dir, deps)
|
|
91
|
+
|
|
92
|
+
sys.path.insert(0, str(cache))
|
|
93
|
+
sp = _venv_site_packages(venv_dir)
|
|
94
|
+
if sp.is_dir():
|
|
95
|
+
sys.path.insert(0, str(sp))
|
|
96
|
+
|
|
97
|
+
os.environ["ZUV_DIR"] = str(arch_dir)
|
|
98
|
+
os.environ["ZUV_CWD"] = str(arch_dir)
|
|
99
|
+
os.environ["ZUV_CACHE"] = str(cache)
|
|
100
|
+
os.chdir(arch_dir)
|
|
101
|
+
|
|
102
|
+
return int(_import_callable(env["entry"])() or 0)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
if __name__ == "__main__":
|
|
106
|
+
sys.exit(_run())
|
zuv-0.0.1/zuv/builder.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""Build a runnable .py from a project (pyproject.toml + src/main.py).
|
|
2
|
+
|
|
3
|
+
The output is a PEP 723 script that uv executes. It does NOT bundle deps —
|
|
4
|
+
instead it embeds a list of dependencies; the runtime loader materializes a
|
|
5
|
+
`.venv` next to the script on first run and `uv pip install`s them there.
|
|
6
|
+
|
|
7
|
+
Build steps:
|
|
8
|
+
1. Read deps from <project>/pyproject.toml.
|
|
9
|
+
2. tar.gz the <project>/src/ tree.
|
|
10
|
+
3. Emit <output> = shebang + latin-1 coding decl + PEP 723 header +
|
|
11
|
+
ENV literal + raw bytes payload literal + loader source.
|
|
12
|
+
"""
|
|
13
|
+
import base64
|
|
14
|
+
import compileall
|
|
15
|
+
import hashlib
|
|
16
|
+
import io
|
|
17
|
+
import platform
|
|
18
|
+
import shutil
|
|
19
|
+
import sys
|
|
20
|
+
import tarfile
|
|
21
|
+
import tempfile
|
|
22
|
+
import tomllib
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
from stat import S_IXGRP, S_IXOTH, S_IXUSR
|
|
25
|
+
|
|
26
|
+
from .__version__ import __version__
|
|
27
|
+
from .constants import PAYLOAD_VAR, ZUV_SHEBANG
|
|
28
|
+
|
|
29
|
+
PEP723_HEADER = """\
|
|
30
|
+
# /// script
|
|
31
|
+
# requires-python = ">={py}"
|
|
32
|
+
# dependencies = []
|
|
33
|
+
# ///
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _build_tag() -> dict[str, str]:
|
|
38
|
+
return {
|
|
39
|
+
"system": platform.system().lower(),
|
|
40
|
+
"machine": platform.machine().lower(),
|
|
41
|
+
"python": f"{sys.version_info.major}.{sys.version_info.minor}",
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _read_deps(pyproject: Path) -> list[str]:
|
|
46
|
+
data = tomllib.loads(pyproject.read_text(encoding="utf-8"))
|
|
47
|
+
return list(data.get("project", {}).get("dependencies", []))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _pre_compile(src_dir: Path) -> Path:
|
|
51
|
+
"""Copy src/ to a temp dir and pre-compile .pyc files into it."""
|
|
52
|
+
tmp = Path(tempfile.mkdtemp(prefix="zuv-src-"))
|
|
53
|
+
shutil.copytree(src_dir, tmp, dirs_exist_ok=True)
|
|
54
|
+
compileall.compile_dir(tmp, quiet=1, workers=0)
|
|
55
|
+
return tmp
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _make_tarball(root: Path) -> tuple[bytes, str]:
|
|
59
|
+
buf = io.BytesIO()
|
|
60
|
+
hasher = hashlib.sha256()
|
|
61
|
+
with tarfile.open(fileobj=buf, mode="w:gz", compresslevel=9) as tf:
|
|
62
|
+
for path in sorted(root.rglob("*"), key=str):
|
|
63
|
+
if not path.is_file():
|
|
64
|
+
continue
|
|
65
|
+
rel = path.relative_to(root).as_posix()
|
|
66
|
+
hasher.update(rel.encode("utf-8"))
|
|
67
|
+
hasher.update(path.read_bytes())
|
|
68
|
+
tf.add(path, arcname=rel)
|
|
69
|
+
return buf.getvalue(), hasher.hexdigest()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _loader_source() -> str:
|
|
73
|
+
return Path(__file__).with_name("_loader_template.py").read_text(encoding="utf-8")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def build_pyz(project_dir: Path, output: Path, entry: str | None) -> int:
|
|
77
|
+
pyproject = project_dir / "pyproject.toml"
|
|
78
|
+
src_dir = project_dir / "src"
|
|
79
|
+
|
|
80
|
+
if not pyproject.exists():
|
|
81
|
+
print(f"error: no pyproject.toml in {project_dir}", file=sys.stderr)
|
|
82
|
+
return 2
|
|
83
|
+
if not (src_dir / "main.py").exists():
|
|
84
|
+
print(f"error: no src/main.py in {project_dir}", file=sys.stderr)
|
|
85
|
+
return 2
|
|
86
|
+
|
|
87
|
+
if output.parent.name == "dist" and output.parent.exists():
|
|
88
|
+
print(f"cleaning {output.parent}...")
|
|
89
|
+
shutil.rmtree(output.parent)
|
|
90
|
+
output.parent.mkdir(parents=True, exist_ok=True)
|
|
91
|
+
|
|
92
|
+
deps = _read_deps(pyproject)
|
|
93
|
+
print(f"deps: {len(deps)} ({', '.join(deps) if deps else 'none'})")
|
|
94
|
+
|
|
95
|
+
print("pre-compiling source...")
|
|
96
|
+
staging = _pre_compile(src_dir)
|
|
97
|
+
try:
|
|
98
|
+
print("packing source tar.gz...")
|
|
99
|
+
payload, build_id = _make_tarball(staging)
|
|
100
|
+
finally:
|
|
101
|
+
shutil.rmtree(staging, ignore_errors=True)
|
|
102
|
+
|
|
103
|
+
env = {
|
|
104
|
+
"zuv_version": __version__,
|
|
105
|
+
"entry": entry or "main:main",
|
|
106
|
+
"build_id": build_id,
|
|
107
|
+
"build_tag": _build_tag(),
|
|
108
|
+
"dependencies": deps,
|
|
109
|
+
}
|
|
110
|
+
py_req = f"{sys.version_info.major}.{sys.version_info.minor}"
|
|
111
|
+
b85 = base64.b85encode(payload).decode("ascii")
|
|
112
|
+
|
|
113
|
+
parts = [
|
|
114
|
+
ZUV_SHEBANG,
|
|
115
|
+
PEP723_HEADER.format(py=py_req),
|
|
116
|
+
f"_ZUV_ENV = {env!r}\n",
|
|
117
|
+
f"{PAYLOAD_VAR} = (\n",
|
|
118
|
+
]
|
|
119
|
+
for i in range(0, len(b85), 80):
|
|
120
|
+
parts.append(f' b"{b85[i:i+80]}"\n')
|
|
121
|
+
parts.append(")\n")
|
|
122
|
+
parts.append(_loader_source())
|
|
123
|
+
|
|
124
|
+
output.write_text("".join(parts), encoding="utf-8")
|
|
125
|
+
output.chmod(output.stat().st_mode | S_IXUSR | S_IXGRP | S_IXOTH)
|
|
126
|
+
|
|
127
|
+
print(f"built {output} ({output.stat().st_size / 1024:.1f} KB)")
|
|
128
|
+
return 0
|
zuv-0.0.1/zuv/cli.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from . import __version__
|
|
6
|
+
from .builder import build_pyz
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main(argv: list[str] | None = None) -> int:
|
|
10
|
+
parser = argparse.ArgumentParser(
|
|
11
|
+
prog="zuv",
|
|
12
|
+
description="Build click-and-run Python apps powered by uv.",
|
|
13
|
+
)
|
|
14
|
+
parser.add_argument("--version", action="version", version=f"zuv {__version__}")
|
|
15
|
+
|
|
16
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
17
|
+
|
|
18
|
+
build = sub.add_parser("build", help="Build a single-file Python app from a uv project.")
|
|
19
|
+
build.add_argument(
|
|
20
|
+
"project",
|
|
21
|
+
nargs="?",
|
|
22
|
+
default=".",
|
|
23
|
+
help="Path to the uv project (containing pyproject.toml). Default: cwd.",
|
|
24
|
+
)
|
|
25
|
+
build.add_argument(
|
|
26
|
+
"-o", "--output",
|
|
27
|
+
default=None,
|
|
28
|
+
help="Output file path. Default: <cwd>/dist/<project-name>.py.",
|
|
29
|
+
)
|
|
30
|
+
build.add_argument(
|
|
31
|
+
"-e", "--entry",
|
|
32
|
+
default=None,
|
|
33
|
+
help="Entry point in 'module:function' form. Defaults to the project's first console script.",
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
args = parser.parse_args(argv)
|
|
37
|
+
|
|
38
|
+
if args.command == "build":
|
|
39
|
+
project_dir = Path(args.project).expanduser().resolve()
|
|
40
|
+
if args.output is None:
|
|
41
|
+
output = Path.cwd() / "dist" / f"{project_dir.name}.py"
|
|
42
|
+
else:
|
|
43
|
+
output = Path(args.output).expanduser().resolve()
|
|
44
|
+
if output.suffix == "":
|
|
45
|
+
output = output.with_suffix(".py")
|
|
46
|
+
return build_pyz(
|
|
47
|
+
project_dir=project_dir,
|
|
48
|
+
output=output,
|
|
49
|
+
entry=args.entry,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
parser.print_help()
|
|
53
|
+
return 1
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
if __name__ == "__main__":
|
|
57
|
+
sys.exit(main())
|