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

examples: added pre-commit check and format all notebooks #1220

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

zilto
Copy link
Collaborator

@zilto zilto commented Nov 6, 2024

Follows #1212.

This adds a script examples/validate_examples.py to check that all .ipynb files under examples/ follow the rules:

  • first cell is a code cell
  • first cell contains %pip install to install dependencies from the notebook / Colab environment.
  • second cell is a markdown cell
  • second cell contains a Colab badge with the right URL
  • second cell contains a GitHub badge with the right URL
  • if the first cell contains ## ignore_ci, checks are skipped
  • if the notebook is a subpath of directories mentioned in EXCLUDED_EXAMPLES, it is ignored (equivalent to ## ignore_ci)

image

Notes

  • Note that it must be %pip, which is the current venv and !pip uses the base environment.
  • Using %pip has limitations for environment managers that don't include pip in their venv (e.g., uv, pdm). In that case, the user is responsible for adding dependencies from the terminal.

@zilto zilto added repo-hygiene examples Related to code under `examples/` labels Nov 6, 2024
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

❌ Changes requested. Reviewed everything up to c707be3 in 1 minute and 6 seconds

More details
  • Looked at 235 lines of code in 2 files
  • Skipped 69 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. examples/validate_examples.py:108
  • Draft comment:
    Consider allowing the dependencies to be specified as a parameter to make this function more flexible.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The function insert_setup_cell hardcodes the dependencies to be installed. It would be more flexible to allow specifying dependencies as a parameter.
2. examples/validate_examples.py:131
  • Draft comment:
    Consider reusing _create_github_badge and _create_colab_badge to avoid code duplication.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The function add_badges_to_title duplicates the logic for creating badges. It would be better to reuse the existing functions _create_github_badge and _create_colab_badge.

Workflow ID: wflow_OWcqVJs2Cjpf0tXB


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

examples/validate_examples.py Outdated Show resolved Hide resolved
return colab_badge


def validate_notebook(notebook_path: pathlib.Path) -> int:
Copy link
Contributor

Choose a reason for hiding this comment

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

The validate_notebook function is performing multiple checks. Consider refactoring it into smaller functions, each handling a specific check, to adhere to the Single Responsibility Principle.

examples/validate_examples.py Show resolved Hide resolved
examples/validate_examples.py Show resolved Hide resolved
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on a6f651e in 30 seconds

More details
  • Looked at 32 lines of code in 1 files
  • Skipped 1 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. examples/validate_examples.py:128
  • Draft comment:
    Ensure that badges are not duplicated if they already exist in the markdown cell. Consider checking for existing badges before adding new ones.
  • Reason this comment was not posted:
    Comment did not seem useful.
2. examples/validate_examples.py:133
  • Draft comment:
    The logic for creating badges is repeated in multiple places. Consider refactoring the badge creation logic into a separate function to adhere to the DRY principle. This applies to lines 18-20 and 24-27 as well.
  • Reason this comment was not posted:
    Comment was on unchanged code.
3. examples/validate_examples.py:128
  • Draft comment:
    The add_badges_to_title function is handling multiple responsibilities. Consider refactoring it to separate the reading, updating, and writing of the notebook into distinct functions to adhere to the Single Responsibility Principle.
  • Reason this comment was not posted:
    Comment was on unchanged code.

Workflow ID: wflow_qioxCvTJddbfHIET


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@zilto zilto merged commit d6f6f90 into main Nov 7, 2024
24 checks passed
@zilto zilto deleted the ci/check-colab-notebooks branch November 7, 2024 02:27
@zilto zilto mentioned this pull request Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples Related to code under `examples/` repo-hygiene
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants