livingproof 2.2.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ """Thin command routing for Living Proof Labs."""
@@ -0,0 +1,14 @@
1
+ {
2
+ "distribution": "livingproof",
3
+ "format_version": 1,
4
+ "identity": {
5
+ "base_version": "2.2.8",
6
+ "branch": "main-0d6e4079",
7
+ "commit": "ac8602a95869c3c2cf04c3c7e47ffdb99f77c283",
8
+ "distance": 0,
9
+ "format_version": 1,
10
+ "history": "tagged",
11
+ "state": "clean"
12
+ },
13
+ "package_version": "2.2.8"
14
+ }
livingproof/cli.py ADDED
@@ -0,0 +1,118 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Discover installed Click commands without importing plugins during group help."""
3
+ from importlib.metadata import entry_points
4
+ import re
5
+
6
+ import click
7
+ from click.shell_completion import CompletionItem
8
+
9
+ from .completion import completion
10
+ from .plugin_management import plugins
11
+
12
+ PLUGIN_GROUP = "livingproof.capability.commands"
13
+ INSTALL_REPORT = (
14
+ "Install explicitly with: livingproof plugins install livingproof-capability-report. "
15
+ "To pin a release, append --version 3.0.1. The installer targets the same Python environment or Debian package "
16
+ "context as livingproof and verifies the required common dependency. "
17
+ "No packages are installed automatically."
18
+ )
19
+
20
+
21
+ class Unavailable(click.Command):
22
+ def __init__(self, name, reason):
23
+ super().__init__(name, help=reason)
24
+ self.reason = reason
25
+
26
+ def get_help(self, ctx):
27
+ raise click.ClickException(self.reason)
28
+
29
+ def invoke(self, ctx):
30
+ raise click.ClickException(self.reason)
31
+
32
+
33
+ class Plugins(click.Group):
34
+ """One small entry-point contract: names map directly to Click commands."""
35
+
36
+ def candidates(self):
37
+ found = {}
38
+ for entry in entry_points(group=PLUGIN_GROUP):
39
+ if re.fullmatch(r"[a-z][a-z0-9-]*", entry.name):
40
+ found.setdefault(entry.name, []).append(entry)
41
+ return found
42
+
43
+ def list_commands(self, ctx):
44
+ return sorted({"report", *self.candidates()})
45
+
46
+ def shell_complete(self, ctx, incomplete):
47
+ # Listing plugins must not import them. Click resolves the selected entry
48
+ # through get_command during resilient parsing for deeper completions.
49
+ commands = [] if incomplete.startswith("-") else [
50
+ CompletionItem(name) for name in self.list_commands(ctx)
51
+ if name.startswith(incomplete)
52
+ ]
53
+ return commands + click.Command.shell_complete(self, ctx, incomplete)
54
+
55
+ def format_commands(self, ctx, formatter):
56
+ found = self.candidates()
57
+ rows = [(name, "Installed plugin" if name in found else "Optional reporting plugin (install required)")
58
+ for name in self.list_commands(ctx)]
59
+ with formatter.section("Commands"):
60
+ formatter.write_dl(rows)
61
+
62
+ def get_command(self, ctx, name):
63
+ entries = self.candidates().get(name, [])
64
+ if not entries:
65
+ return Unavailable(name, INSTALL_REPORT) if name == "report" else None
66
+ if len(entries) != 1:
67
+ return Unavailable(name, f"Multiple installed plugins provide '{name}'. "
68
+ "Remove the conflicting distribution from this environment.")
69
+ entry = entries[0]
70
+ try:
71
+ command = entry.load()
72
+ if not isinstance(command, click.Command):
73
+ raise TypeError("entry point must expose a Click Command")
74
+ except Exception as exc:
75
+ return Unavailable(name, f"Cannot load plugin '{name}': {type(exc).__name__}: {exc}")
76
+ return command
77
+
78
+
79
+ def show_version(ctx, param, value):
80
+ if not value or ctx.resilient_parsing:
81
+ return
82
+ from .version import current_version
83
+ identity, package, source = current_version()
84
+ click.echo(f"livingproof, version {identity}")
85
+ click.echo(f"Package: {package}; identity source: {source}")
86
+ ctx.exit()
87
+
88
+
89
+ @click.group(invoke_without_command=True)
90
+ @click.option("--version", is_flag=True, is_eager=True, expose_value=False,
91
+ callback=show_version, help="Show this tool’s build identity and package version.")
92
+ @click.pass_context
93
+ def main(ctx):
94
+ """Living Proof Labs: specs, evidence, assessments and portable reports.
95
+
96
+ Plugins come from packages explicitly installed in this Python environment.
97
+
98
+ \b
99
+ Enable tab completion in this Bash shell:
100
+ eval "$(livingproof completion bash)"
101
+ For installed-file status and new-shell setup:
102
+ livingproof completion status
103
+ """
104
+ if ctx.invoked_subcommand is None:
105
+ click.echo(ctx.get_help())
106
+
107
+
108
+ @main.group(cls=Plugins, invoke_without_command=True)
109
+ @click.pass_context
110
+ def capability(ctx):
111
+ """Work with capability evidence through installed plugins."""
112
+ if ctx.invoked_subcommand is None:
113
+ click.echo(ctx.get_help())
114
+
115
+
116
+ main.add_command(completion)
117
+
118
+ main.add_command(plugins)
@@ -0,0 +1,129 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Explicit Bash setup; never modify startup files or claim parent-shell state."""
3
+ import os
4
+ from pathlib import Path
5
+ import sys
6
+
7
+ import click
8
+ from click.shell_completion import BashComplete
9
+
10
+ ACTIVATE = 'eval "$(livingproof completion bash)"'
11
+ LOADER = ('# Installed by livingproof completion install; safe to remove.\n'
12
+ 'eval "$(_LIVINGPROOF_COMPLETE=bash_source livingproof)"\n')
13
+
14
+
15
+ def user_directory():
16
+ configured = os.environ.get("BASH_COMPLETION_USER_DIR")
17
+ if configured:
18
+ directory = Path(configured)
19
+ if ":" in configured or not directory.is_absolute():
20
+ raise click.ClickException("BASH_COMPLETION_USER_DIR must be one absolute directory.")
21
+ else:
22
+ data = os.environ.get("XDG_DATA_HOME")
23
+ if data and not Path(data).is_absolute():
24
+ raise click.ClickException("XDG_DATA_HOME must be an absolute directory.")
25
+ directory = (Path(data) if data else Path.home() / ".local/share") / "bash-completion"
26
+ return directory / "completions"
27
+
28
+
29
+ def guidance():
30
+ click.echo("Bash completion setup (Bash 4.4 or newer)")
31
+ package_file = Path(sys.prefix) / "share/bash-completion/completions/livingproof"
32
+ framework = Path("/usr/share/bash-completion/bash_completion")
33
+ user_file = user_directory() / "livingproof"
34
+ for label, path in (("Package registration", package_file),
35
+ ("User registration", user_file), ("Bash-completion framework", framework)):
36
+ click.echo(f"{label}: {'installed' if path.is_file() else 'not found'} ({path})")
37
+ click.echo(f"""
38
+ Installed files do not mean completion is loaded in your current shell.
39
+ This command runs in a child process and cannot inspect or change that shell.
40
+
41
+ Enable completion in your CURRENT Bash shell (also works without bash-completion):
42
+ {ACTIVATE}
43
+ Check the registration in that same shell:
44
+ complete -p livingproof
45
+ Try typing: livingproof capability <TAB>
46
+
47
+ For automatic loading in NEW shells on Debian/Ubuntu:
48
+ apt install bash-completion
49
+ Run apt as an administrator; this tool never elevates privileges or installs packages.
50
+ Then start a login shell, which reads the distribution's framework startup script:
51
+ bash --login
52
+ A new non-login shell (plain bash, including Docker's default bash) may still
53
+ leave the framework disabled. In that shell, use the CURRENT-shell command above.
54
+ Installing a Debian package cannot activate completion in an already-running shell.
55
+
56
+ Wheel/virtual-environment users: put the intended livingproof executable on PATH,
57
+ then register it in your user's standard bash-completion directory:
58
+ livingproof completion install
59
+ This still needs the framework loaded in new shells, or CURRENT-shell activation.
60
+ To remove that user-owned registration:
61
+ livingproof completion install --remove
62
+ Debian/pip remove package-owned registration files when uninstalling the package.
63
+ Already-loaded shell functions remain until the shell exits; remove one now with:
64
+ complete -r livingproof
65
+
66
+ No command here edits .bashrc or other startup files. For persistent non-login
67
+ shell activation without the framework, you may add the CURRENT-shell command
68
+ above to your own .bashrc yourself. Installed plugins are discovered dynamically;
69
+ Tab does not install plugins or run their command callbacks.""")
70
+
71
+
72
+ @click.group(invoke_without_command=True)
73
+ @click.pass_context
74
+ def completion(ctx):
75
+ """Show Bash setup/status and exact activation commands; no startup-file edits.
76
+
77
+ \b
78
+ Enable in the CURRENT Bash shell:
79
+ eval "$(livingproof completion bash)"
80
+ Show installed files and NEW-shell setup:
81
+ livingproof completion status
82
+ """
83
+ if ctx.invoked_subcommand is None:
84
+ guidance()
85
+
86
+
87
+ @completion.command()
88
+ def status():
89
+ """Show installed registration files and explain current/new-shell setup."""
90
+ guidance()
91
+
92
+
93
+ @completion.command()
94
+ @click.pass_context
95
+ def bash(ctx):
96
+ """Print Bash code. Activate with: eval "$(livingproof completion bash)"."""
97
+ click.echo(BashComplete(ctx.find_root().command, {}, "livingproof",
98
+ "_LIVINGPROOF_COMPLETE").source())
99
+
100
+
101
+ @completion.command()
102
+ @click.option("--remove", is_flag=True, help="Remove only the user registration created here.")
103
+ def install(remove):
104
+ """Register for this user in the standard directory; never edit startup files.
105
+
106
+ Requires bash-completion to be loaded in future shells. Existing unrelated
107
+ files are never overwritten. No administrator privileges are requested.
108
+ """
109
+ target = user_directory() / "livingproof"
110
+ try:
111
+ if target.is_symlink():
112
+ raise click.ClickException(f"Refusing to change a symlink: {target}")
113
+ if target.exists():
114
+ if target.read_text() != LOADER:
115
+ raise click.ClickException(f"Existing file was not created by this command: {target}")
116
+ if remove:
117
+ target.unlink()
118
+ elif not remove:
119
+ target.parent.mkdir(parents=True, exist_ok=True)
120
+ with target.open("x") as output:
121
+ output.write(LOADER)
122
+ except OSError as exc:
123
+ raise click.ClickException(f"Cannot update {target}: {exc}") from exc
124
+ click.echo(f"{'Removed' if remove else 'Registered'} user completion: {target}")
125
+ if not remove:
126
+ click.echo(f"Enable in this Bash shell now:\n {ACTIVATE}\n"
127
+ "Future shells need bash-completion loaded; run livingproof completion status.")
128
+ else:
129
+ click.echo("In a shell that already loaded it, run: complete -r livingproof")