bitool 0.1.2__tar.gz → 0.1.3__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.
Files changed (96) hide show
  1. {bitool-0.1.2 → bitool-0.1.3}/PKG-INFO +1 -1
  2. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/Cargo.toml +1 -1
  3. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/pyproject.toml +1 -1
  4. {bitool-0.1.2 → bitool-0.1.3}/pyproject.toml +1 -1
  5. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/__init__.py +1 -1
  6. bitool-0.1.3/src/bitool/scripts/envpy.py +174 -0
  7. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/pymake.py +10 -5
  8. bitool-0.1.2/src/bitool/scripts/envpy.py +0 -161
  9. {bitool-0.1.2 → bitool-0.1.3}/.gitignore +0 -0
  10. {bitool-0.1.2 → bitool-0.1.3}/README.md +0 -0
  11. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/.cargo/config.toml +0 -0
  12. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/.cargo/libs/python38.lib +0 -0
  13. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/.cargo/libs/windows.0.48.5.lib +0 -0
  14. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/README.md +0 -0
  15. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/core/cmd_exec.rs +0 -0
  16. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/core/config.rs +0 -0
  17. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/core/crypto.rs +0 -0
  18. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/core/file_ops.rs +0 -0
  19. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/core/mod.rs +0 -0
  20. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/core/pdf_ops.rs +0 -0
  21. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/core/profiler.rs +0 -0
  22. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/core/text_proc.rs +0 -0
  23. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/lib.rs +0 -0
  24. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/plugins/loader.rs +0 -0
  25. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/plugins/mod.rs +0 -0
  26. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/plugins/registry.rs +0 -0
  27. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/python/mod.rs +0 -0
  28. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/python/py_cmd_exec.rs +0 -0
  29. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/python/py_config.rs +0 -0
  30. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/python/py_file_ops.rs +0 -0
  31. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/python/py_pdf_ops.rs +0 -0
  32. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/python/py_profiler.rs +0 -0
  33. {bitool-0.1.2 → bitool-0.1.3}/bitool-core/src/python/py_text_proc.rs +0 -0
  34. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/cmd/__init__.py +0 -0
  35. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/cmd/_base.py +0 -0
  36. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/cmd/_condition.py +0 -0
  37. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/cmd/_scheduler.py +0 -0
  38. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/cmd/env.py +0 -0
  39. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/cmd/git.py +0 -0
  40. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/cmd/io.py +0 -0
  41. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/cmd/pdf.py +0 -0
  42. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/cmd/run.py +0 -0
  43. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/cmd/toml.py +0 -0
  44. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/cmd/version.py +0 -0
  45. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/consts.py +0 -0
  46. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/core/__init__.py +0 -0
  47. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/core/app.py +0 -0
  48. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/core/commands.py +0 -0
  49. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/core/config.py +0 -0
  50. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/core/env.py +0 -0
  51. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/core/logger.py +0 -0
  52. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/core/plugin.py +0 -0
  53. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/core/workspace.py +0 -0
  54. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/models/__init__.py +0 -0
  55. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/models/version.py +0 -0
  56. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/__init__.py +0 -0
  57. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/bumpversion.py +0 -0
  58. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/clearscreen.py +0 -0
  59. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/envrs.py +0 -0
  60. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/filedate.py +0 -0
  61. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/filelevel.py +0 -0
  62. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/gittool.py +0 -0
  63. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/img2pdf.py +0 -0
  64. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/pdf2img.py +0 -0
  65. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/piptool.py +0 -0
  66. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/sshcopyid.py +0 -0
  67. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/taskkill.py +0 -0
  68. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/scripts/which.py +0 -0
  69. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/types.py +0 -0
  70. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/utils/__init__.py +0 -0
  71. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/utils/cli_parser.py +0 -0
  72. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/utils/executor.py +0 -0
  73. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/utils/profiler.py +0 -0
  74. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/utils/task.py +0 -0
  75. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/utils/task_group.py +0 -0
  76. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/utils/tests/__init__.py +0 -0
  77. {bitool-0.1.2 → bitool-0.1.3}/src/bitool/utils/tests/test_profiler.py +0 -0
  78. {bitool-0.1.2 → bitool-0.1.3}/src/tests/__init__.py +0 -0
  79. {bitool-0.1.2 → bitool-0.1.3}/src/tests/cmd/__init__.py +0 -0
  80. {bitool-0.1.2 → bitool-0.1.3}/src/tests/cmd/test_base.py +0 -0
  81. {bitool-0.1.2 → bitool-0.1.3}/src/tests/cmd/test_condition.py +0 -0
  82. {bitool-0.1.2 → bitool-0.1.3}/src/tests/cmd/test_env.py +0 -0
  83. {bitool-0.1.2 → bitool-0.1.3}/src/tests/cmd/test_io.py +0 -0
  84. {bitool-0.1.2 → bitool-0.1.3}/src/tests/cmd/test_pdf.py +0 -0
  85. {bitool-0.1.2 → bitool-0.1.3}/src/tests/cmd/test_run.py +0 -0
  86. {bitool-0.1.2 → bitool-0.1.3}/src/tests/cmd/test_scheduler.py +0 -0
  87. {bitool-0.1.2 → bitool-0.1.3}/src/tests/cmd/test_toml.py +0 -0
  88. {bitool-0.1.2 → bitool-0.1.3}/src/tests/cmd/test_version.py +0 -0
  89. {bitool-0.1.2 → bitool-0.1.3}/src/tests/conftest.py +0 -0
  90. {bitool-0.1.2 → bitool-0.1.3}/src/tests/scripts/__init__.py +0 -0
  91. {bitool-0.1.2 → bitool-0.1.3}/src/tests/scripts/test_bumpversion.py +0 -0
  92. {bitool-0.1.2 → bitool-0.1.3}/src/tests/scripts/test_filelevel.py +0 -0
  93. {bitool-0.1.2 → bitool-0.1.3}/src/tests/scripts/test_gittool.py +0 -0
  94. {bitool-0.1.2 → bitool-0.1.3}/src/tests/scripts/test_img2pdf.py +0 -0
  95. {bitool-0.1.2 → bitool-0.1.3}/src/tests/scripts/test_pdf2img.py +0 -0
  96. {bitool-0.1.2 → bitool-0.1.3}/src/tests/scripts/test_piptool.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bitool
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: Bitool - Rust + Python 混合架构工具集
5
5
  Project-URL: Homepage, https://gitee.com/gooker_young/bitool
