deterministic-media-enhancer 1.0.0rc5__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.
@@ -0,0 +1,2 @@
1
+ include README.md LICENSE
2
+ recursive-include dme_package/skill *
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: deterministic-media-enhancer
3
+ Version: 1.0.0rc5
4
+ Summary: Offline model-free image and video restoration skill
5
+ License-Expression: MIT
6
+ Project-URL: Repository, https://github.com/Furox-Art/deterministic-media-enhancer
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Environment :: Console
9
+ Classifier: Operating System :: POSIX :: Linux
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Multimedia :: Graphics
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: deterministic-media-enhancer
3
+ Version: 1.0.0rc5
4
+ Summary: Offline model-free image and video restoration skill
5
+ License-Expression: MIT
6
+ Project-URL: Repository, https://github.com/Furox-Art/deterministic-media-enhancer
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Environment :: Console
9
+ Classifier: Operating System :: POSIX :: Linux
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Topic :: Multimedia :: Graphics
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
@@ -0,0 +1,9 @@
1
+ MANIFEST.in
2
+ pyproject.toml
3
+ deterministic_media_enhancer.egg-info/PKG-INFO
4
+ deterministic_media_enhancer.egg-info/SOURCES.txt
5
+ deterministic_media_enhancer.egg-info/dependency_links.txt
6
+ deterministic_media_enhancer.egg-info/entry_points.txt
7
+ deterministic_media_enhancer.egg-info/top_level.txt
8
+ dme_package/__init__.py
9
+ dme_package/launcher.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ dme = dme_package.launcher:main
@@ -0,0 +1 @@
1
+ """Offline deterministic media skill."""
@@ -0,0 +1,146 @@
1
+ """Explicit offline build and invocation of the packaged Rust media skill."""
2
+ import argparse
3
+ from contextlib import contextmanager
4
+ import fcntl
5
+ import hashlib
6
+ import json
7
+ import os
8
+ from pathlib import Path
9
+ import platform
10
+ import shutil
11
+ import stat
12
+ import subprocess
13
+ import sys
14
+ import tempfile
15
+
16
+ SKILL = Path(__file__).resolve().parent / "skill"
17
+ VERSION = "1.0.0-rc5"
18
+
19
+ def fingerprint(path):
20
+ h = hashlib.sha256()
21
+ with open(path, "rb") as f:
22
+ for block in iter(lambda: f.read(1024*1024), b""):
23
+ h.update(block)
24
+ return h.hexdigest()
25
+
26
+ def identity():
27
+ h = hashlib.sha256()
28
+ h.update(bytes.fromhex(fingerprint(__file__)))
29
+ for f in sorted(SKILL.rglob("*")):
30
+ if f.is_file() and "__pycache__" not in f.parts:
31
+ h.update(f.relative_to(SKILL).as_posix().encode() + b"\0")
32
+ h.update(bytes.fromhex(fingerprint(f)))
33
+ return h.hexdigest()
34
+
35
+ def private_dir(path):
36
+ path.mkdir(mode=0o700, exist_ok=True)
37
+ info = path.lstat()
38
+ if not stat.S_ISDIR(info.st_mode) or info.st_uid != os.getuid() or info.st_mode & 0o077:
39
+ raise ValueError("Cache must be an owned private directory: " + str(path))
40
+ return path
41
+
42
+ def cache():
43
+ root = Path(os.environ.get("XDG_CACHE_HOME") or (Path.home() / ".cache"))
44
+ if not root.is_absolute():
45
+ raise ValueError("XDG_CACHE_HOME must be absolute")
46
+ root.mkdir(parents=True, exist_ok=True)
47
+ base = private_dir(root / "deterministic-media-enhancer")
48
+ return private_dir(private_dir(base / platform.machine()) / identity())
49
+
50
+ @contextmanager
51
+ def locked(dest, exclusive):
52
+ fd = os.open(dest / ".lock", os.O_CREAT | os.O_RDWR | os.O_NOFOLLOW, 0o600)
53
+ with os.fdopen(fd, "r+b") as lock:
54
+ fcntl.flock(lock, fcntl.LOCK_EX if exclusive else fcntl.LOCK_SH)
55
+ yield
56
+
57
+ def tools(names):
58
+ result = {}
59
+ for name in names:
60
+ path = shutil.which(name)
61
+ if not path:
62
+ raise ValueError("Missing local dependency: " + name)
63
+ result[name] = fingerprint(path)
64
+ return result
65
+
66
+ def build(dest, gpu=False):
67
+ runtime = tools(("ffmpeg", "ffprobe"))
68
+ toolchain = tools(("cargo", "rustc", "bash") + (("nvcc",) if gpu else ()))
69
+ with tempfile.TemporaryDirectory(prefix="build-", dir=dest) as tmp:
70
+ root = Path(tmp) / "skill"
71
+ shutil.copytree(SKILL, root, ignore=shutil.ignore_patterns("__pycache__"))
72
+ env = dict(os.environ, CARGO_NET_OFFLINE="true", LC_ALL="C", TZ="UTC")
73
+ subprocess.run(["bash", str(root / "scripts/build.sh")], cwd=root, env=env, check=True)
74
+ if gpu:
75
+ subprocess.run(["bash", str(root / "scripts/build-gpu.sh")], cwd=root, env=env, check=True)
76
+ if runtime != tools(runtime) or toolchain != tools(toolchain):
77
+ raise ValueError("Build tools changed during build")
78
+ names = ["dme"] + (["dme-cuda"] if gpu else [])
79
+ stage = root / "build/skill"
80
+ manifest = {"source": identity(), "runtime": runtime, "build_tools": toolchain,
81
+ "binaries": {n: fingerprint(stage / n) for n in names}}
82
+ metadata = Path(tmp) / "manifest.json"
83
+ metadata.write_text(json.dumps(manifest, sort_keys=True))
84
+ # Exclusive lock and manifest-last publication; an interrupted build fails closed.
85
+ (dest / "manifest.json").unlink(missing_ok=True)
86
+ (dest / "dme-cuda").unlink(missing_ok=True)
87
+ for n in names:
88
+ os.replace(stage / n, dest / n)
89
+ os.replace(metadata, dest / "manifest.json")
90
+ return 0
91
+
92
+ def verified_engine(dest):
93
+ meta = dest / "manifest.json"
94
+ if not meta.is_file() or meta.is_symlink():
95
+ raise ValueError("Run dme build first")
96
+ m = json.loads(meta.read_text())
97
+ if m["source"] != identity() or m["runtime"] != tools(("ffmpeg", "ffprobe")):
98
+ raise ValueError("Source or FFmpeg executables changed; run dme build")
99
+ for name in ("dme", "dme-cuda"):
100
+ f = dest / name
101
+ if name not in m["binaries"]:
102
+ if f.exists() or f.is_symlink():
103
+ raise ValueError("Unexpected cached binary")
104
+ elif f.is_symlink() or not f.is_file() or fingerprint(f) != m["binaries"][name]:
105
+ raise ValueError("Cached binary failed integrity check; run dme build")
106
+ if "dme" not in m["binaries"]:
107
+ raise ValueError("Missing engine")
108
+ return dest / "dme"
109
+
110
+ def main():
111
+ args = sys.argv[1:]
112
+ try:
113
+ if platform.system() != "Linux":
114
+ raise ValueError("Only Linux (including WSL) is currently supported")
115
+ if not SKILL.is_dir():
116
+ raise ValueError("Packaged skill source missing")
117
+ if args == ["--version"]:
118
+ print("DME package " + VERSION)
119
+ return 0
120
+ if args == ["skill-path"]:
121
+ print(SKILL)
122
+ return 0
123
+ if not args or args == ["--help"]:
124
+ print("dme build [--gpu] | skill-path | doctor | analyze | enhance | verify-repeat | batch\n"
125
+ "Run dme build once to compile/test the offline engine.")
126
+ return 0
127
+ dest = cache()
128
+ if args[0] == "build":
129
+ p = argparse.ArgumentParser(prog="dme build")
130
+ p.add_argument("--gpu", action="store_true")
131
+ gpu = p.parse_args(args[1:]).gpu
132
+ with locked(dest, True):
133
+ return build(dest, gpu)
134
+ with locked(dest, False):
135
+ engine = verified_engine(dest)
136
+ return subprocess.call([sys.executable, str(SKILL / "scripts/agent.py"),
137
+ "--engine", str(engine), *args])
138
+ except (OSError, ValueError, KeyError, TypeError, subprocess.SubprocessError) as exc:
139
+ print(json.dumps({"status": "error", "error": str(exc)}))
140
+ return 1
141
+ except KeyboardInterrupt:
142
+ print(json.dumps({"status": "error", "error": "Interrupted"}))
143
+ return 130
144
+
145
+ if __name__ == "__main__":
146
+ sys.exit(main())
@@ -0,0 +1,21 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+ [project]
5
+ name = "deterministic-media-enhancer"
6
+ version = "1.0.0rc5"
7
+ description = "Offline model-free image and video restoration skill"
8
+ readme = "README.md"
9
+ requires-python = ">=3.10"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ classifiers = ["Development Status :: 4 - Beta", "Environment :: Console", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3", "Topic :: Multimedia :: Graphics"]
13
+ [project.urls]
14
+ Repository = "https://github.com/Furox-Art/deterministic-media-enhancer"
15
+ [project.scripts]
16
+ dme = "dme_package.launcher:main"
17
+ [tool.setuptools]
18
+ packages = ["dme_package"]
19
+ include-package-data = true
20
+ [tool.setuptools.package-data]
21
+ dme_package = ["skill/*", "skill/src/*", "skill/scripts/*", "skill/tests/*", "skill/gpu/*", "skill/references/*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+