我认为您是在专门询问启动器中笔记本内核的顺序。
排序顺序看起来有点随意,但也许我没有看到它使用的模式。
它首先是“默认”(或“本机”)内核,然后是根据它们的display_name
.
有人知道如何更改启动器上图标的排序顺序吗?
据我所见,控制内核顺序的唯一方法是display_name
为内核指定 s ,以便它们的顺序String.localeCompare()
与您想要的匹配(如果不是,则结合排除“默认”/“本机”内核)你想先看到的)。
解释...
图标的顺序首先由等级控制,然后localeCompare()
由标签控制。这是排序发生的地方,在您已经找到的启动器扩展的 index.tsx 文件中:
// Within each category sort by rank
for (const cat in categories) {
categories[cat] = categories[cat].sort(
(a: ILauncher.IItemOptions, b: ILauncher.IItemOptions) => {
return Private.sortCmp(a, b, this._cwd, this._commands);
}
);
}
(https://github.com/jupyterlab/jupyterlab/blob/0bec95d5364986eaf19dab4721a98c75f13db40f/packages/launcher/src/index.tsx#L172-L179)
排序功能:
/**
* A sort comparison function for a launcher item.
*/
export function sortCmp(
a: ILauncher.IItemOptions,
b: ILauncher.IItemOptions,
cwd: string,
commands: CommandRegistry
): number {
// First, compare by rank.
const r1 = a.rank;
const r2 = b.rank;
if (r1 !== r2 && r1 !== undefined && r2 !== undefined) {
return r1 < r2 ? -1 : 1; // Infinity safe
}
// Finally, compare by display name.
const aLabel = commands.label(a.command, { ...a.args, cwd });
const bLabel = commands.label(b.command, { ...b.args, cwd });
return aLabel.localeCompare(bLabel);
}
}
(https://github.com/jupyterlab/jupyterlab/blob/0bec95d5364986eaf19dab4721a98c75f13db40f/packages/launcher/src/index.tsx#L499-L520)
不幸的是,内核的等级是固定的:0
对于默认内核,Infinity
对于其他内核:
for (const name in specs.kernelspecs) {
const rank = name === specs.default ? 0 : Infinity;
(https://github.com/jupyterlab/jupyterlab/blob/0bec95d5364986eaf19dab4721a98c75f13db40f/packages/notebook-extension/src/index.ts#L770)
如果您尝试如上所述控制顺序,您可能需要考虑排除默认内核(例如Python 3
或类似),因为它总是首先出现:
class KernelSpecManager(LoggingConfigurable):
[...]
ensure_native_kernel = Bool(True, config=True,
help="""If there is no Python kernelspec registered and the IPython
kernel is available, ensure it is added to the spec list.
"""
)
(https://github.com/jupyter/jupyter_client/blob/012cb1948d92c6f329cf1a749fece6c99a2485bf/jupyter_client/kernelspec.py#L122-L125)