6
6
  Project-URL: Issues, https://gitee.com/gooker_young/bitool/issues
@@ -4,7 +4,7 @@ description = "Bitool Maturin - Rust + Python 混合架构工具集"
4
4
  edition = "2021"
5
5
  license = "MIT"
6
6
  name = "bitool_core"
7
- version = "0.1.2"
7
+ version = "0.1.3"
8
8
 
9
9
  [lib]
10
10
  crate-type = ["cdylib"]
@@ -20,4 +20,4 @@ license = { text = "MIT" }
20
20
  name = "bitool_core"
21
21
  readme = "README.md"
22
22
  requires-python = ">=3.8"
23
- version = "0.1.2"
23
+ version = "0.1.3"
@@ -27,7 +27,7 @@ license = { text = "MIT" }
27
27
  name = "bitool"
28
28
  readme = "README.md"
29
29
  requires-python = ">=3.8"
30
- version = "0.1.2"
30
+ version = "0.1.3"
31
31
 
32
32
  [project.urls]
33
33
  Homepage = "https://gitee.com/gooker_young/bitool"
@@ -1,6 +1,6 @@
1
1
  """Bitool Maturin - Rust + Python 混合架构工具集."""
2
2
 
3
- __version__ = "0.1.2"
3
+ __version__ = "0.1.3"
4
4
  __author__ = "gooker_young"
5
5
 
6
6
 
