-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat:tui #9
Merged
feat:tui #9
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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,2 @@ | ||
include requirements.txt | ||
include LICENSE.md |
This file contains 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,139 @@ | ||
import json | ||
import os.path | ||
from typing import List | ||
|
||
import click | ||
from hivemind_plugin_manager import find_plugins, HiveMindPluginTypes | ||
from json_database import JsonStorageXDG | ||
from ovos_utils.xdg_utils import xdg_config_home, xdg_data_home | ||
|
||
_DEFAULT = { | ||
"agent_protocol": {"module": "hivemind-ovos-agent-plugin", | ||
"hivemind-ovos-agent-plugin": { | ||
"host": "127.0.0.1", | ||
"port": 8181 | ||
}}, | ||
"binary_protocol": {"module": None}, | ||
"network_protocol": {"module": "hivemind-websocket-plugin", | ||
"hivemind-websocket-plugin": { | ||
"host": "0.0.0.0", | ||
"port": 5678, | ||
"ssl": False, | ||
"cert_dir": f"{xdg_data_home()}/hivemind", | ||
"cert_name": "hivemind" | ||
}}, | ||
"database": {"module": "hivemind-json-db-plugin", | ||
"hivemind-json-db-plugin": { | ||
"name": "clients", | ||
"subfolder": "hivemind-core" | ||
}} | ||
} | ||
|
||
mapping = { | ||
HiveMindPluginTypes.BINARY_PROTOCOL: "binary_protocol", | ||
HiveMindPluginTypes.AGENT_PROTOCOL: "agent_protocol", | ||
HiveMindPluginTypes.NETWORK_PROTOCOL: "network_protocol", | ||
HiveMindPluginTypes.DATABASE: "database" | ||
} | ||
|
||
|
||
def cast_to_enum(plugin_type: str) -> HiveMindPluginTypes: | ||
if plugin_type == "network": | ||
plugin_type = HiveMindPluginTypes.NETWORK_PROTOCOL | ||
elif plugin_type == "agent": | ||
plugin_type = HiveMindPluginTypes.AGENT_PROTOCOL | ||
elif plugin_type == "binary": | ||
plugin_type = HiveMindPluginTypes.BINARY_PROTOCOL | ||
elif plugin_type == "database": | ||
plugin_type = HiveMindPluginTypes.DATABASE | ||
else: | ||
raise ValueError("invalid plugin type") | ||
return plugin_type | ||
|
||
|
||
def get_server_config() -> JsonStorageXDG: | ||
"""from ~/.config/hivemind-core/server.json """ | ||
db = JsonStorageXDG("server", | ||
xdg_folder=xdg_config_home(), | ||
subfolder="hivemind-core") | ||
# create file if it doesnt exist | ||
if not os.path.isfile(db.path): | ||
db.merge(_DEFAULT) | ||
db.store() | ||
# ensure no missing top level values | ||
for k in [_ for _ in _DEFAULT if _ not in db]: | ||
db[k] = _DEFAULT[k] | ||
return db | ||
|
||
|
||
# Initialize the configuration | ||
config = get_server_config() | ||
|
||
|
||
def list_plugins(plugin_type: str) -> List[str]: | ||
"""Find all plugins of the specified type.""" | ||
return list(find_plugins(HiveMindPluginTypes(plugin_type))) | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
"""A TUI for managing HiveMind configuration.""" | ||
pass | ||
|
||
|
||
@cli.command("list") | ||
@click.argument("plugin_type", type=click.Choice(["network", "agent", "binary", "database"])) | ||
def list_plugins_command(plugin_type): | ||
"""List available plugins of the given type. Valid: "network", "agent", "binary", "database" """ | ||
if plugin_type not in ["network", "agent", "binary", "database"]: | ||
click.echo(f"Invalid plugin type: {plugin_type}", err=True) | ||
return | ||
plugin_type = cast_to_enum(plugin_type) | ||
plugins = list_plugins(plugin_type) | ||
click.echo(json.dumps(plugins, indent=2)) | ||
|
||
|
||
@cli.command("set") | ||
@click.argument("plugin_type", type=click.Choice(["network", "agent", "binary", "database"])) | ||
@click.argument("plugin_name") | ||
def set_plugin(plugin_type, plugin_name): | ||
"""Set the plugin for a specific type. Valid: "network", "agent", "binary", "database" """ | ||
if plugin_type not in ["network", "agent", "binary", "database"]: | ||
click.echo(f"Invalid plugin type: {plugin_type}", err=True) | ||
return | ||
|
||
plugin_type = cast_to_enum(plugin_type) | ||
|
||
available_plugins = list_plugins(plugin_type) | ||
if plugin_name not in available_plugins: | ||
click.echo(f"Plugin '{plugin_name}' not available for '{plugin_type}'.", err=True) | ||
return | ||
|
||
config[mapping[plugin_type]]["module"] = plugin_name | ||
config.store() | ||
click.echo(f"Set {plugin_type} to {plugin_name}.") | ||
|
||
|
||
@cli.command("get") | ||
@click.argument("plugin_type", type=click.Choice(["network", "agent", "binary", "database"])) | ||
def get_plugin(plugin_type): | ||
"""Get the current plugin for a specific type. Valid: "network", "agent", "binary", "database" """ | ||
if plugin_type not in ["network", "agent", "binary", "database"]: | ||
click.echo(f"Invalid plugin type: {plugin_type}", err=True) | ||
return | ||
plugin_type = cast_to_enum(plugin_type) | ||
key = mapping[plugin_type] | ||
if key in config and "module" in config[key]: | ||
click.echo(config[plugin_type]["module"]) | ||
else: | ||
click.echo(f"No plugin set for {plugin_type}.") | ||
|
||
|
||
@cli.command("show-config") | ||
def show_config(): | ||
"""Show the full configuration.""" | ||
click.echo(json.dumps(config, indent=2, ensure_ascii=False, sort_keys=True)) | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
This file contains 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,3 @@ | ||
json_database | ||
ovos-bus-client | ||
ovos-utils |
This file contains 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 |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
|
||
def get_version(): | ||
""" Find the version of the package""" | ||
version = None | ||
version_file = os.path.join(BASEDIR, 'hivemind_plugin_manager', 'version.py') | ||
major, minor, build, alpha = (None, None, None, None) | ||
with open(version_file) as f: | ||
|
@@ -48,7 +47,10 @@ def required(requirements_file): | |
url='https://github.com/JarbasHiveMind/hivemind-plugin-manager', | ||
license='Apache-2.0', | ||
author='jarbasAi', | ||
#install_requires=required("requirements.txt"), | ||
install_requires=required("requirements.txt"), | ||
author_email='[email protected]', | ||
description='plugin manager for hivemind-core' | ||
description='plugin manager for hivemind-core', | ||
entry_points={ | ||
"console_scripts": ["hpm=hivemind_plugin_manager.tui:cli"] | ||
} | ||
) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Dependencies should be pinned to specific versions in requirements.txt
The
requirements.txt
file is correctly included in the package distribution viaMANIFEST.in
. However, the dependencies are not pinned to specific versions, which could lead to compatibility issues if newer versions introduce breaking changes. Consider pinning the dependencies to specific versions using the==
operator, for example:requirements.txt
: Add version constraints for all dependencies🔗 Analysis chain
Ensure inclusion of requirements in the packaged distribution.
Since you are loading dependencies using
required("requirements.txt")
, confirm thatrequirements.txt
is included in the distributed package. You already added it to theMANIFEST.in
, but let’s verify it is there and double-check pinned vs. unpinned versions to avoid accidental breakage.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 66
Script:
Length of output: 63