-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: restructure a little and add tests #2
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,83 @@ | ||
from __future__ import annotations | ||
|
||
from . import skbuild | ||
import pathlib | ||
from collections.abc import MutableMapping, Sequence | ||
from importlib.metadata import EntryPoint | ||
|
||
import click | ||
|
||
def run_cli() -> None: | ||
from . import __version__ | ||
from ._compat.importlib import metadata | ||
|
||
__all__ = ["skbuild"] | ||
|
||
|
||
def __dir__() -> list[str]: | ||
return __all__ | ||
|
||
|
||
class LazyGroup(click.Group): | ||
""" | ||
Entry point to skbuild command. | ||
Lazy loader for click commands. Based on Click's documentation, but uses | ||
EntryPoints. | ||
""" | ||
skbuild() | ||
|
||
def __init__( | ||
self, | ||
name: str | None = None, | ||
commands: MutableMapping[str, click.Command] | ||
| Sequence[click.Command] | ||
| None = None, | ||
*, | ||
lazy_subcommands: Sequence[EntryPoint] = (), | ||
**kwargs: object, | ||
): | ||
super().__init__(name, commands, **kwargs) | ||
self.lazy_subcommands = {v.name: v for v in lazy_subcommands} | ||
|
||
def list_commands(self, ctx: click.Context) -> list[str]: | ||
return sorted([*super().list_commands(ctx), *self.lazy_subcommands]) | ||
|
||
def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None: | ||
if cmd_name in self.lazy_subcommands: | ||
return self._lazy_load(cmd_name) | ||
return super().get_command(ctx, cmd_name) | ||
|
||
def _lazy_load(self, cmd_name: str) -> click.Command: | ||
ep = self.lazy_subcommands[cmd_name] | ||
cmd_object = ep.load() | ||
if not isinstance(cmd_object, click.Command): | ||
msg = f"Lazy loading of {ep} failed by returning a non-command object" | ||
raise ValueError(msg) | ||
return cmd_object | ||
|
||
|
||
# Add all plugin commands. | ||
CMDS = list(metadata.entry_points(group="skbuild.commands")) | ||
|
||
|
||
@click.group("skbuild", cls=LazyGroup, lazy_subcommands=CMDS) | ||
@click.version_option(__version__) | ||
@click.help_option("--help", "-h") | ||
@click.option( | ||
"--root", | ||
"-r", | ||
type=click.Path( | ||
exists=True, | ||
file_okay=False, | ||
dir_okay=True, | ||
writable=True, | ||
path_type=pathlib.Path, | ||
), | ||
help="Path to the Python project's root", | ||
) | ||
@click.pass_context | ||
def skbuild(ctx: click.Context, root: pathlib.Path) -> None: # noqa: ARG001 | ||
""" | ||
scikit-build Main CLI interface | ||
""" | ||
# TODO: Add specific implementations | ||
|
||
|
||
if __name__ == "__main__": | ||
run_cli() | ||
skbuild() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import annotations | ||
|
||
import click | ||
|
||
__all__: list[str] = ["init"] | ||
|
||
|
||
def __dir__() -> list[str]: | ||
return __all__ | ||
|
||
|
||
@click.command() | ||
@click.help_option("--help", "-h") | ||
@click.pass_context | ||
def init(ctx: click.Context) -> None: # noqa: ARG001 | ||
""" | ||
Add scikit-build to an existing project | ||
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. Existing CMake or Python project? Or have to have both? 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. I'm not totally sure. :) I was thinking it could be like new but not overwrite existing files, and maybe adapt to some extent to what is already written. 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. CMake wise it could ve tricky as everyone is having a different format. We would need a build-dir if we want to do some parsing to find the libraries that link to python-devel. Or we could Python-side though should be easier to introspect, but custom Or we could assume the project is either pure-python or pure-cmake for this case? That could be the simplest to support. |
||
""" | ||
# TODO: Add specific implementations |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ def __dir__() -> list[str]: | |
|
||
|
||
@click.command() | ||
@click.help_option("--help", "-h") | ||
@click.pass_context | ||
def metadata(ctx: click.Context) -> None: # noqa: ARG001 | ||
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. I was thinking, this might make more sense to be |
||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import annotations | ||
|
||
import click | ||
|
||
__all__: list[str] = ["new"] | ||
|
||
|
||
def __dir__() -> list[str]: | ||
return __all__ | ||
|
||
|
||
@click.command() | ||
@click.help_option("--help", "-h") | ||
@click.pass_context | ||
def new(ctx: click.Context) -> None: # noqa: ARG001 | ||
""" | ||
Start a new project | ||
""" | ||
# TODO: Add specific implementations |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.