@@ -0,0 +1,174 @@
1
+ """Python环境配置工具模块。
2
+
3
+ 用于设置pip镜像源, 支持清华和阿里云等国内镜像源。
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import argparse
9
+ from pathlib import Path
10
+
11
+ from bitool.cmd import CommandScheduler, SetEnvCommand, WriteFileCommand
12
+ from bitool.consts import Constants
13
+ from bitool.core import ConfigMixin
14
+
15
+
16
+ class EnvPyConfig(ConfigMixin):
17
+ """Python环境配置类。"""
18
+
19
+ # pip 镜像源配置
20
+ PIP_DEFAULT_INDEX_URL: str = "https://pypi.org/simple"
21
+ PIP_INDEX_URLS: dict[str, str] = { # noqa: RUF012
22
+ "tsinghua": "https://pypi.tuna.tsinghua.edu.cn/simple",
23
+ "aliyun": "https://mirrors.aliyun.com/pypi/simple/",
24
+ }
25
+ PIP_TRUSTED_HOSTS: dict[str, str] = { # noqa: RUF012
26
+ "tsinghua": "pypi.tuna.tsinghua.edu.cn",
27
+ "aliyun": "mirrors.aliyun.com",
28
+ }
29
+
30
+ # UV相关配置
31
+ UV_INDEX_URL: str = "https://mirrors.aliyun.com/pypi/simple/"
32
+ UV_DEFAULT_INDEX: str = "https://mirrors.aliyun.com/pypi/simple/"
33
+ UV_HTTP_TIMEOUT: int = 600
34
+ UV_LINK_MODE: str = "copy"
35
+
36
+ # Conda相关配置
37
+ CONDA_DEFAULT_MIRROR = "tsinghua"
38
+ _CONDA_MIRROR_URLS: dict[str, list[str]] = { # noqa: RUF012
39
+ "tsinghua": [
40
+ "https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/",
41
+ "https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/",
42
+ "https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/",
43
+ "https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/",
44
+ "https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/",
45
+ "https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/",
46
+ "https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/",
47
+ "https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/",
48
+ "https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/",
49
+ ],
50
+ "ustc": [
51
+ "https://mirrors.ustc.edu.cn/anaconda/pkgs/main/",
52
+ "https://mirrors.ustc.edu.cn/anaconda/pkgs/free/",
53
+ "https://mirrors.ustc.edu.cn/anaconda/pkgs/r/",
54
+ "https://mirrors.ustc.edu.cn/anaconda/pkgs/msys2/",
55
+ "https://mirrors.ustc.edu.cn/anaconda/pkgs/pro/",
56
+ "https://mirrors.ustc.edu.cn/anaconda/pkgs/dev/",
57
+ "https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/",
58
+ "https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/",
59
+ "https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/",
60
+ "https://mirrors.ustc.edu.cn/anaconda/cloud/pytorch/",
61
+ ],
62
+ "bsfu": [
63
+ "https://mirrors.bsfu.edu.cn/anaconda/pkgs/main/",
64
+ "https://mirrors.bsfu.edu.cn/anaconda/pkgs/free/",
65
+ "https://mirrors.bsfu.edu.cn/anaconda/pkgs/r/",
66
+ "https://mirrors.bsfu.edu.cn/anaconda/pkgs/msys2/",
67
+ "https://mirrors.bsfu.edu.cn/anaconda/pkgs/pro/",
68
+ "https://mirrors.bsfu.edu.cn/anaconda/pkgs/dev/",
69
+ "https://mirrors.bsfu.edu.cn/anaconda/cloud/conda-forge/",
70
+ "https://mirrors.bsfu.edu.cn/anaconda/cloud/bioconda/",
71
+ "https://mirrors.bsfu.edu.cn/anaconda/cloud/menpo/",
72
+ "https://mirrors.bsfu.edu.cn/anaconda/cloud/pytorch/",
73
+ ],
74
+ "aliyun": [
75
+ "https://mirrors.aliyun.com/anaconda/pkgs/main/",
76
+ "https://mirrors.aliyun.com/anaconda/pkgs/free/",
77
+ "https://mirrors.aliyun.com/anaconda/pkgs/r/",
78
+ "https://mirrors.aliyun.com/anaconda/pkgs/msys2/",
79
+ "https://mirrors.aliyun.com/anaconda/pkgs/pro/",
80
+ "https://mirrors.aliyun.com/anaconda/pkgs/dev/",
81
+ "https://mirrors.aliyun.com/anaconda/cloud/conda-forge/",
82
+ "https://mirrors.aliyun.com/anaconda/cloud/bioconda/",
83
+ "https://mirrors.aliyun.com/anaconda/cloud/menpo/",
84
+ "https://mirrors.aliyun.com/anaconda/cloud/pytorch/",
85
+ ],
86
+ }
87
+
88
+
89
+ conf = EnvPyConfig()
90
+
91
+
92
+ def create_scheduler(
93
+ mirror: str = "tsinghua", token: str | None = None
94
+ ) -> CommandScheduler:
95
+ """创建设置pip镜像源的命令调度器。
96
+
97
+ Args:
98
+ mirror: 镜像源名称, 默认为"tsinghua"。
99
+
100
+ Returns:
101
+ 命令调度器实例。
102
+ """
103
+ return CommandScheduler(
104
+ commands=[
105
+ SetEnvCommand(
106
+ envs=[
107
+ (
108
+ "PIP_INDEX_URL",
109
+ conf.PIP_INDEX_URLS.get(mirror, conf.PIP_DEFAULT_INDEX_URL),
110
+ ),
111
+ ("UV_INDEX_URL", conf.UV_INDEX_URL),
112
+ ("UV_DEFAULT_INDEX", conf.UV_DEFAULT_INDEX),
113
+ ("UV_HTTP_TIMEOUT", str(conf.UV_HTTP_TIMEOUT)),
114
+ ("UV_LINK_MODE", conf.UV_LINK_MODE),
115
+ ]
116
+ ),
117
+ WriteFileCommand(
118
+ filepath=Path.home() / ".pip" / "pip.conf"
119
+ if Constants.IS_UNIX
120
+ else Path.home() / "pip" / "pip.ini",
121
+ content=f"[global]\nindex-url = {conf.PIP_INDEX_URLS.get(mirror, conf.PIP_DEFAULT_INDEX_URL)}\
122
+ \n[install]\ntrusted-host = {conf.PIP_TRUSTED_HOSTS.get(mirror, '')}",
123
+ ),
124
+ WriteFileCommand(
125
+ filepath=Path.home() / ".condarc",
126
+ content="show_channel_urls: true\nchannels:\n"
127
+ + "\n".join(
128
+ f" - {url}"
129
+ for url in conf._CONDA_MIRROR_URLS.get(
130
+ mirror, conf._CONDA_MIRROR_URLS["tsinghua"]
131
+ )
132
+ )
133
+ + "\n - defaults",
134
+ ),
135
+ WriteFileCommand(
136
+ filepath=Path.home() / ".pypirc",
137
+ content=f"""[pypi]
138
+ repository: https://upload.pypi.org/legacy/
139
+ username: __token__
140
+ password: {token if token else ""}
141
+ """,
142
+ allow_conditions=[(lambda: bool(token), "有效的token")],
143
+ ),
144
+ ]
145
+ )
146
+
147
+
148
+ def parse_args() -> argparse.Namespace:
149
+ """解析命令行参数。
150
+
151
+ Returns:
152
+ 解析后的参数命名空间。
153
+ """
154
+ parser = argparse.ArgumentParser(description="设置Python包的pip镜像源")
155
+ parser.add_argument(
156
+ "mirror",
157
+ type=str,
158
+ nargs="?",
159
+ default="tsinghua",
160
+ choices=conf.PIP_INDEX_URLS.keys(),
161
+ help="要使用的pip镜像源",
162
+ )
163
+ parser.add_argument(
164
+ "--token", type=str, nargs="?", help="PyPI token for publishing"
165
+ )
166
+ return parser.parse_args()
167
+
168
+
169
+ def main() -> None:
170
+ """主函数, 解析命令行参数并运行调度器。"""
171
+ args = parse_args()
172
+
173
+ scheduler = create_scheduler(mirror=args.mirror, token=args.token)
174
+ scheduler.run()
@@ -53,6 +53,7 @@ conf = PyMakeConfig()
53
53
  _MATURIN_CONDITION = BuiltinConditions.HAS_APP_INSTALLED(conf.MATURIN_TOOL)
54
54
  _PYTEST_CONDITION = BuiltinConditions.HAS_APP_INSTALLED("pytest")
55
55
  _UV_CONDITION = BuiltinConditions.HAS_APP_INSTALLED(conf.BUILD_TOOL)
56
+ _HATCH_CONDITION = BuiltinConditions.HAS_APP_INSTALLED("hatch")
56
57
  _RUFF_CONDITION = BuiltinConditions.HAS_APP_INSTALLED("ruff")
57
58
  _GIT_CONDITION = BuiltinConditions.HAS_APP_INSTALLED("git")
58
59
 
@@ -240,18 +241,22 @@ def create_scheduler_map() -> dict[str, CommandScheduler]:
240
241
  # 发布到 PyPI(先发布 Rust 核心模块,再发布 Python 主包)
241
242
  "pb": CommandScheduler(
242
243
  commands=[
243
- # 发布 Rust 核心模块
244
+ # 发布 Rust 核心模块(在 core 目录执行)
244
245
  RunCommand(
245
- cmd=["maturin", "publish", "-r"],
246
+ name="publish-rust",
247
+ cmd=["maturin", "publish"],
246
248
  cwd=conf.CORE_DIR,
247
249
  allow_conditions=[_MATURIN_CONDITION],
248
250
  timeout=conf.BUILD_TIMEOUT,
249
251
  ),
250
- # 发布 Python 主包
252
+ # 发布 Python 主包(在项目根目录执行,依赖 Rust 发布成功)
251
253
  RunCommand(
252
- cmd=["uv", "publish"],
253
- allow_conditions=[_UV_CONDITION],
254
+ name="publish-python",
255
+ cmd=["hatch", "publish"],
256
+ cwd=conf.PROJECT_ROOT,
257
+ allow_conditions=[_HATCH_CONDITION],
254
258
  timeout=conf.BUILD_TIMEOUT,
259
+ dependencies=["publish-rust"],
255
260
  ),
256
261
  ]
257
262
  ),
@@ -1,161 +0,0 @@
1
- """Python环境配置工具模块。
2
-
3
- 用于设置pip镜像源, 支持清华和阿里云等国内镜像源。
4
- """
5
-
6
- from __future__ import annotations
7
-
8
- import argparse
9
- from pathlib import Path
10
-
11
- from bitool.cmd import CommandScheduler, SetEnvCommand, WriteFileCommand
12
- from bitool.consts import Constants
13
- from bitool.core import ConfigMixin
14
-
15
-
16
- class EnvPyConfig(ConfigMixin):
17
- """Python环境配置类。"""
18
-
19
- # pip 镜像源配置
20
- PIP_DEFAULT_INDEX_URL: str = "https://pypi.org/simple"
21
- PIP_INDEX_URLS: dict[str, str] = { # noqa: RUF012
22
- "tsinghua": "https://pypi.tuna.tsinghua.edu.cn/simple",
23
- "aliyun": "https://mirrors.aliyun.com/pypi/simple/",
24
- }
25
- PIP_TRUSTED_HOSTS: dict[str, str] = { # noqa: RUF012
26
- "tsinghua": "pypi.tuna.tsinghua.edu.cn",
27
- "aliyun": "mirrors.aliyun.com",
28
- }
29
-
30
- # UV相关配置
31
- UV_INDEX_URL: str = "https://mirrors.aliyun.com/pypi/simple/"
32
- UV_DEFAULT_INDEX: str = "https://mirrors.aliyun.com/pypi/simple/"
33
- UV_HTTP_TIMEOUT: int = 600
34
- UV_LINK_MODE: str = "copy"
35
-
36
- # Conda相关配置
37
- CONDA_DEFAULT_MIRROR = "tsinghua"
38
- _CONDA_MIRROR_URLS: dict[str, frozenset[str]] = { # noqa: RUF012
39
- "tsinghua": frozenset(
40
- [
41
- "https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/",
42
- "https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/",
43
- "https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/",
44
- "https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2/",
45
- "https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/",
46
- "https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/",
47
- "https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/",
48
- "https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/",
49
- "https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/",
50
- ]
51
- ),
52
- "ustc": frozenset(
53
- [
54
- "https://mirrors.ustc.edu.cn/anaconda/pkgs/main/",
55
- "https://mirrors.ustc.edu.cn/anaconda/pkgs/free/",
56
- "https://mirrors.ustc.edu.cn/anaconda/pkgs/r/",
57
- "https://mirrors.ustc.edu.cn/anaconda/pkgs/msys2/",
58
- "https://mirrors.ustc.edu.cn/anaconda/pkgs/pro/",
59
- "https://mirrors.ustc.edu.cn/anaconda/pkgs/dev/",
60
- "https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/",
61
- "https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/",
62
- "https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/",
63
- "https://mirrors.ustc.edu.cn/anaconda/cloud/pytorch/",
64
- ]
65
- ),
66
- "bsfu": frozenset(
67
- [
68
- "https://mirrors.bsfu.edu.cn/anaconda/pkgs/main/",
69
- "https://mirrors.bsfu.edu.cn/anaconda/pkgs/free/",
70
- "https://mirrors.bsfu.edu.cn/anaconda/pkgs/r/",
71
- "https://mirrors.bsfu.edu.cn/anaconda/pkgs/msys2/",
72
- "https://mirrors.bsfu.edu.cn/anaconda/pkgs/pro/",
73
- "https://mirrors.bsfu.edu.cn/anaconda/pkgs/dev/",
74
- "https://mirrors.bsfu.edu.cn/anaconda/cloud/conda-forge/",
75
- "https://mirrors.bsfu.edu.cn/anaconda/cloud/bioconda/",
76
- "https://mirrors.bsfu.edu.cn/anaconda/cloud/menpo/",
77
- "https://mirrors.bsfu.edu.cn/anaconda/cloud/pytorch/",
78
- ]
79
- ),
80
- "aliyun": frozenset(
81
- [
82
- "https://mirrors.aliyun.com/anaconda/pkgs/main/",
83
- "https://mirrors.aliyun.com/anaconda/pkgs/free/",
84
- "https://mirrors.aliyun.com/anaconda/pkgs/r/",
85
- "https://mirrors.aliyun.com/anaconda/pkgs/msys2/",
86
- "https://mirrors.aliyun.com/anaconda/pkgs/pro/",
87
- "https://mirrors.aliyun.com/anaconda/pkgs/dev/",
88
- "https://mirrors.aliyun.com/anaconda/cloud/conda-forge/",
89
- "https://mirrors.aliyun.com/anaconda/cloud/bioconda/",
90
- "https://mirrors.aliyun.com/anaconda/cloud/menpo/",
91
- "https://mirrors.aliyun.com/anaconda/cloud/pytorch/",
92
- ]
93
- ),
94
- }
95
-
96
-
97
- conf = EnvPyConfig()
98
-
99
-
100
- def create_scheduler(mirror: str = "tsinghua") -> CommandScheduler:
101
- """创建设置pip镜像源的命令调度器。
102
-
103
- Args:
104
- mirror: 镜像源名称, 默认为"tsinghua"。
105
-
106
- Returns:
107
- 命令调度器实例。
108
- """
109
- return CommandScheduler(
110
- commands=[
111
- SetEnvCommand(
112
- envs=[
113
- (
114
- "PIP_INDEX_URL",
115
- conf.PIP_INDEX_URLS.get(mirror, conf.PIP_DEFAULT_INDEX_URL),
116
- ),
117
- ("UV_INDEX_URL", conf.UV_INDEX_URL),
118
- ("UV_DEFAULT_INDEX", conf.UV_DEFAULT_INDEX),
119
- ("UV_HTTP_TIMEOUT", str(conf.UV_HTTP_TIMEOUT)),
120
- ("UV_LINK_MODE", conf.UV_LINK_MODE),
121
- ]
122
- ),
123
- WriteFileCommand(
124
- filepath=Path.home() / ".pip" / "pip.conf"
125
- if Constants.IS_UNIX
126
- else Path.home() / "pip" / "pip.ini",
127
- content=f"[global]\nindex-url = {conf.PIP_INDEX_URLS.get(mirror, conf.PIP_DEFAULT_INDEX_URL)}\
128
- \n[install]\ntrusted-host = {conf.PIP_TRUSTED_HOSTS.get(mirror, '')}",
129
- ),
130
- WriteFileCommand(
131
- filepath=Path.home() / ".condarc",
132
- content=f"show_channel_urls: true\nchannels:\n - {conf._CONDA_MIRROR_URLS.get(mirror, conf._CONDA_MIRROR_URLS['tsinghua'])}\n - defaults",
133
- ),
134
- ]
135
- )
136
-
137
-
138
- def parse_args() -> argparse.Namespace:
139
- """解析命令行参数。
140
-
141
- Returns:
142
- 解析后的参数命名空间。
143
- """
144
- parser = argparse.ArgumentParser(description="设置Python包的pip镜像源")
145
- parser.add_argument(
146
- "mirror",
147
- type=str,
148
- nargs="?",
149
- default="tsinghua",
150
- choices=conf.PIP_INDEX_URLS.keys(),
151
- help="要使用的pip镜像源",
152
- )
153
- return parser.parse_args()
154
-
155
-
156
- def main() -> None:
157
- """主函数, 解析命令行参数并运行调度器。"""
158
- args = parse_args()
159
-
160
- scheduler = create_scheduler(mirror=args.mirror)
161
- scheduler.run()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes