Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Feature]: expand expression evaluator filter set (upper, lower, length, split, sort, to_json)

未关闭
#4,614 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
52/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
tooling

调研方向

Start in src/specify_cli/workflows/expressions.py, reading the existing filter registration and _apply_filter() implementation around lines 20-26 and 419-484. Then inspect tests/test_workflows.py and the existing filter tests to understand input and error conventions. The work is done when the agreed filter set is registered, implemented, and covered by tests, including the unresolved length semantics and naming decisions.

由索引模型根据 Issue 内容生成。

描述

feature-assess feature-needs-clarification triage-can-wait

Problem

The workflow expression evaluator currently supports only 5 filters: default, join, map, contains, and from_json. For a system marketed as "Jinja2-like," common string and collection operations are missing, forcing workflow authors to shell out for basic transformations.

Missing filters that workflow authors frequently need:

  • String operations: upper, lower, trim (whitespace), split (string to list)
  • Collection operations: length, first, last, sort, unique
  • Serialization: to_json (the reverse of existing from_json)

Example of current limitation:

# Cannot do this today — no `length` filter:
- id: check
  type: shell
  config:
    command: "echo 'Found {{ items | length }} files'"

# Cannot do this today — no `split` filter:
- id: list
  type: shell
  config:
    command: "echo '{{ file_list | split(\",\") | length }} files found'"

Proposed Solution

Add a batch of new filters to the expression evaluator, following the existing registration pattern.

String Filters
Filter Input Output Example
upper "hello" "HELLO" {{ name | upper }}
lower "HELLO" "hello" {{ name | lower }}
trim " hi " "hi" {{ name | trim }}
split "a,b,c" ["a","b","c"] {{ csv | split(",") }}
Collection Filters
Filter Input Output Example
length ["a","b"] 2 {{ items | length }}
first ["a","b","c"] "a" {{ items | first }}
last ["a","b","c"] "c" {{ items | last }}
sort [3,1,2] [1,2,3] {{ items | sort }}
unique ["a","a","b"] ["a","b"] {{ items | unique }}
Serialization Filter
Filter Input Output Example
to_json {"key":"val"} "{\"key\":\"val\"}" {{ data | to_json }}

Design Notes

  • Follows existing pattern: Each filter is a standalone function registered in _REGISTERED_FILTERS and dispatched in _apply_filter() (expressions.py lines 20-26, 419-484)
  • Safe by design: All operations are pure transformations — no arbitrary code execution, no side effects, consistent with the sandboxed evaluator model
  • length enables conditionals: Unlocks {% if items | length > 0 %} patterns that currently require shell workarounds
  • split bridges shell output: Shell steps return newline/comma-separated strings; split converts them to lists for downstream processing
  • to_json completes the round-trip: from_json exists; to_json is its natural pair for passing structured data back to shell commands

Affected Files

  • src/specify_cli/workflows/expressions.py — filter registration and implementation (lines 20-26, 419-484)
  • tests/test_workflows.py — unit tests for each new filter

Questions

  1. Are there additional filters you would want in this batch, or should we start with a smaller set?
  2. Should length work on both lists and strings (Jinja2 behavior), or only collections?
  3. Any naming preferences (e.g., len vs length, flatten vs unique)?

Happy to implement if this aligns with your plans for the expression engine.

主要语言
Python
星标
138k
派生
12.4k
平均合并
3 天 6 小时
30 天内合并 PR
145

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/spec-kit 的其他 Issue

查看 github/spec-kit 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。