multi-lang-build 0.2.1__py3-none-any.whl → 0.2.3__py3-none-any.whl

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.
@@ -0,0 +1,340 @@
1
+ """Mirror configuration CLI for domestic acceleration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ import subprocess
8
+ import sys
9
+ from pathlib import Path
10
+ from typing import Literal
11
+
12
+
13
+ def get_all_mirrors() -> dict:
14
+ """Get all available mirrors with their configurations."""
15
+ from multi_lang_build.mirror.config import MIRROR_CONFIGS
16
+
17
+ mirrors = {}
18
+ for key, config in MIRROR_CONFIGS.items():
19
+ mirrors[key] = {
20
+ "name": config["name"],
21
+ "url": config["url"],
22
+ }
23
+ return mirrors
24
+
25
+
26
+ def print_mirrors() -> None:
27
+ """Print all available mirrors."""
28
+ mirrors = get_all_mirrors()
29
+
30
+ print("\n📦 Available Mirrors:")
31
+ print("-" * 60)
32
+
33
+ # Group by category
34
+ categories = {
35
+ "js": ["npm", "pnpm", "yarn"],
36
+ "go": ["go", "go_qiniu", "go_vip"],
37
+ "python": ["pip", "pip_aliyun", "pip_douban", "pip_huawei", "python", "poetry"],
38
+ }
39
+
40
+ category_names = {
41
+ "js": "🌐 JavaScript (npm/pnpm/yarn)",
42
+ "go": "🔷 Go",
43
+ "python": "🐍 Python (pip/PyPI)",
44
+ }
45
+
46
+ for cat_key, cat_mirrors in categories.items():
47
+ print(f"\n{category_names.get(cat_key, cat_key)}")
48
+ for mirror_key in cat_mirrors:
49
+ if mirror_key in mirrors:
50
+ config = mirrors[mirror_key]
51
+ print(f" • {mirror_key:12} - {config['name']}")
52
+ print(f" {config['url']}")
53
+
54
+ print()
55
+
56
+
57
+ def configure_pip(mirror_key: str) -> bool:
58
+ """Configure pip mirror using pip config command."""
59
+ from multi_lang_build.mirror.config import get_mirror_config
60
+
61
+ config = get_mirror_config(mirror_key)
62
+ if config is None:
63
+ print(f"❌ Unknown pip mirror: {mirror_key}")
64
+ return False
65
+
66
+ url = config["url"]
67
+ if not url.endswith("/simple") and not url.endswith("/simple/"):
68
+ url = f"{url}/simple"
69
+
70
+ # Try pip3 first, fallback to pip
71
+ pip_cmd = "pip3" if sys.platform != "win32" else "pip"
72
+
73
+ try:
74
+ subprocess.run(
75
+ [pip_cmd, "config", "set", "global.index-url", url],
76
+ check=True,
77
+ )
78
+ print(f"✅ pip mirror set to: {url}")
79
+ return True
80
+ except subprocess.CalledProcessError as e:
81
+ print(f"❌ Failed to set pip mirror: {e}")
82
+ return False
83
+ except FileNotFoundError:
84
+ # Try alternative
85
+ try:
86
+ alternative = "pip" if pip_cmd == "pip3" else "pip3"
87
+ subprocess.run(
88
+ [alternative, "config", "set", "global.index-url", url],
89
+ check=True,
90
+ )
91
+ print(f"✅ pip mirror set to: {url}")
92
+ return True
93
+ except Exception:
94
+ print("❌ pip/pip3 not found")
95
+ return False
96
+
97
+
98
+ def configure_go(mirror_key: str) -> bool:
99
+ """Configure Go proxy using go env -w."""
100
+ from multi_lang_build.mirror.config import get_mirror_config
101
+
102
+ config = get_mirror_config(mirror_key)
103
+ if config is None:
104
+ print(f"❌ Unknown Go mirror: {mirror_key}")
105
+ return False
106
+
107
+ # Get the GOPROXY value from environment variables
108
+ proxy_value = config["environment_variables"].get("GOPROXY", f"{config['url']},direct")
109
+
110
+ try:
111
+ subprocess.run(
112
+ ["go", "env", "-w", f"GOPROXY={proxy_value}"],
113
+ check=True,
114
+ )
115
+ print(f"✅ Go GOPROXY set to: {proxy_value}")
116
+
117
+ # Also set GOSUMDB if present
118
+ gosumdb = config["environment_variables"].get("GOSUMDB")
119
+ if gosumdb:
120
+ subprocess.run(
121
+ ["go", "env", "-w", f"GOSUMDB={gosumdb}"],
122
+ check=True,
123
+ )
124
+ print(f"✅ Go GOSUMDB set to: {gosumdb}")
125
+
126
+ return True
127
+ except subprocess.CalledProcessError as e:
128
+ print(f"❌ Failed to set Go mirror: {e}")
129
+ return False
130
+ except FileNotFoundError:
131
+ print("❌ go not found")
132
+ return False
133
+
134
+
135
+ def configure_npm(mirror_key: str) -> bool:
136
+ """Configure npm/pnpm registry."""
137
+ from multi_lang_build.mirror.config import get_mirror_config
138
+
139
+ config = get_mirror_config(mirror_key)
140
+ if config is None:
141
+ print(f"❌ Unknown npm mirror: {mirror_key}")
142
+ return False
143
+
144
+ url = config["url"]
145
+
146
+ try:
147
+ subprocess.run(
148
+ ["npm", "config", "set", "registry", url],
149
+ check=True,
150
+ )
151
+ print(f"✅ npm registry set to: {url}")
152
+
153
+ # Also set for pnpm if available
154
+ try:
155
+ subprocess.run(
156
+ ["pnpm", "config", "set", "registry", url],
157
+ check=True,
158
+ )
159
+ print(f"✅ pnpm registry set to: {url}")
160
+ except (subprocess.CalledProcessError, FileNotFoundError):
161
+ pass
162
+
163
+ return True
164
+ except subprocess.CalledProcessError as e:
165
+ print(f"❌ Failed to set npm registry: {e}")
166
+ return False
167
+ except FileNotFoundError:
168
+ print("❌ npm not found")
169
+ return False
170
+
171
+
172
+ def get_current_config() -> dict:
173
+ """Get current mirror configuration."""
174
+ config = {}
175
+
176
+ # Try pip3 first, fallback to pip
177
+ pip_cmd = "pip3" if sys.platform != "win32" else "pip"
178
+
179
+ try:
180
+ result = subprocess.run(
181
+ [pip_cmd, "config", "get", "global.index-url"],
182
+ capture_output=True,
183
+ text=True,
184
+ )
185
+ if result.returncode == 0 and result.stdout.strip():
186
+ config["pip"] = result.stdout.strip()
187
+ except Exception:
188
+ pass
189
+
190
+ # Check Go
191
+ try:
192
+ result = subprocess.run(
193
+ ["go", "env", "GOPROXY"],
194
+ capture_output=True,
195
+ text=True,
196
+ )
197
+ if result.returncode == 0:
198
+ config["go"] = result.stdout.strip()
199
+ except Exception:
200
+ pass
201
+
202
+ # Check npm
203
+ try:
204
+ result = subprocess.run(
205
+ ["npm", "config", "get", "registry"],
206
+ capture_output=True,
207
+ text=True,
208
+ )
209
+ if result.returncode == 0:
210
+ config["npm"] = result.stdout.strip()
211
+ except Exception:
212
+ pass
213
+
214
+ return config
215
+
216
+
217
+ def configure_mirror(mirror_type: str, mirror_key: str) -> bool:
218
+ """Configure mirror for a specific package manager.
219
+
220
+ Args:
221
+ mirror_type: Package manager type (pip, go, npm)
222
+ mirror_key: Mirror key to use
223
+
224
+ Returns:
225
+ True if successful, False otherwise
226
+ """
227
+ if mirror_type == "pip":
228
+ return configure_pip(mirror_key)
229
+ elif mirror_type == "go":
230
+ return configure_go(mirror_key)
231
+ elif mirror_type in ["npm", "pnpm"]:
232
+ return configure_npm(mirror_key)
233
+ else:
234
+ print(f"❌ Unknown package manager: {mirror_type}")
235
+ return False
236
+
237
+
238
+ def mirror_main():
239
+ """Main entry point for mirror command."""
240
+ import argparse
241
+
242
+ parser = argparse.ArgumentParser(
243
+ description="Configure domestic mirror acceleration",
244
+ epilog="""
245
+ Examples:
246
+ %(prog)s list List all available mirrors
247
+ %(prog)s set pip Configure pip mirror (default)
248
+ %(prog)s set go Configure Go proxy
249
+ %(prog)s set npm Configure npm registry
250
+ %(prog)s show Show current configuration
251
+ """,
252
+ )
253
+ parser.add_argument(
254
+ "--version",
255
+ action="version",
256
+ version="%(prog)s 0.2.2",
257
+ )
258
+
259
+ subparsers = parser.add_subparsers(dest="command", help="Commands")
260
+
261
+ # list command
262
+ list_parser = subparsers.add_parser("list", help="List available mirrors")
263
+ list_parser.add_argument(
264
+ "--json",
265
+ action="store_true",
266
+ help="Output as JSON",
267
+ )
268
+ list_parser.add_argument(
269
+ "--type",
270
+ type=str,
271
+ choices=["pip", "go", "npm"],
272
+ help="Filter by type",
273
+ )
274
+
275
+ # set command
276
+ set_parser = subparsers.add_parser("set", help="Configure mirror")
277
+ set_parser.add_argument(
278
+ "type",
279
+ type=str,
280
+ default="pip",
281
+ nargs="?",
282
+ choices=["pip", "go", "npm", "pnpm"],
283
+ help="Package manager type (default: pip)",
284
+ )
285
+ set_parser.add_argument(
286
+ "mirror",
287
+ type=str,
288
+ nargs="?",
289
+ default="pip",
290
+ help="Mirror to use",
291
+ )
292
+
293
+ # show command
294
+ show_parser = subparsers.add_parser("show", help="Show current mirror configuration")
295
+
296
+ args = parser.parse_args()
297
+
298
+ if args.command == "list":
299
+ mirrors = get_all_mirrors()
300
+ if getattr(args, "json", False):
301
+ print(json.dumps(mirrors, indent=2, ensure_ascii=False))
302
+ else:
303
+ print_mirrors()
304
+
305
+ elif args.command == "set":
306
+ mirror_type = args.type
307
+ mirror_key = args.mirror
308
+ success = configure_mirror(mirror_type, mirror_key)
309
+ sys.exit(0 if success else 1)
310
+
311
+ elif args.command == "show":
312
+ config = get_current_config()
313
+ if config:
314
+ print("\n📦 Current Mirror Configuration:")
315
+ print("-" * 40)
316
+ for key, value in config.items():
317
+ print(f" • {key}: {value}")
318
+ print()
319
+ else:
320
+ print("\n📦 No mirror configured")
321
+ print(" Run 'multi-lang-build mirror set <type> <mirror>' to configure")
322
+ print()
323
+ print_mirrors()
324
+
325
+ else:
326
+ # No subcommand, show help
327
+ parser.print_help()
328
+ print("\n📋 Commands:")
329
+ print(" list List all available mirrors")
330
+ print(" set <type> <name> Configure mirror (type: pip/go/npm)")
331
+ print(" show Show current configuration")
332
+ print("\n📋 Examples:")
333
+ print(" multi-lang-build mirror list")
334
+ print(" multi-lang-build mirror set pip")
335
+ print(" multi-lang-build mirror set go")
336
+ print(" multi-lang-build mirror set npm")
337
+
338
+
339
+ if __name__ == "__main__":
340
+ mirror_main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: multi-lang-build
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: Multi-language automated build tool with domestic mirror acceleration support
5
5
  Project-URL: Homepage, https://github.com/example/multi-lang-build
6
6
  Project-URL: Repository, https://github.com/example/multi-lang-build
@@ -0,0 +1,18 @@
1
+ multi_lang_build/__init__.py,sha256=Mbf6osu53IHciannWp_l6rZtEiCZEZmXSMhv9rC4G8M,1777
2
+ multi_lang_build/cli.py,sha256=cOlXyJKdb6sReBPyCLZgQhCkJOA_lbkY67Xfk-hGbPc,12949
3
+ multi_lang_build/py.typed,sha256=c8jtFarMovqA5DdwhEzKPH4WrX85xaoiWilIlvuc6KU,84
4
+ multi_lang_build/register.py,sha256=aws1xEaNKH4pMkwBxoKizPh8Anr1Wz0ukUhi_d5In_w,13840
5
+ multi_lang_build/types.py,sha256=iCyz_6KmEBU4xwpCtfJnpzXoiSsmOcOKOhzHJVx8Z4Q,1043
6
+ multi_lang_build/compiler/__init__.py,sha256=y5vvVN6HdSzq4W1kXBMy_vQq9G3-TtiVcNMOyBQHbCw,484
7
+ multi_lang_build/compiler/base.py,sha256=crtDW9bthfV-FSpp96O2Hi0DrViNqcIt4TjAVK2lPXE,9391
8
+ multi_lang_build/compiler/go.py,sha256=JV0GdHfhe-Lqyh7byMX_HguQ_XMwspW9RtHZIG1wyAo,15273
9
+ multi_lang_build/compiler/pnpm.py,sha256=BDUVZCX5PuhqlFp_ARKUMbLqUDLraTlKp3tdom60hzk,15774
10
+ multi_lang_build/compiler/python.py,sha256=8XqE_Jp_G-x6g5Qrux4tCV8Ag-zZqLLLXapSIzcSLJw,17662
11
+ multi_lang_build/mirror/__init__.py,sha256=RrZOQ83bxImAR275zeAUKyyCgwqdGt5xH8tF_-UShJo,489
12
+ multi_lang_build/mirror/cli.py,sha256=qv6RI6izxUIsfMCIDOtTK3avcNSJpAaUF3NPiK1W49A,9820
13
+ multi_lang_build/mirror/config.py,sha256=d9KJoV80BUZOR9R3DpcT1r0nyxH1HK6hfLZU7IsUGcw,8552
14
+ multi_lang_build-0.2.3.dist-info/METADATA,sha256=wk7FFDlFNXICxtmIUMMk_9KRDQdHumEIFEU3YJRYNXM,9055
15
+ multi_lang_build-0.2.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
16
+ multi_lang_build-0.2.3.dist-info/entry_points.txt,sha256=0vd5maQH5aZoqnpbr2Yr_IWB_-ncWX1rO3jGBCW3pHY,319
17
+ multi_lang_build-0.2.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
18
+ multi_lang_build-0.2.3.dist-info/RECORD,,
@@ -1,6 +1,7 @@
1
1
  [console_scripts]
2
2
  go-build = multi_lang_build.compiler.go:main
3
3
  multi-lang-build = multi_lang_build:main
4
+ multi-lang-mirror = multi_lang_build.mirror.cli:mirror_main
4
5
  multi-lang-register = multi_lang_build:main_register
5
6
  pnpm-build = multi_lang_build.compiler.pnpm:main
6
7
  python-build = multi_lang_build.compiler.python:main
@@ -1,17 +0,0 @@
1
- multi_lang_build/__init__.py,sha256=FvlY43Kj6VO5iwosAJy3GU9_QdAWmdF_bd3_G8rOg78,1626
2
- multi_lang_build/cli.py,sha256=MV_RnKcHBCy6v6XQdkQCTFOy5gTuHlNCtZ1K1k8OB2M,10134
3
- multi_lang_build/py.typed,sha256=c8jtFarMovqA5DdwhEzKPH4WrX85xaoiWilIlvuc6KU,84
4
- multi_lang_build/register.py,sha256=aws1xEaNKH4pMkwBxoKizPh8Anr1Wz0ukUhi_d5In_w,13840
5
- multi_lang_build/types.py,sha256=iCyz_6KmEBU4xwpCtfJnpzXoiSsmOcOKOhzHJVx8Z4Q,1043
6
- multi_lang_build/compiler/__init__.py,sha256=y5vvVN6HdSzq4W1kXBMy_vQq9G3-TtiVcNMOyBQHbCw,484
7
- multi_lang_build/compiler/base.py,sha256=jZvXh16KA0-kxd6ueY2xNtMoFNN9g8Kho3-2Ys4RQ7w,5743
8
- multi_lang_build/compiler/go.py,sha256=pwrZe4FOUEjl1EASGrW1JQ1y26l-06ArW7H42l57Blo,14758
9
- multi_lang_build/compiler/pnpm.py,sha256=7JiN4SoPy6oUkmBp_4RLuGLbq_3J5no_vsd6rGdPMBY,14014
10
- multi_lang_build/compiler/python.py,sha256=Vsw9JFuZQPkSwFbNbirUpb4613ti3kaq3EVvYPVCXrc,17320
11
- multi_lang_build/mirror/__init__.py,sha256=RrZOQ83bxImAR275zeAUKyyCgwqdGt5xH8tF_-UShJo,489
12
- multi_lang_build/mirror/config.py,sha256=d9KJoV80BUZOR9R3DpcT1r0nyxH1HK6hfLZU7IsUGcw,8552
13
- multi_lang_build-0.2.1.dist-info/METADATA,sha256=c4rllbEeDDB6qhiaN_JG91RMTg3NEUgDvzCc7FUMGtQ,9055
14
- multi_lang_build-0.2.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
15
- multi_lang_build-0.2.1.dist-info/entry_points.txt,sha256=1JxmXQltgTEvzWWu2u4aKRX_z8DoDM3VYJfCncjBaYY,259
16
- multi_lang_build-0.2.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
- multi_lang_build-0.2.1.dist-info/RECORD,,