Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

Notebook.Refactor To Utils

БесплатноБез исполняемых скриптовНе проверен

Move or add notebook code to a *_utils.py library file

gpsaggeseот gpsaggese★ 158 звёзд на GitHub

Об этом скилле

Goal

  • You are an expert Python developer

  • I will pass you a Python file paired with a Jupyter notebook using jupytext in py:percent format

  • I can also pass a description <DESCRIPTION> of new code to add

    • With <DESCRIPTION> follow Scenario 2, otherwise follow Scenario 1

Plan Only (--only_plan)

  • With --only_plan, follow .claude/skills/skill.rules.md section "Create Only a Plan with --only_plan"
  • Write the plan to notebook.refactor_to_utils.<INPUT_REF>.md, then stop without executing the skill

Constraints

  • Follow .claude/skills/coding.rules.md for all code

  • Important Notes

    • Always sync before editing: uvx jupytext --sync notebook.py
    • Always sync after editing: uvx jupytext --sync notebook.py

Scenarios

  • This skill handles two complementary scenarios:

Scenario 1: Moving Existing Functions to Utils

  • Extract functions from an existing notebook and move them to utils

Scenario 2: Adding New Code to Utils

  • Add new functions or code to the utils file that corresponds to the notebook

Workflow

Identify or Create the Utils File

  • Find or create the library file for the notebook, named after it with underscores
    • E.g., Lesson94-Information_Theory.ipynb -> Lesson94_Information_Theory_utils.py
    • E.g., tutorial_advanced.ipynb -> tutorial_advanced_utils.py

Organize Code Structure in Utils File

  • Mirror the notebook's flow, with section separators for each notebook section

    • Example:
      # #############################################################################
      # Cell 1: Visual Bin - Population of Marbles
      # #############################################################################
      
      def cell1_draw_bin_with_marbles_interactive(...):
          ...
      
      def _cell1_helper_function(...):
          ...
      
      # #############################################################################
      # Cell 2: Entropy Calculations
      # #############################################################################
      
      def cell2_calculate_entropy(...):
          ...
      
  • Put each function in the part of the utils file that matches its notebook section

  • Group related functions together

  • Use private functions (prefix _) for helpers not called from the notebook

Move or Add Functions

For Moving Functions (Scenario 1):

  • Follow these steps:

    1. Copy all functions from the notebook to the utils file, without changing code
    2. Remove the functions from the notebook
    3. Update the notebook cells to call the utils functions

For Adding Functions (Scenario 2):

  • Follow these steps:

    1. Implement new code directly in the utils file
    2. Create caller code in the notebook that imports and uses the functions
    3. Add the code in the matching section of the utils file

Update Notebook to Call Utils

  • Replace function implementations with imports and calls

  • Pattern:

    import notebook_name_utils as utils
    
    # In code cells:
    utils.function_name(...)
    
  • Keep each code cell minimal:

    # Display results of Cell 2 analysis.
    utils.cell2_calculate_entropy()
    

Code Reuse

  • Reuse code already in the *_utils.py file and in the helpers directory
  • Avoid duplication across utils functions. Extract common patterns into helpers

Sync with Jupytext

  • After all modifications, sync both files, following # Code Architecture and Responsibility -> ## Utilities vs. Notebook Responsibilities in .claude/skills/notebook.rules.md:
    > uvx jupytext --sync <path/to/notebook.py>
    

Conventions

  • Always follow .claude/skills/notebook.rules.md

Verification

  • --only_plan (check only this item): the plan is in notebook.refactor_to_utils.<INPUT_REF>.md in the current dir, has the Generated by line, and nothing was executed
  • Confirm no function moved to *_utils.py changed behavior
  • Confirm every notebook cell that held inline code now calls its utils function
  • Confirm the .ipynb and paired .py file are in sync via Jupytext
Полный SKILL.md на GitHub

Установить Notebook.Refactor To Utils в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл Notebook.Refactor To Utils?

Move or add notebook code to a *_utils.py library file

Как установить скилл Notebook.Refactor To Utils?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл Notebook.Refactor To Utils запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить Notebook.Refactor To Utils с