Skip to content

Commit 4b5c8b7

Browse files
authored
docs: add doc for miniforge (#108)
1 parent aaf6b68 commit 4b5c8b7

File tree

2 files changed

+150
-16
lines changed

2 files changed

+150
-16
lines changed

docs/zh/miniforge.mdx

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
mirrorId: miniforge
3+
---
4+
import { Miniforge3Installer, CondaConfigGen } from '../../src/components/anaconda-config';
5+
6+
Miniforge 类似 Anaconda/Miniconda ,但以 conda-forge 为主要 channel ,使用 conda 和 mamba 管理软件包。
7+
8+
### 安装包下载
9+
10+
<Miniforge3Installer />
11+
12+
13+
### 设置软件包镜像
14+
15+
修改用户目录下的 `.condarc` 文件来使用浙大镜像源。
16+
17+
Windows 用户无法直接创建名为 `.condarc` 的文件,可先执行 `conda config --set show_channel_urls yes` 生成该文件之后再修改。
18+
19+
1. 根据需要修改 `.condarc` 配置如下:
20+
21+
<hr />
22+
23+
<CondaConfigGen isMiniforge3 />
24+
25+
<hr />
26+
27+
2. 运行 `conda clean -i` 清除索引缓存,保证用的是镜像站提供的索引。
28+
29+
3. 运行 `conda create -n myenv numpy` 测试一下吧。
30+
31+
### 反代 channel 说明
32+
33+
为解决校内访问问题,以下 channel 通过反代方式提供服务:
34+
35+
- nvidia
36+
37+
这些 channel 在校外访问时,会通过 302 请求重定向至官方源。
38+
39+
### 其他第三方源
40+
41+
暂不支持。

src/components/anaconda-config.tsx

+109-16
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const osNameDict: Record<string, string> = {
2525
MacOSX: 'macOS',
2626
Linux: 'Linux',
2727
};
28-
2928
const installerDict: Record<string, HumanReadableInstallerName> = {
3029
'': {},
3130
'Windows': {
@@ -49,6 +48,28 @@ const installerDict: Record<string, HumanReadableInstallerName> = {
4948
},
5049
};
5150

51+
const mf3Prefix = 'https://mirrors.zju.edu.cn/miniforge/';
52+
const mf3OsNameDict: Record<string, string> = {
53+
Windows: 'Windows',
54+
Darwin: 'macOS',
55+
Linux: 'Linux',
56+
};
57+
const mf3InstallerDict: Record<string, HumanReadableInstallerName> = {
58+
'': {},
59+
'Windows': {
60+
'x86_64.exe': 'x86_64 EXE',
61+
},
62+
'Darwin': {
63+
'arm64.sh': 'ARM64 SH (Apple Silicon)',
64+
'x86_64.sh': 'x86_64 SH (Intel)',
65+
},
66+
'Linux': {
67+
'x86_64.sh': 'x86_64 SH',
68+
'aarch64.sh': 'arm64 SH',
69+
'ppc64le.sh': 'ppc64le SH',
70+
},
71+
};
72+
5273
const MinicondaInstaller = () => {
5374
const [os, setOS] = useState('');
5475
const [variant, setVariant] = useState('');
@@ -116,6 +137,72 @@ const MinicondaInstaller = () => {
116137
);
117138
};
118139

140+
const Miniforge3Installer = () => {
141+
const [os, setOS] = useState('');
142+
const [variant, setVariant] = useState('');
143+
const installerName = os && variant ? `Miniforge3-${os}-${variant}` : '';
144+
145+
const handleOSChange: SelectProps['onChange'] = event => {
146+
setOS(event.target.value as string);
147+
setVariant('');
148+
};
149+
150+
const handleVariantChange: SelectProps['onChange'] = event => {
151+
setVariant(event.target.value as string);
152+
};
153+
154+
return (
155+
<div>
156+
<FormControl variant="standard" sx={{ m: 1, minWidth: 120 }}>
157+
<InputLabel id="os-select-label">操作系统</InputLabel>
158+
<Select
159+
labelId="os-select-label"
160+
id="os-select"
161+
value={os}
162+
onChange={handleOSChange}
163+
label="操作系统"
164+
>
165+
{Object.keys(mf3OsNameDict).map(osKey => (
166+
<MenuItem value={osKey} key={osKey}>
167+
{mf3OsNameDict[osKey]}
168+
</MenuItem>
169+
))}
170+
</Select>
171+
</FormControl>
172+
<FormControl variant="standard" sx={{ m: 1, minWidth: 300 }}>
173+
<InputLabel id="variant-select-label">
174+
系统架构 及 安装包类型
175+
</InputLabel>
176+
<Select
177+
labelId="variant-select-label"
178+
id="variant-select"
179+
value={variant}
180+
onChange={handleVariantChange}
181+
label="系统架构及安装包类型"
182+
>
183+
{Object.keys(mf3InstallerDict[os]).map(k => (
184+
<MenuItem value={k} key={`${os}-${k}`}>
185+
{mf3InstallerDict[os][k]}
186+
</MenuItem>
187+
))}
188+
</Select>
189+
</FormControl>
190+
<br />
191+
<Button
192+
variant="contained"
193+
startIcon={<DownloadIcon />}
194+
sx={{ m: 1 }}
195+
disabled={!installerName}
196+
href={mf3Prefix + installerName}
197+
>
198+
<Typography textTransform="none">
199+
下载 {installerName && `(${installerName})`}
200+
</Typography>
201+
</Button>
202+
</div>
203+
);
204+
};
205+
119206
const baseConf = `channels:
120207
- defaults
121208
show_channel_urls: true
@@ -207,7 +294,9 @@ const channelOriginToUrl = (origin: ChannelOrigin) => {
207294
return 'https://mirrors.zju.edu.cn/anaconda-r';
208295
};
209296

210-
const CondaConfigGen = () => {
297+
const CondaConfigGen: React.FC<{
298+
isMiniforge3?: boolean;
299+
}> = ({ isMiniforge3 }) => {
211300
const [showCustom, setShowCustom] = useState(false);
212301
const [channelStatus, setChannelStatus] = useState(defaultChannelStatus);
213302

@@ -221,7 +310,7 @@ const CondaConfigGen = () => {
221310
});
222311
};
223312

224-
let conf = baseConf;
313+
let conf = isMiniforge3 ? '' : baseConf;
225314
if (Object.values(channelStatus).some(v => v)) {
226315
conf += 'custom_channels:\n';
227316
}
@@ -243,18 +332,22 @@ const CondaConfigGen = () => {
243332
</FormGroup>
244333
<Collapse in={showCustom}>
245334
<FormGroup sx={{ flexDirection: 'row' }}>
246-
<FormControlLabel
247-
control={<Checkbox defaultChecked disabled />}
248-
label="pkgs/main"
249-
/>
250-
<FormControlLabel
251-
control={<Checkbox defaultChecked disabled />}
252-
label="pkgs/r"
253-
/>
254-
<FormControlLabel
255-
control={<Checkbox defaultChecked disabled />}
256-
label="pkgs/msys2"
257-
/>
335+
{!isMiniforge3 && (
336+
<>
337+
<FormControlLabel
338+
control={<Checkbox defaultChecked disabled />}
339+
label="pkgs/main"
340+
/>
341+
<FormControlLabel
342+
control={<Checkbox defaultChecked disabled />}
343+
label="pkgs/r"
344+
/>
345+
<FormControlLabel
346+
control={<Checkbox defaultChecked disabled />}
347+
label="pkgs/msys2"
348+
/>
349+
</>
350+
)}
258351
{Object.keys(channelStatus).map(channel => {
259352
return (
260353
<FormControlLabel
@@ -281,4 +374,4 @@ const CondaConfigGen = () => {
281374
);
282375
};
283376

284-
export { MinicondaInstaller, CondaConfigGen };
377+
export { MinicondaInstaller, Miniforge3Installer, CondaConfigGen };

0 commit comments

Comments
 (0)