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

Allow packages to not have release notes #1306

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion scripts/lib/api/Pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import { determineHistoricalQiskitGithubUrl } from "../qiskitMetapackage";
import { TocGrouping } from "./TocGrouping";

export class ReleaseNotesConfig {
readonly enabled: boolean;
readonly separatePagesVersions: string[];

constructor(kwargs: { separatePagesVersions?: string[] }) {
constructor(kwargs: { enabled?: boolean; separatePagesVersions?: string[] }) {
this.enabled = kwargs.enabled ?? true;
this.separatePagesVersions = kwargs.separatePagesVersions ?? [];
}
}
Expand Down
4 changes: 0 additions & 4 deletions scripts/lib/api/__snapshots__/conversionPipeline.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ exports[`qiskit-sphinx-theme: _toc 1`] = `
"url": "/api/qiskit-sphinx-theme/inline_classes"
}
]
},
{
"title": "Release notes",
"url": "/api/qiskit-sphinx-theme/release-notes"
}
],
"collapsed": true
Expand Down
3 changes: 2 additions & 1 deletion scripts/lib/api/conversionPipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { globby } from "globby";
import { expect, test } from "@jest/globals";

import { runConversionPipeline } from "./conversionPipeline";
import { Pkg } from "./Pkg";
import { Pkg, ReleaseNotesConfig } from "./Pkg";

// This test uses snapshot testing (https://jestjs.io/docs/snapshot-testing#updating-snapshots). If the tests fail and the changes
// are valid, run `npm test -- --updateSnapshot`.
Expand Down Expand Up @@ -58,6 +58,7 @@ test("qiskit-sphinx-theme", async () => {
version: "0.1.1",
versionWithoutPatch: "0.1",
type: "latest",
releaseNotesConfig: new ReleaseNotesConfig({ enabled: false }),
});
const markdownFolder = pkg.outputDir(docsBaseFolder);

Expand Down
81 changes: 41 additions & 40 deletions scripts/lib/api/generateToc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ describe("generateToc", () => {
});
});

test("TOC with distinct release note files", () => {
test("TOC with separate release note files", () => {
const toc = generateToc(
Pkg.mock({
releaseNotesConfig: new ReleaseNotesConfig({
Expand Down Expand Up @@ -318,53 +318,54 @@ describe("generateToc", () => {
});
});

test("generate a toc without modules", () => {
const toc = generateToc(Pkg.mock({}), [
{
meta: { apiType: "class", apiName: "Sampler" },
url: "/api/my-quantum-project/my_quantum_project.Sampler",
...DEFAULT_ARGS,
},
{
meta: { apiType: "method", apiName: "Sampler.run" },
url: "/api/my-quantum-project/my_quantum_project.Sampler.run",
...DEFAULT_ARGS,
},
{
meta: { apiType: "class", apiName: "Estimator" },
url: "/api/my-quantum-project/my_quantum_project.Estimator",
...DEFAULT_ARGS,
},
{
meta: { apiType: "class" },
url: "/api/my-quantum-project/my_quantum_project.NoName",
...DEFAULT_ARGS,
},
{
meta: { apiType: "class", apiName: "Options" },
url: "docs/my_quantum_project.options.Options",
...DEFAULT_ARGS,
},
{
meta: {
apiType: "function",
apiName: "runSomething",
test("generate a toc without modules and releaes notes", () => {
const toc = generateToc(
Pkg.mock({
releaseNotesConfig: new ReleaseNotesConfig({ enabled: false }),
}),
[
Copy link
Collaborator Author

@Eric-Arellano Eric-Arellano May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No changes made to this list of inputs - it's only formatting

{
meta: { apiType: "class", apiName: "Sampler" },
url: "/api/my-quantum-project/my_quantum_project.Sampler",
...DEFAULT_ARGS,
},
url: "docs/my_quantum_project.runSomething",
...DEFAULT_ARGS,
},
]);
{
meta: { apiType: "method", apiName: "Sampler.run" },
url: "/api/my-quantum-project/my_quantum_project.Sampler.run",
...DEFAULT_ARGS,
},
{
meta: { apiType: "class", apiName: "Estimator" },
url: "/api/my-quantum-project/my_quantum_project.Estimator",
...DEFAULT_ARGS,
},
{
meta: { apiType: "class" },
url: "/api/my-quantum-project/my_quantum_project.NoName",
...DEFAULT_ARGS,
},
{
meta: { apiType: "class", apiName: "Options" },
url: "docs/my_quantum_project.options.Options",
...DEFAULT_ARGS,
},
{
meta: {
apiType: "function",
apiName: "runSomething",
},
url: "docs/my_quantum_project.runSomething",
...DEFAULT_ARGS,
},
],
);

expect(toc).toEqual({
children: [
{
title: "API index",
url: "/api/my-quantum-project",
},
{
title: "Release notes",
url: "/api/my-quantum-project/release-notes",
},
],
collapsed: true,
title: "My Quantum Project",
Expand Down
23 changes: 14 additions & 9 deletions scripts/lib/api/generateToc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,32 @@ export function generateToc(pkg: Pkg, results: HtmlToMdResultWithUrl[]): Toc {

addItemsToModules(items, tocModulesByTitle, tocModuleTitles);

let sortedTocModules;
let orderedModules;
if (pkg.tocGrouping) {
sortedTocModules = groupAndSortModules(pkg.tocGrouping, tocModulesByTitle);
orderedModules = groupAndSortModules(pkg.tocGrouping, tocModulesByTitle);
} else if (pkg.nestModulesInToc) {
sortedTocModules = getNestedTocModulesSorted(
orderedModules = getNestedTocModulesSorted(
tocModulesByTitle,
tocModuleTitles,
);
} else {
sortedTocModules = sortAndTruncateModules(tocModules);
orderedModules = sortAndTruncateModules(tocModules);
}

generateOverviewPage(tocModules);
const maybeIndexPage = ensureIndexPage(pkg, sortedTocModules);
const maybeIndexPage = ensureIndexPage(pkg, orderedModules);
if (maybeIndexPage) {
sortedTocModules.unshift(maybeIndexPage);
orderedModules.unshift(maybeIndexPage);
}

const maybeReleaseNotes = generateReleaseNotesEntry(pkg);
if (maybeReleaseNotes) {
orderedModules.push(maybeReleaseNotes);
}

return {
title: pkg.title,
children: [...sortedTocModules, generateReleaseNotesEntries(pkg)],
children: orderedModules,
collapsed: true,
};
}
Expand Down Expand Up @@ -266,7 +271,8 @@ function generateOverviewPage(tocModules: TocEntry[]): void {
}
}

function generateReleaseNotesEntries(pkg: Pkg) {
function generateReleaseNotesEntry(pkg: Pkg): TocEntry | undefined {
if (!pkg.releaseNotesConfig.enabled) return;
const releaseNotesUrl = `/api/${pkg.name}/release-notes`;
const releaseNotesEntry: TocEntry = {
title: "Release notes",
Expand All @@ -280,7 +286,6 @@ function generateReleaseNotesEntries(pkg: Pkg) {
} else {
releaseNotesEntry.url = releaseNotesUrl;
}

return releaseNotesEntry;
}

Expand Down
Loading