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

add script to post process docs #4838

Merged
merged 5 commits into from
Sep 25, 2024
Merged

add script to post process docs #4838

merged 5 commits into from
Sep 25, 2024

Conversation

imanjra
Copy link
Contributor

@imanjra imanjra commented Sep 24, 2024

What changes are proposed in this pull request?

Add a script to post-process docs. Currently support adding bolded NEW label in orange as shown below:

docs/source/index.rst:

...

   Dataset Zoo __SUB_NEW__ <dataset_zoo/index>
   Model Zoo __SUB_NEW__ <model_zoo/index>
   FiftyOne Brain <brain>
   Integrations <integrations/index>
   Plugins  <plugins/index>

...

__SUB_NEW__ in snippet above will be replaced with HTML

<strong style="color: hsl(25, 100%, 51%); font-size: 0.85em; vertical-align: top">NEW</strong>

How is this patch tested? If it is not, please explain why.

Using docs build

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new post-processing step in the documentation generation workflow to enhance the output.
    • Added a script to process HTML files, replacing placeholders with styled badges for improved presentation.
    • Added new section headers for "Remotely-sourced datasets" and "Remotely-sourced models" in the documentation.
  • Documentation

    • Updated formatting in various documentation sections for consistency and clarity.

@imanjra imanjra requested review from brimoor and a team September 24, 2024 21:47
Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Walkthrough

The changes introduce a new post-processing step in the documentation generation workflow. This includes an echo statement and the execution of a new Node.js script, post-process.js, which processes HTML files in the build directory. The script replaces specific placeholders in the HTML files with styled content, while formatting adjustments are made in various documentation files to enhance clarity and organization.

Changes

File Change Summary
docs/generate_docs.bash Added a post-processing step with an echo statement and execution of post-process.js.
docs/scripts/post-process.js Introduced a new script to process HTML files, replacing placeholders with styled content.
docs/source/dataset_zoo/index.rst Modified section header formatting for "Remotely-sourced datasets."
docs/source/index.rst Adjusted formatting in the navigation section, adding spaces and __SUB_NEW__ tags.
docs/source/model_zoo/index.rst Added a new section header for "Remotely-sourced models."

Possibly related PRs

  • Add docs script #4556: This PR adds a new script to the documentation, which may relate to the changes in the documentation generation process introduced in the main PR.
  • Migrating zoo/brain docs to top-level #4818: This PR involves updates to the documentation structure, including sections that may interact with the new post-processing step added in the main PR.

Suggested labels

documentation

Suggested reviewers

  • findtopher
  • mwoodson1

🐰 In the garden of code, changes bloom bright,
A script for the docs, what a wonderful sight!
With badges of "NEW" that gleam and they shine,
Our workflow now dances, oh how it aligns!
Let’s hop to the future, with docs that are neat,
A post-process magic, oh, what a treat! 🌼


Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 125ff93 and b3ec6d3.

Files selected for processing (1)
  • docs/scripts/post-process.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • docs/scripts/post-process.js

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (6)
docs/scripts/post-process.js (5)

1-4: LGTM! Consider adding error handling for path resolution.

The import statements and path resolution look good. However, it might be beneficial to add error handling for the path resolution to ensure the script fails gracefully if run from an unexpected location.

Consider adding a check like this:

const buildPath = path.resolve(__dirname, "../build");
if (!fs.existsSync(buildPath)) {
  console.error(`Build directory not found: ${buildPath}`);
  process.exit(1);
}

6-11: LGTM! Consider moving function declaration.

The file finding and substitution definition look good and align with the PR objectives. For improved readability, consider moving the findHTMLFiles function declaration before its usage.

You could restructure the file like this:

const fs = require("fs");
const path = require("path");

function findHTMLFiles(dir) {
  // ... (existing implementation)
}

const buildPath = path.resolve(__dirname, "../build");
const htmlFiles = findHTMLFiles(buildPath);

// ... (rest of the code)

13-21: LGTM! Consider adding error handling for file operations.

The main processing loop looks good and efficiently applies the substitutions. However, it's important to add error handling for file reading and writing operations to make the script more robust.

