Debian Codegraph @

scripts/generate_manifest.py

raw
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Copyright (c) DataLab Platform Developers, BSD 3-Clause license, see LICENSE file.
4
5 """
6 Generate build manifest for DataLab executable
7
8 This script generates a JSON manifest file containing information about the build
9 environment, Python version, system information, and all installed packages with
10 their versions. This manifest is then included in the frozen executable and displayed
11 in the installation configuration viewer.
12 """
13
14 import json
15 import platform
16 from datetime import datetime
17 from importlib.metadata import distributions
18
19
20 def generate_manifest(file_path="manifest.json"):
21 """Generate a manifest file with build information and package list
22
23 Args:
24 file_path: Path to the output manifest JSON file (default: "manifest.json")
25 """
26 manifest = {
27 "build_time": datetime.utcnow().isoformat() + "Z",
28 "python_version": platform.python_version(),
29 "system": platform.system(),
30 "release": platform.release(),
31 "architecture": platform.machine(),
32 "packages": {dist.metadata["Name"]: dist.version for dist in distributions()},
33 }
34
35 with open(file_path, "w", encoding="utf-8") as f:
36 json.dump(manifest, f, indent=2)
37
38 print(f"Manifest written to {file_path}")
39 print(f" Build time: {manifest['build_time']}")
40 print(f" Python version: {manifest['python_version']}")
41 print(f" System: {manifest['system']} {manifest['release']}")
42 print(f" Architecture: {manifest['architecture']}")
43 print(f" Total packages: {len(manifest['packages'])}")
44
45
46 if __name__ == "__main__":
47 generate_manifest()