invocations v4.1.0 — 事实采集基线(R 阶段)#
本文档为「源码 → OKF wiki」工作流的 R(事实采集)阶段产物。 数据来源:
d:\spaces\SpecWeave\external\libs\tools\pyinvoke\invocations\下各源码文件的实际行内容。 纪律(G1):只陈述代码中真实存在的内容,并标注来源文件;不使用「用于/目的是/设计为」等推断词;不臆造任何 API;不能从源码验证的细节一律省略。
1. 版本确认#
来源:
pyproject.toml([project]段,第 4 行)version = "4.1.0"包名:
name = "invocations"requires-python = ">=3.9"运行时依赖(
[project].dependencies):invoke>=1.7.2、blessings>=1.6、build>=1.3、pip>=25.1、releases>=1.6、semantic_version>=2.4,<2.7、tabulate>=0.7.5、tqdm>=4.8.1、twine>=1.15、wheel>=0.24.0构建后端:
[build-system]→setuptools.build_meta,requires = ["setuptools >= 77"]注:
invocations/__init__.py第 3 行通过metadata.version("invocations")运行时读取版本号,源码本身未硬编码版本数字。
2. 真实模块清单#
packaging/ 子包实际存在的文件(经目录列举核实):
invocations/packaging/__init__.pyinvocations/packaging/release.pyinvocations/packaging/semantic_version_monkey.pyinvocations/packaging/vendorize.py
确认:packaging/version.py 不存在(Glob 检索 invocations/packaging/version.py 返回空)。
顶层模块实际存在的文件:
invocations/__init__.pyinvocations/autodoc.pyinvocations/checks.pyinvocations/ci.pyinvocations/console.pyinvocations/docs.pyinvocations/environment.pyinvocations/pytest.pyinvocations/testing.pyinvocations/util.pyinvocations/watch.py
3. 各模块事实#
说明:
setuptools包默认情况下,若某模块未定义ns/ns = Collection(...),则其@task不会被自动注册;下文仅陈述源码中实际出现的结构。
F-autodoc — invocations/autodoc.py#
无任何
@task装饰的task函数。定义类
TaskDocumenter(autodoc.DocstringSignatureMixin, autodoc.ModuleLevelDocumenter)(第 52 行)。类属性
objtype = "task"、directivetype = "function"(第 55-56 行)。类方法
can_document_member(cls, member, membername, isattr, parent)(第 58 行):函数体return isinstance(member, Task)。实例方法
format_args(self)(第 62 行):函数体function = self.object.body,返回autodoc.stringify_signature(inspect.signature(function))。实例方法
document_members(self, all_members=False)(第 73 行):函数体为pass(被改写为空实现)。
顶层函数
setup(app)(第 79 行):调用app.setup_extension("sphinx.ext.autodoc")与app.add_autodocumenter(TaskDocumenter)。模块导入
from invoke import Task与from sphinx.ext import autodoc。
F-checks — invocations/checks.py#
from invoke import task(第 7 行)。未定义ns。
任务函数 |
装饰器 |
参数与默认值 |
函数体要点 |
|---|---|---|---|
|
|
|
读 |
|
|
|
执行 |
|
|
|
设 |
blacken配置项(blacken子树):folders、find_opts(均由函数体内config.get(...)读取)。
F-ci — invocations/ci.py#
from invoke import task, Collection(第 29 行)。
任务函数 |
参数与默认值 |
函数体要点 |
|---|---|---|
|
|
读 |
|
|
执行 |
|
|
设 |
Collection 结构(第 94-105 行):
ns = Collection(make_sudouser, sudo_run, make_sshable)ns.configure({...}),config 键:ci.sudo.user(默认"invoker")、ci.sudo.password(默认"secret")、ci.sudo.groups(默认["sudo", "circleci"])。
F-console — invocations/console.py#
无
@task。无ns。顶层函数
confirm(question, assume_yes=True)(第 9 行):循环input("{} [{}] ".format(...));接受y/yes返回True、n/no返回False、空输入返回assume_yes;suffix依assume_yes为"Y/n"或"y/N";无效输入向sys.stderr打印"I didn't understand you. Please specify '(y)es' or '(n)o'."后重试。返回bool。
F-docs — invocations/docs.py#
from invoke import task, Collection, Context(第 10 行);from .watch import make_handler, observe(第 12 行)。
任务函数 |
装饰器 |
参数与默认值 |
函数体要点 |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
`ignore = ".git |
|
|
|
构造 |
|
|
|
分别为 www 与 docs 构造 handler( |
Collection 结构(第 104-114 行):
ns = Collection(_clean, _browse, build, tree, doctest)ns.configure({"sphinx": {...}}),config 键:sphinx.source("docs")、sphinx.target(join("docs", "_build"))、sphinx.target_file("index.html")。
模块级子集合(第 122-139 行):
辅助函数
_site(name, help_part):基于sys.modules[__name__]调用Collection.from_module(self, name=name, config={"sphinx": {"source": _path, "target": join(_path,"_build")}}),并改写集合与coll["build"]的__doc__。docs = _site("docs", "the API docs subsite.");www = _site("www", "the main project website.")。
build任务实际引用的配置键:c.sphinx.source、c.sphinx.target、c.sphinx.target_file(见上)。
F-environment — invocations/environment.py#
无
@task、无ns。顶层函数
in_ci():遍历哨兵("CIRCLECI", "TRAVIS"),os.environ.get(sentinel, False)非空即返回True,否则False。
F-pytest — invocations/pytest.py#
from invoke import task(第 5 行)。未定义ns。
任务函数 |
装饰器 |
参数与默认值 |
函数体要点 |
|---|---|---|---|
|
|
|
组装 flags( |
|
|
|
|
|
|
|
构造 |
F-testing — invocations/testing.py#
from invoke import task(第 5 行);from .watch import watch(第 8 行)。未定义ns。
任务函数 |
装饰器 |
参数与默认值 |
函数体要点 |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
读 |
|
|
|
先 |
|
|
|
|
tests配置键:logformat、package(由test/watch_tests读取)。
F-util — invocations/util.py#
无
@task。无ns。上下文管理器函数
tmpdir(skip_cleanup=False, explicit=None):tmp = explicit if explicit is not None else mkdtemp();yield tmp;finally中若not skip_cleanup则rmtree(tmp)。
F-watch — invocations/watch.py#
无
@task。无ns。顶层函数(均依赖 watchdog):
make_handler(ctx, task_, regexes, ignore_regexes, *args, **kwargs)(第 9 行):args = [ctx] + list(args);尝试from watchdog.events import RegexMatchingEventHandler,ImportError时sys.exit("If you want to use this, 'pip install watchdog' first.");定义内部Handler类(on_any_event中对BaseException静默pass);返回Handler(regexes=regexes, ignore_regexes=ignore_regexes)。observe(*handlers)(第 26 行):from watchdog.observers import Observer(ImportError同样sys.exit(...));建Observer(),对每个 handlerobserver.schedule(handler, ".", recursive=True);observer.start();time.sleep(1)循环,KeyboardInterrupt时stop(),join()。watch(c, task_, regexes, ignore_regexes, *args, **kwargs)(第 45 行):observe(make_handler(c, task_, regexes, ignore_regexes, *args, **kwargs))。
F-packaging.init — invocations/packaging/__init__.py#
第 2-3 行:
from .vendorize import vendorize;from . import release。第 7 行:
ns = release(指向release模块的 Collection)。末尾含# flake8: noqa。
F-release — invocations/packaging/release.py#
from invoke import Collection, Exit, task(第 26 行)。模块级导入:
blessings.Terminal、build._builder._read_pyproject_toml、docutils.utils.Reporter、pip.__version__ as pip_version、releases.util.parse_changelog、tabulate.tabulate、twine.commands.check.check as twine_check、..console.confirm、..environment.in_ci、..util.tmpdir、.semantic_version_monkey.Version等。模块级全局:
t = Terminal();check = "✔";ex = "✘";Release = Enum("Release", "BUGFIX FEATURE UNDEFINED");枚举类Changelog/VersionFile/Tag(值均为带颜色/符号的状态文案);正则BUGFIX_RE = r"^\d+\.\d+$"、BUGFIX_RELEASE_RE = r"^\d+\.\d+\.\d+$"、FEATURE_RE = r"^(main|master)$";异常类UndefinedReleaseType(Exception)。模块加载时(第 47-48 行)对
readme_renderer.rst.SETTINGS(halt_level、report_level)赋Reporter.INFO_LEVEL。@task任务函数:
任务函数 |
装饰器 |
参数与默认值 |
函数体要点 |
|---|---|---|---|
|
|
|
调 |
|
|
|
依次 |
|
|
|
调 |
|
|
|
读 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
非任务公共/辅助函数:
_converge(c):返回(actions, state),state为Lexicon(含branch/release_type/changelog/latest_line_release/latest_overall_release/unreleased_issues/current_version/tags/latest_version/next_version/expected_version);actions为Lexicon(changelog/version/tag/all_okay)。find_gpg(c):在"gpg gpg1 gpg2"中which探测,返回存在的候选名(否则返回None)。get_archives(directory: Union[str, Path]) -> list[Path]:sorted(target.glob("*.whl")) + sorted(target.glob("*.tar.gz"))。私有内部函数:
_release_line(c)、_latest_feature_bucket(changelog)、_versions_from_changelog(changelog)、_release_and_issues(changelog, branch, release_type)、_get_tags(c)、_latest_and_next_version(state)、_find_package(c)。
Collection 结构(第 914-926 行):
ns = Collection("release", all_, status, prepare, build, publish, push, test_install, upload)ns.configure({"run": {"hide": "stdout"}})。
说明:本模块未定义任何名为
success/timed的@task装饰器或辅助函数(对def (success|timed)(的检索在整包内无匹配)。
F-vendorize — invocations/packaging/vendorize.py#
from invoke import task(第 8 行)。
任务函数 |
参数与默认值 |
函数体要点 |
|---|---|---|
|
|
|
私有辅助函数
_unpack(c, tmp, package, version, git_url=None):git_url真时暂为空实现(pass);否则pip install --download=. --build=build --no-use-wheel <package>==<version>,按zip/tgz/tar.gz后缀识别归档并解压;返回(real_version, source)。本模块未定义
ns(packaging/__init__.py通过from .vendorize import vendorize直接导入该任务函数,而非经 Collection)。
F-semantic_version_monkey — invocations/packaging/semantic_version_monkey.py#
无
@task。无ns。from semantic_version import Version(第 9 行)。定义且在模块级挂到
Version上的方法(jit/monkey-patch):clone(self)→return Version(str(self));挂载Version.clone = clone。next_minor(self)→self.clone()后clone.minor += 1; clone.patch = 0;挂载Version.next_minor = next_minor。next_patch(self)→self.clone()后clone.patch += 1;挂载Version.next_patch = next_patch。
4. Collection 结构总览#
文件 |
|
|
成员任务 |
|---|---|---|---|
|
未定义 |
— |
(不自动注册) |
|
|
|
|
|
|
|
|
|
未定义 |
— |
|
|
未定义 |
— |
|
|
|
同 |
见下 |
|
|
|
|
|
未定义 |
— |
|
集合注册方式汇总:
ci.py、docs.py、packaging/release.py通过在模块级定义ns = Collection(...)自动注册任务。packaging/__init__.py复用release的 Collection 作为自身ns,并将vendorize任务直接导入供使用。checks.py、pytest.py、testing.py、vendorize.py、console.py、environment.py、util.py、watch.py、autodoc.py均未定义模块级ns(其中autodoc.py本身不含@task,console/environment/util/watch亦无@task)。
附注:任务参数默认值精度说明#
所有
@task函数与其参数默认值均逐字取自源码函数签名。docs.build、testing.test、pytest.test等任务带显式help={...}字典,键名见各节。ci.py、packaging/release.py的ns.configure(...)为模块加载期确定的固定配置;checks.py/pytest.py/testing.py等的配置读取发生在任务函数体内(c.config.get(...)、c.<key>),并非由ns.configure预设。