pbs-installer 2023.7.13__tar.gz → 2023.7.14__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,15 +1,22 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pbs-installer
3
- Version: 2023.7.13
3
+ Version: 2023.7.14
4
4
  Summary: Installer for Python Build Standalone
5
5
  Author-Email: Frost Ming <me@frostming.com>
6
6
  License: MIT
7
7
  Requires-Python: >=3.7
8
- Requires-Dist: zstandard>=0.21.0
8
+ Provides-Extra: download
9
+ Provides-Extra: install
10
+ Provides-Extra: all
11
+ Requires-Dist: requests>=2.24.0; extra == "download"
12
+ Requires-Dist: zstandard>=0.21.0; extra == "install"
13
+ Requires-Dist: pbs-installer[download,install]; extra == "all"
9
14
  Description-Content-Type: text/markdown
10
15
 
11
16
  # pbs-installer
12
17
 
18
+ [![PyPI](https://img.shields.io/pypi/v/pbs-installer)](https://pypi.org/project/pbs-installer)
19
+
13
20
  An installer for @indygreg's [python-build-standalone](https://github.com/indygreg/python-build-standalone)
14
21
 
15
22
  The list of python versions are kept sync with the upstream automatically, via a periodically GitHub Action.
@@ -1,5 +1,7 @@
1
1
  # pbs-installer
2
2
 
3
+ [![PyPI](https://img.shields.io/pypi/v/pbs-installer)](https://pypi.org/project/pbs-installer)
4
+
3
5
  An installer for @indygreg's [python-build-standalone](https://github.com/indygreg/python-build-standalone)
4
6
 
5
7
  The list of python versions are kept sync with the upstream automatically, via a periodically GitHub Action.
@@ -4,17 +4,26 @@ description = "Installer for Python Build Standalone"
4
4
  authors = [
5
5
  { name = "Frost Ming", email = "me@frostming.com" },
6
6
  ]
7
- dependencies = [
8
- "zstandard>=0.21.0",
9
- ]
7
+ dependencies = []
10
8
  requires-python = ">=3.7"
11
9
  readme = "README.md"
12
10
  dynamic = []
13
- version = "2023.7.13"
11
+ version = "2023.7.14"
14
12
 
15
13
  [project.license]
16
14
  text = "MIT"
17
15
 
16
+ [project.optional-dependencies]
17
+ download = [
18
+ "requests>=2.24.0",
19
+ ]
20
+ install = [
21
+ "zstandard>=0.21.0",
22
+ ]
23
+ all = [
24
+ "pbs-installer[download,install]",
25
+ ]
26
+
18
27
  [project.scripts]
19
28
  pbs-install = "pbs_installer.__main__:main"
20
29
 
@@ -26,7 +35,6 @@ build-backend = "pdm.backend"
26
35
 
27
36
  [tool.pdm.dev-dependencies]
28
37
  dev = [
29
- "requests>=2.31.0",
30
38
  "black>=23.3.0",
31
39
  ]
32
40
 
@@ -40,3 +48,10 @@ shell = "./scripts/update.sh"
40
48
  line-length = 100
41
49
  include = "\\.pyi?$"
42
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"
51
+
52
+ [tool.ruff]
53
+ line-length = 100
54
+ extend-select = [
55
+ "I",
56
+ ]
57
+ target-version = "py310"
@@ -1,3 +1,10 @@
1
+ """
2
+ Installer for Python Build Standalone
3
+
4
+ Author: frostming
5
+ License: MIT
6
+ """
7
+
1
8
  from ._install import download, get_download_link, install, install_file
2
9
  from ._utils import PythonVersion
3
10
 
@@ -0,0 +1,31 @@
1
+ import logging
2
+ from argparse import ArgumentParser
3
+
4
+ from ._install import install
5
+
6
+
7
+ def _setup_logger(verbose: bool):
8
+ logger = logging.getLogger("pbs_installer")
9
+ handler = logging.StreamHandler()
10
+ handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
11
+ logger.addHandler(handler)
12
+ logger.setLevel(logging.DEBUG if verbose else logging.WARNING)
13
+
14
+
15
+ def main():
16
+ parser = ArgumentParser("pbs-install", description="Installer for Python Build Standalone")
17
+ parser.add_argument("version", help="The version of Python to install, e.g. 3.8,3.10.4")
18
+ parser.add_argument(
19
+ "--version-dir", help="Install to a subdirectory named by the version", action="store_true"
20
+ )
21
+ parser.add_argument("-v", "--verbose", help="Enable verbose logging", action="store_true")
22
+ parser.add_argument("-d", "--destination", help="The directory to install to", required=True)
23
+
24
+ args = parser.parse_args()
25
+ _setup_logger(args.verbose)
26
+ install(args.version, args.destination, version_dir=args.version_dir)
27
+ print("Done!")
28
+
29
+
30
+ if __name__ == "__main__":
31
+ main()
@@ -7,13 +7,12 @@ import tempfile
7
7
  from typing import TYPE_CHECKING
8
8
  from urllib.parse import unquote
9
9
 
10
- import requests
11
-
12
10
  from ._utils import PythonVersion, get_arch_platform, unpack_tar
13
11
 
14
12
  logger = logging.getLogger(__name__)
15
13
 
16
14
  if TYPE_CHECKING:
15
+ import requests
17
16
  from _typeshed import StrPath
18
17
 
19
18
  THIS_ARCH, THIS_PLATFORM = get_arch_platform()
@@ -30,6 +29,11 @@ def _get_headers() -> dict[str, str] | None:
30
29
 
31
30
 
32
31
  def get_download_link(request: str) -> tuple[PythonVersion, str]:
32
+ """Get the download URL matching the given requested version.
33
+
34
+ :param request: The version of Python to install, e.g. 3.8,3.10.4
35
+ :return: A tuple of the PythonVersion and the download URL
36
+ """
33
37
  from ._versions import PYTHON_VERSIONS
34
38
 
35
39
  for py_ver, urls in PYTHON_VERSIONS.items():
@@ -55,8 +59,20 @@ def _read_sha256(url: str, sess: requests.Session) -> str | None:
55
59
 
56
60
 
57
61
  def download(url: str, destination: StrPath, session: requests.Session | None = None) -> str:
62
+ """Download the given url to the destination.
63
+
64
+ :param url: The url to download
65
+ :param destination: The file path to download to
66
+ :param session: A requests session to use for downloading, or None to create a new one
67
+ :return: The original filename of the downloaded file
68
+ """
58
69
  logger.debug("Downloading url %s to %s", url, destination)
59
70
  filename = unquote(url.rsplit("/")[-1])
71
+ try:
72
+ import requests
73
+ except ModuleNotFoundError:
74
+ raise RuntimeError("You must install requests to use this function") from None
75
+
60
76
  if session is None:
61
77
  session = requests.Session()
62
78
 
@@ -79,6 +95,13 @@ def download(url: str, destination: StrPath, session: requests.Session | None =
79
95
  def install_file(
80
96
  filename: StrPath, destination: StrPath, original_filename: str | None = None
81
97
  ) -> None:
98
+ """Unpack the downloaded file to the destination.
99
+
100
+ :param filename: The file to unpack
101
+ :param destination: The directory to unpack to
102
+ :param original_filename: The original filename of the file, if it was renamed
103
+ """
104
+
82
105
  import tarfile
83
106
 
84
107
  import zstandard as zstd
@@ -105,10 +128,23 @@ def install_file(
105
128
  unpack_tar(z, destination, 1)
106
129
 
107
130
 
108
- def install(request: str, destination: StrPath, session: requests.Session | None = None) -> None:
109
- """Download and install the requested python version"""
131
+ def install(
132
+ request: str,
133
+ destination: StrPath,
134
+ version_dir: bool = False,
135
+ session: requests.Session | None = None,
136
+ ) -> None:
137
+ """Download and install the requested python version.
138
+
139
+ :param request: The version of Python to install, e.g. 3.8,3.10.4
140
+ :param destination: The directory to install to
141
+ :param version_dir: Whether to install to a subdirectory named with the python version
142
+ :param session: A requests session to use for downloading
143
+ """
110
144
  ver, url = get_download_link(request)
111
- logger.debug("Installing %s", ver)
145
+ if version_dir:
146
+ destination = os.path.join(destination, str(ver))
147
+ logger.debug("Installing %s to %s", ver, destination)
112
148
  os.makedirs(destination, exist_ok=True)
113
149
  with tempfile.NamedTemporaryFile() as tf:
114
150
  tf.close()
@@ -1,17 +0,0 @@
1
- from argparse import ArgumentParser
2
-
3
- from ._install import install
4
-
5
-
6
- def main():
7
- parser = ArgumentParser("pbs-install")
8
- parser.add_argument("version", help="The version of Python to install, e.g. 3.8,3.10.4")
9
- parser.add_argument("-d", "--destination", help="The directory to install to", required=True)
10
-
11
- args = parser.parse_args()
12
- install(args.version, args.destination)
13
- print("Done!")
14
-
15
-
16
- if __name__ == "__main__":
17
- main()