Skip to content

Commit

Permalink
chore: move --dep-tree to -X/--extras
Browse files Browse the repository at this point in the history
  • Loading branch information
actionless committed Sep 11, 2024
1 parent f6b9f40 commit 75663f0
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 40 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ non_final_globals:
-e '=.*\|' \
-e '=.*(dict|list|Callable)\[' \
\
-e '__all__' \
\
$(GLOBALS_IGNORES) \
| sort \
) ; \
Expand All @@ -153,6 +155,8 @@ unreasonable_globals:
-e ' = [a-zA-Z_]+\[' \
-e ' = str[^(]' \
\
-e '__all__' \
\
$(GLOBALS_IGNORES) \
| sort \
) ; \
Expand Down
63 changes: 44 additions & 19 deletions pikaur/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
HelpMessage = tuple[str | None, str | None, str | None]


# @TODO: refactor to use NamedTuple instead of normal tuple


PACMAN_ACTIONS: "Final[ArgSchema]" = [
("S", "sync", None, None),
("Q", "query", None, None),
Expand All @@ -40,6 +43,7 @@
PIKAUR_ACTIONS: "Final[ArgSchema]" = [
("P", "pkgbuild", None, None),
("G", "getpkgbuild", None, None),
("X", "extras", None, None),
(None, "interactive_package_select", None, None),
]

Expand Down Expand Up @@ -210,6 +214,18 @@ def get_pikaur_bool_opts(action: str | None = None) -> ArgSchema:
translate("install built package"),
),
]
if action == "extras":
result += [
(
"d", "dep-tree",
None,
translate("visualize package dependency tree"),
),
# (
# "q", "quiet", None,
# translate("less verbose output"),
# ),
]
result += [
(
None, "print-commands", PikaurConfig().ui.PrintCommands.get_bool(),
Expand Down Expand Up @@ -356,6 +372,14 @@ def get_pikaur_int_opts(action: str | None = None) -> ArgSchema:
translate("user ID to run makepkg if pikaur started from root"),
),
]
if action == "extras":
result += [
(
"l", "level",
2,
translate("dependency tree level"),
),
]
return result


Expand Down Expand Up @@ -469,38 +493,39 @@ class MissingArgumentError(Exception):
class PikaurArgs(Namespace):
unknown_args: list[str]
raw: list[str]

# typehints:
info: bool | None
keepbuild: bool | None
output_dir: str | None
# @TODO: remove? :
# nodeps: bool | None
# owns: bool | None
# check: bool | None
aur_clone_concurrency: int | None
build_gpgdir: str
clean: int
config: str | None
dbpath: str | None
devel: int
ignore: list[str]
info: bool | None
interactive_package_select: bool = False
keepbuild: bool | None
level: int
makepkg_config: str | None
mflags: str | None
makepkg_path: str | None
pacman_path: str
pacman_conf_path: str
quiet: bool
sysupgrade: int
devel: int
mflags: str | None
namesonly: bool
build_gpgdir: str
needed: bool
config: str | None
output_dir: str | None
pacman_conf_path: str
pacman_path: str
positional: list[str]
preserve_env: str = ""
quiet: bool
read_stdin: bool = False
refresh: int
clean: int
dbpath: str | None
root: str | None

aur_clone_concurrency: int | None
skip_aur_pull: bool | None
positional: list[str]
read_stdin: bool = False
preserve_env: str = ""
interactive_package_select: bool = False
sysupgrade: int

