Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

本地测试开发插件注册后,运行插件失败 #26

Open
522247020 opened this issue Sep 30, 2024 · 0 comments
Open

本地测试开发插件注册后,运行插件失败 #26

522247020 opened this issue Sep 30, 2024 · 0 comments

Comments

@522247020
Copy link

使用 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant