pyenv-native 0.2.22__tar.gz → 0.2.24__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyenv-native
3
- Version: 0.2.22
3
+ Version: 0.2.24
4
4
  Summary: Python install package for the native-first pyenv-native runtime bundles.
5
5
  Project-URL: Homepage, https://github.com/imyourboyroy
6
6
  Project-URL: Repository, https://github.com/imyourboyroy/pyenv-native
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pyenv-native"
7
- version = "0.2.22"
7
+ version = "0.2.24"
8
8
  description = "Python install package for the native-first pyenv-native runtime bundles."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.8"
@@ -1,6 +1,6 @@
1
- # ./python-package/src/pyenv_native_bootstrap/__init__.py
2
- """Package metadata for the pyenv-native bootstrap helper."""
3
-
4
- __all__ = ["__version__"]
5
-
6
- __version__ = "0.2.22"
1
+ # ./python-package/src/pyenv_native_bootstrap/__init__.py
2
+ """Package metadata for the pyenv-native bootstrap helper."""
3
+
4
+ __all__ = ["__version__"]
5
+
6
+ __version__ = "0.2.24"
@@ -1,8 +1,8 @@
1
- # ./python-package/src/pyenv_native_bootstrap/__main__.py
2
- """Module runner for `python -m pyenv_native_bootstrap`."""
3
-
4
- from .cli import main
5
-
6
-
7
- if __name__ == "__main__":
8
- raise SystemExit(main())
1
+ # ./python-package/src/pyenv_native_bootstrap/__main__.py
2
+ """Module runner for `python -m pyenv_native_bootstrap`."""
3
+
4
+ from .cli import main
5
+
6
+
7
+ if __name__ == "__main__":
8
+ raise SystemExit(main())
@@ -1,163 +1,163 @@
1
- # ./python-package/src/pyenv_native_bootstrap/bundle.py
2
- """Bundle metadata, checksum, and download helpers for pyenv-native release assets."""
3
-
4
- from __future__ import annotations
5
-
6
- import hashlib
7
- import json
8
- import tarfile
9
- import urllib.request
10
- from dataclasses import dataclass
11
- from pathlib import Path
12
- from typing import Optional
13
- from zipfile import ZipFile
14
-
15
- from . import __version__
16
-
17
-
18
- @dataclass(frozen=True)
19
- class BundleManifest:
20
- """Describes a built release bundle and the scripts it carries."""
21
-
22
- bundle_name: str
23
- bundle_version: str
24
- platform: str
25
- architecture: str
26
- executable: str
27
- install_script: str
28
- uninstall_script: str
29
-
30
-
31
- def sha256_file(path: Path) -> str:
32
- """Return the SHA-256 digest for a file."""
33
-
34
- digest = hashlib.sha256()
35
- with path.open("rb") as handle:
36
- for chunk in iter(lambda: handle.read(1024 * 1024), b""):
37
- digest.update(chunk)
38
- return digest.hexdigest()
39
-
40
-
41
- def parse_checksum_text(text: str, expected_file_name: Optional[str] = None) -> str:
42
- """Extract a SHA-256 value from a checksum file or raw string."""
43
-
44
- lines = [line.strip() for line in text.splitlines() if line.strip()]
45
- if not lines:
46
- raise ValueError("checksum text did not contain any usable lines")
47
-
48
- for line in lines:
49
- parts = line.split()
50
- if len(parts) == 1 and len(parts[0]) == 64:
51
- return parts[0].lower()
52
- if len(parts) >= 2 and len(parts[0]) == 64:
53
- candidate_name = parts[-1].lstrip("*")
54
- if expected_file_name is None or candidate_name == expected_file_name:
55
- return parts[0].lower()
56
-
57
- raise ValueError("checksum text did not contain a valid SHA-256 entry")
58
-
59
-
60
- def is_tar_bundle(bundle_path: Path) -> bool:
61
- """Return true when a bundle path uses a tar-based archive format."""
62
-
63
- suffixes = [suffix.lower() for suffix in bundle_path.suffixes]
64
- return suffixes[-2:] == [".tar", ".gz"] or bundle_path.suffix.lower() == ".tgz"
65
-
66
-
67
- def read_manifest_from_bundle(bundle_path: Path) -> BundleManifest:
68
- """Read and parse the bundle manifest embedded inside a release archive."""
69
-
70
- if is_tar_bundle(bundle_path):
71
- with tarfile.open(bundle_path, "r:*") as archive:
72
- member = next(
73
- (
74
- candidate
75
- for candidate in archive.getmembers()
76
- if Path(candidate.name).name == "bundle-manifest.json"
77
- ),
78
- None,
79
- )
80
- if member is None:
81
- raise FileNotFoundError("bundle-manifest.json was not found in the bundle archive")
82
- handle = archive.extractfile(member)
83
- if handle is None:
84
- raise FileNotFoundError("bundle-manifest.json could not be extracted")
85
- payload = json.loads(handle.read().decode("utf-8-sig"))
86
- else:
87
- with ZipFile(bundle_path, "r") as archive:
88
- with archive.open("bundle-manifest.json", "r") as handle:
89
- payload = json.loads(handle.read().decode("utf-8-sig"))
90
-
91
- return BundleManifest(
92
- bundle_name=payload["bundle_name"],
93
- bundle_version=payload["bundle_version"],
94
- platform=payload["platform"],
95
- architecture=payload["architecture"],
96
- executable=payload["executable"],
97
- install_script=payload["install_script"],
98
- uninstall_script=payload["uninstall_script"],
99
- )
100
-
101
-
102
- def read_manifest_from_zip(bundle_path: Path) -> BundleManifest:
103
- """Backward-compatible wrapper for zip-based bundle manifest reads."""
104
-
105
- return read_manifest_from_bundle(bundle_path)
106
-
107
-
108
- def download_file(url: str, destination: Path) -> Path:
109
- """Download a file to a destination path, replacing any prior file."""
110
-
111
- destination.parent.mkdir(parents=True, exist_ok=True)
112
- request = urllib.request.Request(
113
- url,
114
- headers={"User-Agent": f"pyenv-native/{__version__}"},
115
- )
116
- with urllib.request.urlopen(request) as response, destination.open("wb") as handle: # noqa: S310
117
- handle.write(response.read())
118
- return destination
119
-
120
-
121
- def load_checksum_text(
122
- checksum: Optional[str],
123
- checksum_path: Optional[Path],
124
- checksum_url: Optional[str],
125
- cache_path: Path,
126
- ) -> Optional[str]:
127
- """Load checksum content from an inline value, local file, or remote URL."""
128
-
129
- if checksum:
130
- return checksum.strip()
131
- if checksum_path:
132
- return checksum_path.read_text(encoding="utf-8")
133
- if checksum_url:
134
- checksum_target = cache_path.with_suffix(cache_path.suffix + ".sha256")
135
- download_file(checksum_url, checksum_target)
136
- return checksum_target.read_text(encoding="utf-8")
137
- return None
138
-
139
-
140
- def verify_bundle_checksum(
141
- bundle_path: Path,
142
- checksum: Optional[str] = None,
143
- checksum_path: Optional[Path] = None,
144
- checksum_url: Optional[str] = None,
145
- ) -> str:
146
- """Verify the bundle against a supplied checksum source and return the digest."""
147
-
148
- checksum_text = load_checksum_text(
149
- checksum=checksum,
150
- checksum_path=checksum_path,
151
- checksum_url=checksum_url,
152
- cache_path=bundle_path,
153
- )
154
- actual = sha256_file(bundle_path)
155
- if checksum_text is None:
156
- return actual
157
-
158
- expected = parse_checksum_text(checksum_text, bundle_path.name)
159
- if actual.lower() != expected.lower():
160
- raise ValueError(
161
- f"checksum mismatch for {bundle_path}: expected {expected}, got {actual}"
162
- )
163
- return actual
1
+ # ./python-package/src/pyenv_native_bootstrap/bundle.py
2
+ """Bundle metadata, checksum, and download helpers for pyenv-native release assets."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import hashlib
7
+ import json
8
+ import tarfile
9
+ import urllib.request
10
+ from dataclasses import dataclass
11
+ from pathlib import Path
12
+ from typing import Optional
13
+ from zipfile import ZipFile
14
+
15
+ from . import __version__
16
+
17
+
18
+ @dataclass(frozen=True)
19
+ class BundleManifest:
20
+ """Describes a built release bundle and the scripts it carries."""
21
+
22
+ bundle_name: str
23
+ bundle_version: str
24
+ platform: str
25
+ architecture: str
26
+ executable: str
27
+ install_script: str
28
+ uninstall_script: str
29
+
30
+
31
+ def sha256_file(path: Path) -> str:
32
+ """Return the SHA-256 digest for a file."""
33
+
34
+ digest = hashlib.sha256()
35
+ with path.open("rb") as handle:
36
+ for chunk in iter(lambda: handle.read(1024 * 1024), b""):
37
+ digest.update(chunk)
38
+ return digest.hexdigest()
39
+
40
+
41
+ def parse_checksum_text(text: str, expected_file_name: Optional[str] = None) -> str:
42
+ """Extract a SHA-256 value from a checksum file or raw string."""
43
+
44
+ lines = [line.strip() for line in text.splitlines() if line.strip()]
45
+ if not lines:
46
+ raise ValueError("checksum text did not contain any usable lines")
47
+
48
+ for line in lines:
49
+ parts = line.split()
50
+ if len(parts) == 1 and len(parts[0]) == 64:
51
+ return parts[0].lower()
52
+ if len(parts) >= 2 and len(parts[0]) == 64:
53
+ candidate_name = parts[-1].lstrip("*")
54
+ if expected_file_name is None or candidate_name == expected_file_name:
55
+ return parts[0].lower()
56
+
57
+ raise ValueError("checksum text did not contain a valid SHA-256 entry")
58
+
59
+
60
+ def is_tar_bundle(bundle_path: Path) -> bool:
61
+ """Return true when a bundle path uses a tar-based archive format."""
62
+
63
+ suffixes = [suffix.lower() for suffix in bundle_path.suffixes]
64
+ return suffixes[-2:] == [".tar", ".gz"] or bundle_path.suffix.lower() == ".tgz"
65
+
66
+
67
+ def read_manifest_from_bundle(bundle_path: Path) -> BundleManifest:
68
+ """Read and parse the bundle manifest embedded inside a release archive."""
69
+
70
+ if is_tar_bundle(bundle_path):
71
+ with tarfile.open(bundle_path, "r:*") as archive:
72
+ member = next(
73
+ (
74
+ candidate
75
+ for candidate in archive.getmembers()
76
+ if Path(candidate.name).name == "bundle-manifest.json"
77
+ ),
78
+ None,
79
+ )
80
+ if member is None:
81
+ raise FileNotFoundError("bundle-manifest.json was not found in the bundle archive")
82
+ handle = archive.extractfile(member)
83
+ if handle is None:
84
+ raise FileNotFoundError("bundle-manifest.json could not be extracted")
85
+ payload = json.loads(handle.read().decode("utf-8-sig"))
86
+ else:
87
+ with ZipFile(bundle_path, "r") as archive:
88
+ with archive.open("bundle-manifest.json", "r") as handle:
89
+ payload = json.loads(handle.read().decode("utf-8-sig"))
90
+
91
+ return BundleManifest(
92
+ bundle_name=payload["bundle_name"],
93
+ bundle_version=payload["bundle_version"],
94
+ platform=payload["platform"],
95
+ architecture=payload["architecture"],
96
+ executable=payload["executable"],
97
+ install_script=payload["install_script"],
98
+ uninstall_script=payload["uninstall_script"],
99
+ )
100
+
101
+
102
+ def read_manifest_from_zip(bundle_path: Path) -> BundleManifest:
103
+ """Backward-compatible wrapper for zip-based bundle manifest reads."""
104
+
105
+ return read_manifest_from_bundle(bundle_path)
106
+
107
+
108
+ def download_file(url: str, destination: Path) -> Path:
109
+ """Download a file to a destination path, replacing any prior file."""
110
+
111
+ destination.parent.mkdir(parents=True, exist_ok=True)
112
+ request = urllib.request.Request(
113
+ url,
114
+ headers={"User-Agent": f"pyenv-native/{__version__}"},
115
+ )
116
+ with urllib.request.urlopen(request) as response, destination.open("wb") as handle: # noqa: S310
117
+ handle.write(response.read())
118
+ return destination
119
+
120
+
121
+ def load_checksum_text(
122
+ checksum: Optional[str],
123
+ checksum_path: Optional[Path],
124
+ checksum_url: Optional[str],
125
+ cache_path: Path,
126
+ ) -> Optional[str]:
127
+ """Load checksum content from an inline value, local file, or remote URL."""
128
+
129
+ if checksum:
130
+ return checksum.strip()
131
+ if checksum_path:
132
+ return checksum_path.read_text(encoding="utf-8")
133
+ if checksum_url:
134
+ checksum_target = cache_path.with_suffix(cache_path.suffix + ".sha256")
135
+ download_file(checksum_url, checksum_target)
136
+ return checksum_target.read_text(encoding="utf-8")
137
+ return None
138
+
139
+
140
+ def verify_bundle_checksum(
141
+ bundle_path: Path,
142
+ checksum: Optional[str] = None,
143
+ checksum_path: Optional[Path] = None,
144
+ checksum_url: Optional[str] = None,
145
+ ) -> str:
146
+ """Verify the bundle against a supplied checksum source and return the digest."""
147
+
148
+ checksum_text = load_checksum_text(
149
+ checksum=checksum,
150
+ checksum_path=checksum_path,
151
+ checksum_url=checksum_url,
152
+ cache_path=bundle_path,
153
+ )
154
+ actual = sha256_file(bundle_path)
155
+ if checksum_text is None:
156
+ return actual
157
+
158
+ expected = parse_checksum_text(checksum_text, bundle_path.name)
159
+ if actual.lower() != expected.lower():
160
+ raise ValueError(
161
+ f"checksum mismatch for {bundle_path}: expected {expected}, got {actual}"
162
+ )
163
+ return actual