def __init__(self) -> None:
self.positional = []
Expand Down
9 changes: 9 additions & 0 deletions pikaur/extras/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""
Experimental extra functions for Pikaur.
MB later it will be turned into a plugin system.
"""
from . import dep_tree

__all__ = [
"dep_tree",
]
22 changes: 18 additions & 4 deletions pikaur_meta_helpers/dep_tree.py → pikaur/extras/dep_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@

import pyalpm

from pikaur.exceptions import SysExit
from pikaur.i18n import translate
from pikaur.pacman import PackageDB
from pikaur.pikaprint import ColorsHighlight, color_line, format_paragraph, get_term_width
from pikaur.pikaprint import (
ColorsHighlight,
bold_line,
color_line,
format_paragraph,
get_term_width,
print_error,
print_stdout,
)
from pikaur.pikatypes import InstallInfo
from pikaur.print_department import pretty_format_upgradeable

Expand Down Expand Up @@ -70,7 +80,7 @@ def print_package_info(
),
),
)
print(output)
print_stdout(output)


def add_dependencies_to_stack(
Expand Down Expand Up @@ -115,7 +125,7 @@ def process_stack_item(

if item.content in already_processed:
print_package_info(install_info, level_spaces, desc_spaces, description=False)
print(desc_spaces + "^")
print_stdout(desc_spaces + "^")
return

print_package_info(install_info, level_spaces, desc_spaces, description=description)
Expand All @@ -126,7 +136,7 @@ def process_stack_item(

elif item.item_type == "title":
_level_spaces, desc_spaces = compute_padding(item.level - 1, global_padding, branch_padding)
print(desc_spaces + item.content)
print_stdout(desc_spaces + item.content)

else:
raise NotImplementedError
Expand All @@ -136,6 +146,10 @@ def cli(pkgname: str, max_level: int = 2, *, description: bool = True) -> None:
"""Entry point for the CLI."""
local_pkgs_dict = PackageDB.get_local_dict()

if pkgname not in local_pkgs_dict:
print_error(translate("{pkg} is not installed").format(pkg=bold_line(pkgname)))
raise SysExit(6)

already_processed: set[str] = set()
stack = [StackItem("pkg", pkgname, 0)]

Expand Down
40 changes: 24 additions & 16 deletions pikaur/help_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,29 @@ def _format_options_help(options: list[HelpMessage]) -> str:
def cli_print_help() -> None:
args = parse_args()

proc = spawn([
args.pacman_path,
*reconstruct_args(args, ignore_args=get_pikaur_long_opts()),
])
if not proc.stdout_text:
no_response_from_pacman = translate("No response from Pacman")
raise RuntimeError(no_response_from_pacman)
pacman_help = proc.stdout_text.replace(
"pacman", PIKAUR_NAME,
).replace(
"options:", "\n" + translate("Common pacman options:"),
)
if not (args.pkgbuild or args.getpkgbuild or args.extras):
proc = spawn([
args.pacman_path,
*reconstruct_args(args, ignore_args=get_pikaur_long_opts()),
])
if not proc.stdout_text:
no_response_from_pacman = translate("No response from Pacman")
raise RuntimeError(no_response_from_pacman)
pacman_help = proc.stdout_text.replace(
"pacman", PIKAUR_NAME,
).replace(
"options:", "\n" + translate("Common pacman options:"),
)
else:
pacman_help = ""

if LiteralArgs.HELP in pacman_help:
pacman_help += (
"\n" +
translate("pikaur-specific operations:") + "\n " +
translate("pikaur {-P --pkgbuild} [options] [file(s)]") + "\n " +
translate("pikaur {-G --getpkgbuild} [options] <package(s)>")
"\n"
+ translate("pikaur-specific operations:") + "\n "
+ translate("pikaur {-P --pkgbuild} [options] [file(s)]") + "\n "
+ translate("pikaur {-G --getpkgbuild} [options] <package(s)>") + "\n "
+ translate("pikaur {-X --extras} [options]")
)
if args.pkgbuild:
pacman_help = (
Expand All @@ -70,6 +74,10 @@ def cli_print_help() -> None:
pacman_help = (
translate("usage: pikaur {-G --getpkgbuild} [options] <package(s)>")
)
if args.extras:
pacman_help = (
translate("usage: pikaur {-X --extras} [options]")
)

pikaur_options_help = get_help()

Expand Down
19 changes: 18 additions & 1 deletion pikaur/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import pyalpm

from . import extras
from .args import parse_args
from .config import (
DEFAULT_INPUT_ENCODING,
Expand Down Expand Up @@ -284,7 +285,20 @@ def execute_pikaur_operation(
pikaur_operation()


def cli_entry_point() -> None:
def cli_extras() -> None:
args = parse_args()
if args.dep_tree:
if not args.positional:
print_error(translate("no package(s) specified"))
for pkg in args.positional:
extras.dep_tree.cli(
pkgname=pkg, max_level=args.level, description=not args.quiet,
)
else:
cli_print_help()


def cli_entry_point() -> None: # pylint: disable=too-many-statements
# pylint: disable=too-many-branches

try:
Expand Down Expand Up @@ -321,6 +335,9 @@ def cli_entry_point() -> None:
require_sudo = True
pikaur_operation = cli_pkgbuild

elif args.extras:
pikaur_operation = cli_extras

elif args.sync:
if args.search or args.list:
pikaur_operation = cli_search_packages
Expand Down

0 comments on commit 75663f0

Please sign in to comment.