xonsh/xonsh

feat: Add shared context to callable aliases

Open

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

在 GitHub 查看
 (5 留言) (2 反應) (0 負責人)Python (7,489 star) (635 fork)batch import
aliasesaliases-callablegood first issuepriority-mediumv1

描述

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

貢獻者指南