-
-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
使用 pdm init 初始化项目
在包内 __init__ 中添加内容
from pdm.core import Core
from .command import HelloCommand
def hello_plugin(core: Core):
core.register_command(HelloCommand, "hello")同目录新建了一个文件 command.py
from pdm.cli.commands.base import BaseCommand
class HelloCommand(BaseCommand):
"""向指定的人打招呼。
如果未指定,将从"hello.name"配置中读取。
"""
name = 'hello'
def add_arguments(self, parser):
parser.add_argument("-n", "--name", help="要问候的人的姓名")
def handle(self, project, options):
if not options.name:
name = project.config["hello.name"]
else:
name = options.name
print(f"Hello, {name}")在 pyproject.toml 文件中添加
[tool.pdm]
distribution = false
plugins = [
"-e file:///${PROJECT_ROOT}"
]在命令行执行
pdm install --plugins执行 pdm self list 也能看到注册的插件,但是使用 pdm hello 这个命令会出现错误
$ pdm hello 123
Usage: pdm [-h] [-V] [-c CONFIG] [-v | -q] [--no-cache] [-I] [--pep582 [SHELL]] [-n] ...
pdm: error: Script unknown: hello
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels