Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🆙 Upgrade Jupyter Books in myst init #1223

Merged
merged 31 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e6c93df
refactor: move init to new subdirectory
agoose77 Jun 19, 2024
5857dfd
feat: add upgrade process
agoose77 Jun 19, 2024
855a66a
docs: add docstrings
agoose77 Jun 19, 2024
04bbc84
feat: upgrade ipynb too
agoose77 Jun 19, 2024
a715daa
feat: copy bibliography section
agoose77 Jun 19, 2024
4617e20
fix: add conversion for latex export name
agoose77 Jun 19, 2024
28b6e3f
mising file
agoose77 Jun 19, 2024
634a40a
fix: use of helper
agoose77 Jun 19, 2024
6be110b
fix: handle toc properly
agoose77 Jun 19, 2024
d790b70
chore: run linter
agoose77 Jun 19, 2024
1f22035
fix: restore zod
agoose77 Jun 19, 2024
1da5417
chore: run linter
agoose77 Jun 19, 2024
a0ef52d
fix: renamed attribute
agoose77 Jun 19, 2024
19d3c89
docs: add comments
agoose77 Jun 19, 2024
03c78d1
chore: add changeset
agoose77 Jun 19, 2024
19ee6d0
feat: improve UX, ask
agoose77 Jul 5, 2024
b885ba5
fix: support multi-line definitions
agoose77 Jul 8, 2024
a460e76
test: ensure glossary upgrade behaves
agoose77 Jul 8, 2024
f34cd73
chore: run prettier
agoose77 Jul 8, 2024
1ecad34
feat: add support for renaming directives
agoose77 Jul 8, 2024
ac937b1
feat: add note about upgrade
agoose77 Jul 8, 2024
8e0d3e5
chore: run linter
agoose77 Jul 8, 2024
b151e49
fix: support legacy-style analytics declarations
agoose77 Jul 8, 2024
ad6c3eb
fix: support whitespace in admonition declaration
agoose77 Jul 8, 2024
c9a6432
test: add spacing test
agoose77 Jul 8, 2024
b5b2974
fix: nullish config support, atomic upgrades
agoose77 Jul 17, 2024
fc1ed37
feat: use debug
agoose77 Jul 17, 2024
8931f24
chore: run linter
agoose77 Jul 17, 2024
d6ea812
fix: cleanup atomics, debug
agoose77 Jul 17, 2024
ebd237d
chore: run linter
agoose77 Jul 17, 2024
274e3c1
fix: add try-catch
agoose77 Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: run linter
  • Loading branch information
agoose77 committed Jun 26, 2024
commit 1da54179fd596f5d63746c9e6b6901d8431d93b4
30 changes: 4 additions & 26 deletions packages/myst-cli/src/init/jupyter-book/toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,30 +187,6 @@ export function validateSphinxExternalTOC(toc: unknown): SphinxExternalTOC | und
}
}

type PrimitiveEntry = FileEntry | URLEntry | GlobEntry;

function convertEntry(dir: string, data: PrimitiveEntry): MySTEntry {
if ('file' in data) {
const resolved = resolveExtension(join(dir, data.file as string));
// TODO: check this is valid!
return {
file: relative(dir, resolved as string),
title: data.title,
};
} else if ('url' in data) {
return {
url: data.url,
title: data.title,
};
} else if ('glob' in data) {
return {
pattern: data.glob,
};
} else {
assertNever();
}
}

function assertNever(): never {
throw new Error('unreachable code');
}
Expand Down Expand Up @@ -281,6 +257,7 @@ function convertNoFormat(dir: string, data: z.infer<typeof NoFormatTOC>) {
function convertBookToNoFormat(data: z.infer<typeof BookTOC>): z.infer<typeof NoFormatTOC> {
const convertEntry = (item: z.infer<typeof BookEntry>): z.infer<typeof NoFormatEntry> => {
// Drop subtrees and sections
// eslint-disable-next-line prefer-const, @typescript-eslint/no-unused-vars
let { sections, subtrees, ...result } = item as z.infer<typeof BookEntry> & {
sections: any;
subtrees: any;
Expand Down Expand Up @@ -328,7 +305,7 @@ function convertBookToNoFormat(data: z.infer<typeof BookTOC>): z.infer<typeof No
}
};

const { root, defaults, format, ...rest } = data;
const { root, defaults, format: _, ...rest } = data;
let result = {
root,
defaults,
Expand All @@ -343,6 +320,7 @@ function convertBookToNoFormat(data: z.infer<typeof BookTOC>): z.infer<typeof No
function convertArticleToNoFormat(data: z.infer<typeof ArticleTOC>): z.infer<typeof NoFormatTOC> {
const convertEntry = (item: z.infer<typeof ArticleEntry>): z.infer<typeof NoFormatEntry> => {
// Drop subtrees and sections
// eslint-disable-next-line prefer-const, @typescript-eslint/no-unused-vars
let { sections, subtrees, ...result } = item as z.infer<typeof ArticleEntry> & {
sections: any;
subtrees: any;
Expand Down Expand Up @@ -370,7 +348,7 @@ function convertArticleToNoFormat(data: z.infer<typeof ArticleTOC>): z.infer<typ
return { options, ...convertSubtree(rest) };
}
};
const { root, defaults, format, ...rest } = data;
const { root, defaults, format: _, ...rest } = data;
let result = {
root,
defaults,
Expand Down
14 changes: 7 additions & 7 deletions packages/myst-cli/src/init/jupyter-book/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ export async function upgradeJupyterBook(session: ISession, configFile: string)
if (!(await fsExists('_config.yml'))) {
throw new Error('_config.yml is a required Jupyter Book configuration file');
}
const content = await fs.readFile('_config.yml', { encoding: 'utf-8' });
const data = validateJupyterBookConfig(yaml.load(content));
if (defined(data)) {
const configContent = await fs.readFile('_config.yml', { encoding: 'utf-8' });
const configData = validateJupyterBookConfig(yaml.load(configContent));
if (defined(configData)) {
// Update MyST configuration
({ site: config.site, project: config.project } = upgradeConfig(data));
({ site: config.site, project: config.project } = upgradeConfig(configData));
}

// Does TOC exist?
if (await fsExists('_toc.yml')) {
const content = await fs.readFile('_toc.yml', { encoding: 'utf-8' });
const data = validateSphinxExternalTOC(yaml.load(content));
if (defined(data)) {
const tocContent = await fs.readFile('_toc.yml', { encoding: 'utf-8' });
const tocData = validateSphinxExternalTOC(yaml.load(tocContent));
if (defined(tocData)) {
(config as any).project.toc = upgradeTOC(data);
}
}
Expand Down