-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: support local plugin install #8448
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
Open
LIghtJUNction
wants to merge
6
commits into
master
Choose a base branch
from
feat/plugin-install-editable-local
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a0644d1
feat: support local plugin install
LIghtJUNction f65172f
Merge remote-tracking branch 'origin/master' into feat/plugin-install…
LIghtJUNction 748901d
fix: make editable plugin install symlink
LIghtJUNction 34a5498
fix: harden local plugin install
LIghtJUNction 422ac6b
Update tests/test_cli_plugin.py
LIghtJUNction f2a685d
Update astrbot/cli/commands/cmd_plug.py
LIghtJUNction File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ uv.lock | |
| # IDE and editors | ||
| .vscode | ||
| .idea | ||
| .zed/ | ||
|
|
||
| # Logs and temporary files | ||
| botpy.log | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,103 @@ | ||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||
|
|
||||||||||||||||||
| import pytest | ||||||||||||||||||
| from click.testing import CliRunner | ||||||||||||||||||
|
|
||||||||||||||||||
| from astrbot.cli.commands.cmd_plug import plug | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def _write_plugin(path: Path, name: str = "astrbot_plugin_local_demo") -> None: | ||||||||||||||||||
| path.mkdir(parents=True) | ||||||||||||||||||
| (path / "metadata.yaml").write_text( | ||||||||||||||||||
| "\n".join( | ||||||||||||||||||
| [ | ||||||||||||||||||
| f"name: {name}", | ||||||||||||||||||
| "desc: Local plugin", | ||||||||||||||||||
| "version: 1.0.0", | ||||||||||||||||||
| "author: AstrBot", | ||||||||||||||||||
| "repo: https://example.com/local-plugin", | ||||||||||||||||||
| ], | ||||||||||||||||||
| ), | ||||||||||||||||||
| encoding="utf-8", | ||||||||||||||||||
| ) | ||||||||||||||||||
| (path / "main.py").write_text("PLUGIN_LOADED = True\n", encoding="utf-8") | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def _write_astrbot_root(path: Path) -> None: | ||||||||||||||||||
| (path / ".astrbot").touch() | ||||||||||||||||||
| (path / "data" / "plugins").mkdir(parents=True) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def test_plugin_install_editable_copies_local_plugin( | ||||||||||||||||||
| monkeypatch: pytest.MonkeyPatch, | ||||||||||||||||||
| tmp_path: Path, | ||||||||||||||||||
| ) -> None: | ||||||||||||||||||
| root = tmp_path / "root" | ||||||||||||||||||
| source = tmp_path / "source-plugin" | ||||||||||||||||||
| root.mkdir() | ||||||||||||||||||
| _write_astrbot_root(root) | ||||||||||||||||||
| _write_plugin(source) | ||||||||||||||||||
| monkeypatch.chdir(root) | ||||||||||||||||||
|
|
||||||||||||||||||
| result = CliRunner().invoke( | ||||||||||||||||||
| plug, | ||||||||||||||||||
| ["install", "-e", str(source)], | ||||||||||||||||||
| catch_exceptions=False, | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| target = root / "data" / "plugins" / "astrbot_plugin_local_demo" | ||||||||||||||||||
| assert result.exit_code == 0 | ||||||||||||||||||
| assert (target / "metadata.yaml").exists() | ||||||||||||||||||
| assert (target / "main.py").read_text(encoding="utf-8") == "PLUGIN_LOADED = True\n" | ||||||||||||||||||
|
LIghtJUNction marked this conversation as resolved.
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def test_plugin_install_accepts_local_path_without_editable_flag( | ||||||||||||||||||
| monkeypatch: pytest.MonkeyPatch, | ||||||||||||||||||
| tmp_path: Path, | ||||||||||||||||||
| ) -> None: | ||||||||||||||||||
| root = tmp_path / "root" | ||||||||||||||||||
| source = tmp_path / "source-plugin" | ||||||||||||||||||
| root.mkdir() | ||||||||||||||||||
| _write_astrbot_root(root) | ||||||||||||||||||
| _write_plugin(source) | ||||||||||||||||||
| monkeypatch.chdir(root) | ||||||||||||||||||
|
|
||||||||||||||||||
| result = CliRunner().invoke(plug, ["install", str(source)]) | ||||||||||||||||||
|
|
||||||||||||||||||
| assert result.exit_code == 0 | ||||||||||||||||||
| assert ( | ||||||||||||||||||
| root / "data" / "plugins" / "astrbot_plugin_local_demo" / "metadata.yaml" | ||||||||||||||||||
| ).exists() | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an assertion to verify that the non-editable local installation copies the directory instead of creating a symlink.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def test_plugin_install_editable_rejects_existing_plugin( | ||||||||||||||||||
| monkeypatch: pytest.MonkeyPatch, | ||||||||||||||||||
| tmp_path: Path, | ||||||||||||||||||
| ) -> None: | ||||||||||||||||||
| root = tmp_path / "root" | ||||||||||||||||||
| source = tmp_path / "source-plugin" | ||||||||||||||||||
| root.mkdir() | ||||||||||||||||||
| _write_astrbot_root(root) | ||||||||||||||||||
| _write_plugin(source) | ||||||||||||||||||
| _write_plugin(root / "data" / "plugins" / "astrbot_plugin_local_demo") | ||||||||||||||||||
| monkeypatch.chdir(root) | ||||||||||||||||||
|
|
||||||||||||||||||
| result = CliRunner().invoke(plug, ["install", "-e", str(source)]) | ||||||||||||||||||
|
|
||||||||||||||||||
| assert result.exit_code != 0 | ||||||||||||||||||
| assert "already exists" in result.output | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def test_plugin_install_requires_name_or_editable_path( | ||||||||||||||||||
| monkeypatch: pytest.MonkeyPatch, | ||||||||||||||||||
| tmp_path: Path, | ||||||||||||||||||
| ) -> None: | ||||||||||||||||||
| root = tmp_path / "root" | ||||||||||||||||||
| root.mkdir() | ||||||||||||||||||
| _write_astrbot_root(root) | ||||||||||||||||||
| monkeypatch.chdir(root) | ||||||||||||||||||
|
|
||||||||||||||||||
| result = CliRunner().invoke(plug, ["install"]) | ||||||||||||||||||
|
|
||||||||||||||||||
| assert result.exit_code != 0 | ||||||||||||||||||
| assert "Missing plugin name or local plugin path" in result.output | ||||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.