Skip to content

Conversation

@simonw
Copy link
Owner

@simonw simonw commented Nov 24, 2025

Claude Code: https://gistpreview.github.io/?37fe8d2b19231e8ed5ef2967e1ba757b

Closes:

The --functions option now supports:

  1. File paths: Pass a .py file containing function definitions

    sqlite-utils query db.db "select domain(url) from urls" --functions funcs.py
  2. Multiple invocations: Use --functions multiple times to load from different sources

    sqlite-utils query db.db "select f1(x), f2(x) from data" \
      --functions funcs.py \
      --functions 'def f2(x): return x * 2'
  3. Inline code: Existing behavior still works

    sqlite-utils query db.db "select double(5)" --functions 'def double(x): return x * 2'

Implementation

Follows the same pattern as LLM's --functions flag (simonw/llm@a880c123):

  • Detects file paths by checking for no newlines and .py extension
  • Reads file contents using pathlib.Path().read_text()
  • Iterates over multiple function sources when multiple=True

Changes

  • Added multiple=True to --functions Click option in query, bulk, and memory commands
  • Modified _register_functions() to detect and read .py files
  • Updated _maybe_register_functions() to iterate over multiple function sources
  • Removed unused bytes/bytearray handling
  • Added comprehensive tests for file paths and multiple invocations
  • Updated documentation with examples

All tests pass including new test coverage for:

  • Loading functions from .py files
  • Using --functions multiple times
  • Combining file and inline code
  • Error handling for missing files

📚 Documentation preview 📚: https://sqlite-utils--681.org.readthedocs.build/en/681/

The --functions option now accepts:
- File paths ending in .py (e.g., --functions my_funcs.py)
- Multiple invocations (e.g., --functions foo.py --functions 'def bar(): ...')
- Inline Python code (existing behavior)

Implementation follows the same pattern as llm's --functions flag
(simonw/llm@a880c123).

Changes:
- Added multiple=True to --functions Click option in query, bulk, and memory commands
- Modified _register_functions() to detect and read .py files
- Updated _maybe_register_functions() to iterate over multiple function sources
- Removed unused bytes/bytearray handling
- Added comprehensive tests for file paths and multiple invocations
- Updated documentation with examples

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Nov 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.32%. Comparing base (fb93452) to head (4147ed0).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #681      +/-   ##
==========================================
+ Coverage   95.27%   95.32%   +0.04%     
==========================================
  Files           8        8              
  Lines        3008     3014       +6     
==========================================
+ Hits         2866     2873       +7     
+ Misses        142      141       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@simonw simonw added refactor enhancement New feature or request cli-tool and removed refactor labels Nov 24, 2025
@simonw simonw merged commit 0bbc680 into main Nov 24, 2025
88 checks passed
@simonw simonw deleted the sqlite-utils-659-functions-files branch November 24, 2025 05:46
simonw added a commit that referenced this pull request Nov 24, 2025
Closes #659

The --functions option now accepts:
- File paths ending in .py (e.g., --functions my_funcs.py)
- Multiple invocations (e.g., --functions foo.py --functions 'def bar(): ...')
- Inline Python code (existing behavior)

Implementation follows the same pattern as llm's --functions flag
(simonw/llm@a880c123).

Changes:
- Added multiple=True to --functions Click option in query, bulk, and memory commands
- Modified _register_functions() to detect and read .py files
- Updated _maybe_register_functions() to iterate over multiple function sources
- Removed unused bytes/bytearray handling
- Added comprehensive tests for file paths and multiple invocations
- Updated documentation with examples

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Shorter help for --functions

---------

Co-authored-by: Claude <noreply@anthropic.com>
simonw added a commit that referenced this pull request Nov 24, 2025
Closes #659

The --functions option now accepts:
- File paths ending in .py (e.g., --functions my_funcs.py)
- Multiple invocations (e.g., --functions foo.py --functions 'def bar(): ...')
- Inline Python code (existing behavior)

Implementation follows the same pattern as llm's --functions flag
(simonw/llm@a880c123).

Changes:
- Added multiple=True to --functions Click option in query, bulk, and memory commands
- Modified _register_functions() to detect and read .py files
- Updated _maybe_register_functions() to iterate over multiple function sources
- Removed unused bytes/bytearray handling
- Added comprehensive tests for file paths and multiple invocations
- Updated documentation with examples

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Shorter help for --functions

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli-tool enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants