pbs-installer 2024.2.26__tar.gz → 2024.3.22__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,14 +1,14 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pbs-installer
3
- Version: 2024.2.26
3
+ Version: 2024.3.22
4
4
  Summary: Installer for Python Build Standalone
5
5
  Author-Email: Frost Ming <me@frostming.com>
6
6
  License: MIT
7
- Requires-Python: >=3.7
7
+ Requires-Python: >=3.8
8
8
  Provides-Extra: download
9
9
  Provides-Extra: install
10
10
  Provides-Extra: all
11
- Requires-Dist: requests>=2.24.0; extra == "download"
11
+ Requires-Dist: httpx<1,>=0.27.0; extra == "download"
12
12
  Requires-Dist: zstandard>=0.21.0; extra == "install"
13
13
  Requires-Dist: pbs-installer[download,install]; extra == "all"
14
14
  Description-Content-Type: text/markdown
@@ -20,3 +20,5 @@ Description-Content-Type: text/markdown
20
20
  An installer for @indygreg's [python-build-standalone](https://github.com/indygreg/python-build-standalone)
21
21
 
22
22
  The list of python versions are kept sync with the upstream automatically, via a periodically GitHub Action.
23
+
24
+ [📖 Read the docs](http://pbs-installer.readthedocs.io/)
@@ -5,3 +5,5 @@
5
5
  An installer for @indygreg's [python-build-standalone](https://github.com/indygreg/python-build-standalone)
6
6
 
7
7
  The list of python versions are kept sync with the upstream automatically, via a periodically GitHub Action.
8
+
9
+ [📖 Read the docs](http://pbs-installer.readthedocs.io/)
@@ -4,18 +4,17 @@ description = "Installer for Python Build Standalone"
4
4
  authors = [
5
5
  { name = "Frost Ming", email = "me@frostming.com" },
6
6
  ]
7
- dependencies = []
8
- requires-python = ">=3.7"
7
+ requires-python = ">=3.8"
9
8
  readme = "README.md"
10
9
  dynamic = []
11
- version = "2024.2.26"
10
+ version = "2024.3.22"
12
11
 
13
12
  [project.license]
14
13
  text = "MIT"
15
14
 
16
15
  [project.optional-dependencies]
17
16
  download = [
18
- "requests>=2.24.0",
17
+ "httpx<1,>=0.27.0",
19
18
  ]
20
19
  install = [
21
20
  "zstandard>=0.21.0",
@@ -33,21 +32,18 @@ requires = [
33
32
  ]
34
33
  build-backend = "pdm.backend"
35
34
 
36
- [tool.pdm.dev-dependencies]
37
- dev = [
38
- "black>=23.3.0",
39
- ]
40
-
41
35
  [tool.pdm.version]
42
36
  source = "scm"
43
37
 
44
38
  [tool.pdm.scripts.update]
45
39
  shell = "./scripts/update.sh"
46
40
 
47
- [tool.black]
48
- line-length = 100
49
- include = "\\.pyi?$"
50
- exclude = "/(\n \\.eggs\n | \\.git\n | \\.hg\n | \\.mypy_cache\n | \\.tox\n | \\.venv\n | build\n | dist\n | src/pythonfinder/_vendor\n)\n"
41
+ [tool.pdm.dev-dependencies]
42
+ doc = [
43
+ "mkdocs>=1.5.3",
44
+ "mkdocs-material>=9.5.14",
45
+ "mkdocstrings[python]>=0.24",
46
+ ]
51
47
 
52
48
  [tool.ruff]
53
49
  line-length = 100
@@ -1,8 +1,5 @@
1
1
  """
2
- Installer for Python Build Standalone
3
-
4
- Author: frostming
5
- License: MIT
2
+ Core functions for the PBS Installer.
6
3
  """
7
4
 
8
5
  from ._install import download, get_download_link, install, install_file
@@ -12,7 +12,7 @@ from ._utils import PythonVersion, get_arch_platform, unpack_tar
12
12
  logger = logging.getLogger(__name__)
13
13
 
14
14
  if TYPE_CHECKING:
15
- import requests
15
+ import httpx
16
16
  from _typeshed import StrPath
17
17
 
18
18
  THIS_ARCH, THIS_PLATFORM = get_arch_platform()
@@ -33,10 +33,18 @@ def get_download_link(
33
33
  ) -> tuple[PythonVersion, str]:
34
34
  """Get the download URL matching the given requested version.
35
35
 
36
- :param request: The version of Python to install, e.g. 3.8,3.10.4
37
- :param arch: The architecture to install, e.g. x86_64, arm64
38
- :param platform: The platform to install, e.g. linux, macos
39
- :return: A tuple of the PythonVersion and the download URL
36
+ Parameters:
37
+ request: The version of Python to install, e.g. 3.8,3.10.4
38
+ arch: The architecture to install, e.g. x86_64, arm64
39
+ platform: The platform to install, e.g. linux, macos
40
+
41
+ Returns:
42
+ A tuple of the PythonVersion and the download URL
43
+
44
+ Examples:
45
+ >>> get_download_link("3.10", "x86_64", "linux")
46
+ (PythonVersion(kind='cpython', major=3, minor=10, micro=13),
47
+ 'https://github.com/indygreg/python-build-standalone/releases/download/20240224/cpython-3.10.13%2B20240224-x86_64-unknown-linux-gnu-pgo%2Blto-full.tar.zst')
40
48
  """
41
49
  from ._versions import PYTHON_VERSIONS
42
50
 
@@ -59,39 +67,44 @@ def get_download_link(
59
67
  raise ValueError(f"Could not find a CPython {request!r} matching this system")
60
68
 
61
69
 
62
- def _read_sha256(url: str, sess: requests.Session) -> str | None:
63
- resp = sess.get(url + ".sha256", headers=_get_headers())
64
- if not resp.ok:
70
+ def _read_sha256(url: str, client: httpx.Client) -> str | None:
71
+ resp = client.get(url + ".sha256", headers=_get_headers())
72
+ if not resp.is_success:
65
73
  logger.warning("No checksum found for %s, this would be insecure", url)
66
74
  return None
67
75
  return resp.text.strip()
68
76
 
69
77
 
70
- def download(url: str, destination: StrPath, session: requests.Session | None = None) -> str:
78
+ def download(url: str, destination: StrPath, client: httpx.Client | None = None) -> str:
71
79
  """Download the given url to the destination.
72
80
 
73
- :param url: The url to download
74
- :param destination: The file path to download to
75
- :param session: A requests session to use for downloading, or None to create a new one
76
- :return: The original filename of the downloaded file
81
+ Note: Extras required
82
+ `pbs-installer[download]` must be installed to use this function.
83
+
84
+ Parameters:
85
+ url: The url to download
86
+ destination: The file path to download to
87
+ client: A http.Client to use for downloading, or None to create a new one
88
+
89
+ Returns:
90
+ The original filename of the downloaded file
77
91
  """
78
92
  logger.debug("Downloading url %s to %s", url, destination)
79
- filename = unquote(url.rsplit("/")[-1])
80
93
  try:
81
- import requests
94
+ import httpx
82
95
  except ModuleNotFoundError:
83
- raise RuntimeError("You must install requests to use this function") from None
96
+ raise RuntimeError("You must install httpx to use this function") from None
84
97
 
85
- if session is None:
86
- session = requests.Session()
98
+ if client is None:
99
+ client = httpx.Client(trust_env=True, follow_redirects=True)
87
100
 
101
+ filename = unquote(url.rsplit("/")[-1])
88
102
  hasher = hashlib.sha256()
89
- checksum = _read_sha256(url, session)
103
+ checksum = _read_sha256(url, client)
90
104
 
91
- with open(destination, "wb") as f:
92
- response = session.get(url, stream=True, headers=_get_headers())
93
- response.raise_for_status()
94
- for chunk in response.iter_content(chunk_size=8192):
105
+ with open(destination, "wb") as f, client.stream("GET", url, headers=_get_headers()) as resp:
106
+ resp.raise_for_status()
107
+ for chunk in resp.iter_bytes(chunk_size=8192):
95
108
  if checksum:
96
109
  hasher.update(chunk)
97
110
  f.write(chunk)
@@ -106,9 +119,13 @@ def install_file(
106
119
  ) -> None:
107
120
  """Unpack the downloaded file to the destination.
108
121
 
109
- :param filename: The file to unpack
110
- :param destination: The directory to unpack to
111
- :param original_filename: The original filename of the file, if it was renamed
122
+ Note: Extras required
123
+ `pbs-installer[install]` must be installed to use this function.
124
+
125
+ Parameters:
126
+ filename: The file to unpack
127
+ destination: The directory to unpack to
128
+ original_filename: The original filename of the file, if it was renamed
112
129
  """
113
130
 
114
131
  import tarfile
@@ -141,18 +158,28 @@ def install(
141
158
  request: str,
142
159
  destination: StrPath,
143
160
  version_dir: bool = False,
144
- session: requests.Session | None = None,
161
+ client: httpx.Client | None = None,
145
162
  arch: str | None = None,
146
163
  platform: str | None = None,
147
164
  ) -> None:
148
165
  """Download and install the requested python version.
149
166
 
150
- :param request: The version of Python to install, e.g. 3.8,3.10.4
151
- :param destination: The directory to install to
152
- :param version_dir: Whether to install to a subdirectory named with the python version
153
- :param session: A requests session to use for downloading
154
- :param arch: The architecture to install, e.g. x86_64, arm64
155
- :param platform: The platform to install, e.g. linux, macos
167
+ Note: Extras required
168
+ `pbs-installer[all]` must be installed to use this function.
169
+
170
+ Parameters:
171
+ request: The version of Python to install, e.g. 3.8,3.10.4
172
+ destination: The directory to install to
173
+ version_dir: Whether to install to a subdirectory named with the python version
174
+ client: A httpx.Client to use for downloading
175
+ arch: The architecture to install, e.g. x86_64, arm64
176
+ platform: The platform to install, e.g. linux, macos
177
+
178
+ Examples:
179
+ >>> install("3.10", "./python")
180
+ Installing cpython@3.10.4 to ./python
181
+ >>> install("3.10", "./python", version_dir=True)
182
+ Installing cpython@3.10.4 to ./python/cpython@3.10.4
156
183
  """
157
184
  ver, url = get_download_link(request, arch=arch, platform=platform)
158
185
  if version_dir:
@@ -161,5 +188,5 @@ def install(
161
188
  os.makedirs(destination, exist_ok=True)
162
189
  with tempfile.NamedTemporaryFile() as tf:
163
190
  tf.close()
164
- original_filename = download(url, tf.name, session)
191
+ original_filename = download(url, tf.name, client)
165
192
  install_file(tf.name, destination, original_filename)