Add namespaces to task decorators
まだ誰も着手していません。
評価
調査の方向性
Start in tasks.py and inspect the @task decorator and invoke.Collection entry points. Compare the proposed namespace forms and default root-collection behavior, then verify that nested namespaces and unqualified tasks behave as described in the examples.
索引モデルが issue の本文から書いたものです。
説明
The current mechanism to create namespaces is a lot of work. I've hacked together an example tasks decorator dynamically creates namespaces as needed.
@task('ns1.ns2.ns3') # or @task(collection='ns1.ns2.ns3') or @task(namespace=...)
def do_something(c):
pass
I'm also of the opinion that anything marked with @task in tasks.py should be added to the root collection by default.
Here's a working example. I'd be more that happy to contribute this as a feature.
import invoke
from collections import deque
namespace = invoke.Collection()
def resolve_collection(namespace_str):
"""
Returns an existing subcollection for a path (e.g. 'a.b.c') or creates them
and returns the "leaf" subcollection.
"""
collection_names = deque(namespace_str.split('.'))
curr = namespace
while True:
collection_name = collection_names.popleft()
try:
subcollection = curr.subcollection_from_path(collection_name)
except KeyError:
subcollection = None
# if theres not a matching subcollection add it
if not subcollection:
subcollection = invoke.Collection(collection_name)
curr.add_collection(subcollection)
curr = subcollection
if not collection_names:
return subcollection
def task(collection = namespace, **kwargs):
"""invoke.task wrapped with some extra goodies"""
def wrapper(task_fn):
if isinstance(collection, invoke.Collection):
collection.add_task(invoke.task(task_fn, **kwargs))
if isinstance(collection, str):
resolve_collection(collection).add_task(invoke.task(task_fn, **kwargs))
return wrapper
#
# Usage
#
@task()
def this_task_will_be_in_the_default_namespace(c):
pass
@task(collection='docs')
def this_task_will_be_in_docs(c):
pass
- 主要言語
- Python
- スター
- 4.8k
- フォーク
- 412
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pyinvoke/invoke のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
pyinvoke/invoke の issue をすべて見る
似ている issue
-
documentation help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
simonw/sqlite-utils#872 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100