xonsh/xonsh

feat: Add shared context to callable aliases

開放

#6,078 建立於 2026年1月30日

 (5 則留言) (2 個反應) (0 位負責人)Python (635 個分叉)batch import
aliasesaliases-callablegood first issuepriority-mediumv1

倉庫指標

星標
 (7,489 顆星)
PR 合併指標
 (平均合併 1天 20小時) (30 天內合併 26 個 PR)

描述

Motivation

We want to have a shared context (ctx) for pipeline that we can use from callable alias e.g.

@aliases.register
def _table(args, ctx):
    # ctx['columns'] = from first line of data
    print("transform 'a,b,c\n1,2,3' to '1,2,3' and put 'a,b,c' to the shared context of pipeline")

@aliases.register
def _column(args, ctx):
    # get column names from ctx['columns'] and return requested column
    print("read '1,2,3' with 'a,b,c' in shared context and choose 2 as b column")

echo 'a,b,c\n1,2,3' | table ',' | column 'b'
# 2

This allows to populate context during pipeline and make xontribs like xontrib-pipeliner more smart.

Pointers

For every pipeline we have CommandPipeline object (object, running) and every single command is spec so we can have mutable ctx in CommandPipeline object and put the reference to every spec during initialization.

For community

⬇️ Please click the 👍 reaction instead of leaving a +1 or 👍 comment

貢獻者指南