Consider wrapping the file operations in try-catch blocks:

for (const file of htmlFiles) {
  try {
    let content = fs.readFileSync(file, "utf8");
    if (content.includes("__fo_doc_sub")) {
      for (const [key, value] of Object.entries(substitutions)) {
        content = content.replace(key, value);
      }
      fs.writeFileSync(file, content);
      console.log(`Processed: ${file}`);
    }
  } catch (error) {
    console.error(`Error processing file ${file}: ${error.message}`);
  }
}

23-39: LGTM! Consider performance and error handling improvements.

The findHTMLFiles function correctly implements a recursive search for HTML files. However, there are a few areas where it could be improved:

  1. For large directory structures, using synchronous file system operations might lead to performance issues.
  2. There's no error handling for file system operations.

Consider these improvements:

  1. Use asynchronous file system operations for better performance:
async function findHTMLFiles(dir) {
  const files = await fs.promises.readdir(dir);
  const htmlFiles = [];

  for (const file of files) {
    const filePath = path.join(dir, file);
    const stat = await fs.promises.lstat(filePath);

    if (stat.isDirectory()) {
      htmlFiles.push(...await findHTMLFiles(filePath));
    } else if (file.endsWith(".html")) {
      htmlFiles.push(filePath);
    }
  }

  return htmlFiles;
}
  1. Add error handling:
async function findHTMLFiles(dir) {
  try {
    const files = await fs.promises.readdir(dir);
    const htmlFiles = [];

    for (const file of files) {
      try {
        const filePath = path.join(dir, file);
        const stat = await fs.promises.lstat(filePath);

        if (stat.isDirectory()) {
          htmlFiles.push(...await findHTMLFiles(filePath));
        } else if (file.endsWith(".html")) {
          htmlFiles.push(filePath);
        }
      } catch (error) {
        console.error(`Error processing ${file}: ${error.message}`);
      }
    }

    return htmlFiles;
  } catch (error) {
    console.error(`Error reading directory ${dir}: ${error.message}`);
    return [];
  }
}

Note that if you implement these changes, you'll need to update the main script to use async/await as well.


1-39: Overall assessment: Good implementation with room for improvement.

The script successfully implements the post-processing of HTML files to add "NEW" badges as described in the PR objectives. It's a straightforward and functional solution. However, there are several areas where it could be improved:

  1. Error handling: Add checks for directory existence and wrap file operations in try-catch blocks.
  2. Performance: Consider using asynchronous file system operations, especially for the findHTMLFiles function.
  3. Code structure: Move function declarations before their usage for better readability.
  4. Logging: Add more verbose logging to track the script's progress and any issues encountered.

These improvements would make the script more robust, efficient, and maintainable.

docs/generate_docs.bash (1)

136-138: LGTM! Consider adding error handling and documentation.

The addition of the post-processing step aligns well with the PR objectives. Here are some suggestions to improve robustness and clarity:

  1. Add error handling for the Node.js script execution. This will help catch and report any issues that might occur during post-processing.

  2. Include a brief comment explaining the purpose of the post-processing step. This will help future maintainers understand the script's functionality.

Consider updating the code as follows:

 echo "Post-processing docs"
-node ./scripts/post-process.js
+# Post-process the docs to add "NEW" labels
+if ! node ./scripts/post-process.js; then
+    echo "Error: Post-processing failed" >&2
+    exit 1
+fi
 

This change adds error handling and a comment explaining the purpose of the post-processing step.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 77de164 and eceaa13.

Files selected for processing (2)
  • docs/generate_docs.bash (1 hunks)
  • docs/scripts/post-process.js (1 hunks)

docs/generate_docs.bash Show resolved Hide resolved
Copy link
Contributor

@minhtuev minhtuev left a comment

Choose a reason for hiding this comment

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

🚀 🙏

Copy link
Contributor

@brimoor brimoor left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@brimoor brimoor merged commit 9e7aa51 into develop Sep 25, 2024
13 checks passed
@brimoor brimoor deleted the docs/post-process-im branch September 25, 2024 17:40
@coderabbitai coderabbitai bot mentioned this pull request Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants