-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into opentofu/stages/sync-versions
- Loading branch information
Showing
19 changed files
with
539 additions
and
122 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,54 @@ | ||
import logging | ||
import pathlib | ||
from typing import Optional | ||
|
||
from packaging.requirements import SpecifierSet | ||
from pydantic import BaseModel, ConfigDict, field_validator | ||
|
||
from _nebari._version import __version__ | ||
from _nebari.utils import yaml | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ConfigSetMetadata(BaseModel): | ||
model_config: ConfigDict = ConfigDict(extra="allow", arbitrary_types_allowed=True) | ||
name: str # for use with guided init | ||
description: Optional[str] = None | ||
nebari_version: str | SpecifierSet | ||
|
||
@field_validator("nebari_version") | ||
@classmethod | ||
def validate_version_requirement(cls, version_req): | ||
if isinstance(version_req, str): | ||
version_req = SpecifierSet(version_req, prereleases=True) | ||
|
||
return version_req | ||
|
||
def check_version(self, version): | ||
if not self.nebari_version.contains(version, prereleases=True): | ||
raise ValueError( | ||
f'Nebari version "{version}" is not compatible with ' | ||
f'version requirement {self.nebari_version} for "{self.name}" config set.' | ||
) | ||
|
||
|
||
class ConfigSet(BaseModel): | ||
metadata: ConfigSetMetadata | ||
config: dict | ||
|
||
|
||
def read_config_set(config_set_filepath: str): | ||
"""Read a config set from a config file.""" | ||
|
||
filename = pathlib.Path(config_set_filepath) | ||
|
||
with filename.open() as f: | ||
config_set_yaml = yaml.load(f) | ||
|
||
config_set = ConfigSet(**config_set_yaml) | ||
|
||
# validation | ||
config_set.metadata.check_version(__version__) | ||
|
||
return config_set |
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
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
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
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
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
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
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
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
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,42 @@ | ||
from importlib.metadata import version | ||
|
||
import rich | ||
import typer | ||
from rich.table import Table | ||
|
||
from nebari.hookspecs import hookimpl | ||
|
||
|
||
@hookimpl | ||
def nebari_subcommand(cli: typer.Typer): | ||
plugin_cmd = typer.Typer( | ||
add_completion=False, | ||
no_args_is_help=True, | ||
rich_markup_mode="rich", | ||
context_settings={"help_option_names": ["-h", "--help"]}, | ||
) | ||
|
||
cli.add_typer( | ||
plugin_cmd, | ||
name="plugin", | ||
help="Interact with nebari plugins", | ||
rich_help_panel="Additional Commands", | ||
) | ||
|
||
@plugin_cmd.command() | ||
def list(ctx: typer.Context): | ||
""" | ||
List installed plugins | ||
""" | ||
from nebari.plugins import nebari_plugin_manager | ||
|
||
external_plugins = nebari_plugin_manager.get_external_plugins() | ||
|
||
table = Table(title="Plugins") | ||
table.add_column("name", justify="left", no_wrap=True) | ||
table.add_column("version", justify="left", no_wrap=True) | ||
|
||
for plugin in external_plugins: | ||
table.add_row(plugin, version(plugin)) | ||
|
||
rich.print(table) |
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
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
Oops, something went wrong.