Skip to content

Commit

Permalink
Convert WeakAuras Companion port to a plug-in
Browse files Browse the repository at this point in the history
  • Loading branch information
layday committed Feb 11, 2024
1 parent 1787b25 commit e9b3b44
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 52 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ WeakAura updater
`WeakAuras Companion <https://weakauras.wtf/>`__. To use the updater
and provided that you have WeakAuras installed::

instawow weakauras-companion build
instawow plugins weakauras-companion build
instawow install instawow:weakauras-companion

You will have to rebuild the companion add-on prior to updating
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ readme = "README.rst"
urls.homepage = "http://github.com/layday/instawow"
packages = [
{ include = "instawow", from = "src" },
{ include = "instawow_wa_updater", from = "src" },
{ include = "instawow_gui", from = "gui-webview/src" },
]
include = [
Expand Down Expand Up @@ -82,6 +83,9 @@ test = [
"pytest-xdist",
]

[tool.poetry.plugins."instawow.plugins"]
"instawow_wa_updater" = "instawow_wa_updater._plugin"


[tool.ruff]
line-length = 99
Expand Down Expand Up @@ -119,6 +123,7 @@ mark-parentheses = false
known-first-party = [
"instawow",
"instawow_gui",
"instawow_wa_updater",
]
required-imports = [
"from __future__ import annotations",
Expand Down
2 changes: 1 addition & 1 deletion src/instawow/_sources/instawow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def resolve_one(self, defn: Defn, metadata: None) -> pkg_models.Pkg:
except StopIteration:
raise R.PkgNonexistent from None

from ..wa_updater import WaCompanionBuilder
from instawow_wa_updater._core import WaCompanionBuilder

builder = WaCompanionBuilder(self._manager_ctx)
if source_id == '1':
Expand Down
57 changes: 13 additions & 44 deletions src/instawow/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __str__(self) -> str:
)

def generate(self) -> None:
mw: _CtxObjWrapper | None = click.get_current_context().obj
mw: CtxObjWrapper | None = click.get_current_context().obj

if mw and mw.manager.ctx.config.global_config.auto_update_check:
from ._version import is_outdated
Expand All @@ -94,7 +94,7 @@ def generate_and_exit(self) -> NoReturn:
ctx.exit(self.exit_code)


class _CtxObjWrapper:
class CtxObjWrapper:
def __init__(self, ctx: click.Context) -> None:
self._ctx = ctx

Expand Down Expand Up @@ -303,7 +303,7 @@ def _parse_debug_option(
@click.pass_context
def cli(ctx: click.Context, **__: object) -> None:
"Add-on manager for World of Warcraft."
ctx.obj = _CtxObjWrapper(ctx)
ctx.obj = CtxObjWrapper(ctx)


@overload
Expand Down Expand Up @@ -387,7 +387,7 @@ def _parse_uri(
)
@click.pass_obj
def install(
mw: _CtxObjWrapper,
mw: CtxObjWrapper,
addons: Sequence[Defn],
replace: bool,
dry_run: bool,
Expand Down Expand Up @@ -416,7 +416,7 @@ def install(
)
@click.pass_obj
def update(
mw: _CtxObjWrapper,
mw: CtxObjWrapper,
addons: Sequence[Defn],
retain_strategies: bool,
dry_run: bool,
Expand Down Expand Up @@ -457,7 +457,7 @@ def installed_pkgs_to_defns():
help='Remove the add-on from the database but do not delete its folders.',
)
@click.pass_obj
def remove(mw: _CtxObjWrapper, addons: Sequence[Defn], keep_folders: bool) -> None:
def remove(mw: CtxObjWrapper, addons: Sequence[Defn], keep_folders: bool) -> None:
"Remove add-ons."
results = mw.run_with_progress(mw.manager.remove(addons, keep_folders))
Report(results.items()).generate_and_exit()
Expand All @@ -472,7 +472,7 @@ def remove(mw: _CtxObjWrapper, addons: Sequence[Defn], keep_folders: bool) -> No
help='Undo rollback by reinstalling an add-on using the default strategy.',
)
@click.pass_obj
def rollback(mw: _CtxObjWrapper, addon: Defn, undo: bool) -> None:
def rollback(mw: CtxObjWrapper, addon: Defn, undo: bool) -> None:
"Roll an add-on back to an older version."
from ._cli_prompts import Choice, ask, select

Expand Down Expand Up @@ -522,7 +522,7 @@ def rollback(mw: _CtxObjWrapper, addon: Defn, undo: bool) -> None:
'--list-unreconciled', is_flag=True, default=False, help='List unreconciled add-ons and exit.'
)
@click.pass_obj
def reconcile(mw: _CtxObjWrapper, auto: bool, rereconcile: bool, list_unreconciled: bool) -> None:
def reconcile(mw: CtxObjWrapper, auto: bool, rereconcile: bool, list_unreconciled: bool) -> None:
"Reconcile pre-installed add-ons."
from ._cli_prompts import PkgChoice, ask, confirm, select, skip
from .matchers import DEFAULT_MATCHERS, AddonFolder, get_unreconciled_folders
Expand Down Expand Up @@ -723,7 +723,7 @@ def search(
from ._cli_prompts import PkgChoice, ask, checkbox, confirm
from .catalogue.search import search

mw: _CtxObjWrapper = ctx.obj
mw: CtxObjWrapper = ctx.obj

catalogue_entries = mw.run_with_progress(
search(
Expand Down Expand Up @@ -780,7 +780,7 @@ class _ListFormat(StrEnum):
help='Change the output format.',
)
@click.pass_obj
def list_installed(mw: _CtxObjWrapper, addons: Sequence[Defn], output_format: _ListFormat) -> None:
def list_installed(mw: CtxObjWrapper, addons: Sequence[Defn], output_format: _ListFormat) -> None:
"List installed add-ons."
import sqlalchemy as sa

Expand Down Expand Up @@ -880,7 +880,7 @@ def info(ctx: click.Context, addon: Defn) -> None:
@cli.command
@click.argument('addon', callback=_with_manager(partial(_parse_uri, raise_invalid=False)))
@click.pass_obj
def reveal(mw: _CtxObjWrapper, addon: Defn) -> None:
def reveal(mw: CtxObjWrapper, addon: Defn) -> None:
"Bring an add-on up in your file manager."
pkg = mw.manager.get_pkg(addon, partial_match=True)
if pkg:
Expand All @@ -900,7 +900,7 @@ def reveal(mw: _CtxObjWrapper, addon: Defn) -> None:
help='Convert HTML and Markdown changelogs to plain text using pandoc.',
)
@click.pass_obj
def view_changelog(mw: _CtxObjWrapper, addon: Defn | None, convert: bool) -> None:
def view_changelog(mw: CtxObjWrapper, addon: Defn | None, convert: bool) -> None:
"""View the changelog of an installed add-on.
If `addon` is not provided, displays the changelogs of all add-ons
Expand Down Expand Up @@ -1026,7 +1026,7 @@ def format_combined_changelog_entry(source: str, slug: str, changelog: str):
help='Change the output format.',
)
@click.pass_obj
def list_sources(mw: _CtxObjWrapper, output_format: _ListFormat) -> None:
def list_sources(mw: CtxObjWrapper, output_format: _ListFormat) -> None:
"Print source metadata."
from cattrs.preconf.json import make_converter

Expand Down Expand Up @@ -1286,37 +1286,6 @@ def _plugin_group() -> None: # pyright: ignore[reportUnusedFunction]
"Registered plug-ins."


@cli.group('weakauras-companion')
def _weakauras_group() -> None:
"Manage your WeakAuras."


@_weakauras_group.command('build')
@click.pass_obj
def build_weakauras_companion(mw: _CtxObjWrapper) -> None:
"Build the WeakAuras Companion add-on."
from .wa_updater import WaCompanionBuilder

mw.run_with_progress(WaCompanionBuilder(mw.manager.ctx).build())


@_weakauras_group.command('list')
@click.pass_obj
def list_installed_wago_auras(mw: _CtxObjWrapper) -> None:
"List WeakAuras installed from Wago."
from .wa_updater import WaCompanionBuilder

aura_groups = WaCompanionBuilder(mw.manager.ctx).extract_installed_auras()
installed_auras = sorted(
(g.addon_name, a.id, a.url)
for g in aura_groups
for v in g.root.values()
for a in v
if not a.parent
)
click.echo(tabulate([('type', 'name', 'URL'), *installed_auras]))


@cli.command(hidden=True)
@click.option(
'--start-date',
Expand Down
1 change: 1 addition & 0 deletions src/instawow_wa_updater/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from __future__ import annotations
38 changes: 38 additions & 0 deletions src/instawow_wa_updater/_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from __future__ import annotations

import click

from instawow import cli


@click.group('weakauras-companion')
def wa_updater_command_group() -> None:
"Manage your WeakAuras."


@wa_updater_command_group.command('build')
@click.pass_obj
def build_weakauras_companion(mw: cli.CtxObjWrapper) -> None:
"Build the WeakAuras Companion add-on."
from ._core import WaCompanionBuilder

mw.run_with_progress(WaCompanionBuilder(mw.manager.ctx).build())


@wa_updater_command_group.command('list')
@click.pass_obj
def list_installed_wago_auras(mw: cli.CtxObjWrapper) -> None:
"List WeakAuras installed from Wago."
from instawow.utils import tabulate

from ._core import WaCompanionBuilder

aura_groups = WaCompanionBuilder(mw.manager.ctx).extract_installed_auras()
installed_auras = sorted(
(g.addon_name, a.id, a.url)
for g in aura_groups
for v in g.root.values()
for a in v
if not a.parent
)
click.echo(tabulate([('type', 'name', 'URL'), *installed_auras]))
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from typing_extensions import TypedDict
from yarl import URL

from ..http import CACHE_INDEFINITELY, make_generic_progress_ctx
from ..manager_ctx import ManagerCtx
from ..utils import StrEnum, bucketise, gather, read_resource_as_text, shasum, time_op
from ..utils import run_in_thread as t
from instawow.http import CACHE_INDEFINITELY, make_generic_progress_ctx
from instawow.manager_ctx import ManagerCtx
from instawow.utils import StrEnum, bucketise, gather, read_resource_as_text, shasum, time_op
from instawow.utils import run_in_thread as t

_LuaTable: TypeAlias = Mapping[str, '_LuaTable']
_Auras: TypeAlias = 'WeakAuras | Plateroos'
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions src/instawow_wa_updater/_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from __future__ import annotations

import instawow.plugins

from ._cli import wa_updater_command_group


@instawow.plugins.hookimpl
def instawow_add_commands():
return (wa_updater_command_group,)
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_wa_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from instawow.manager_ctx import ManagerCtx
from instawow.pkg_management import PkgManager
from instawow.pkg_models import Pkg
from instawow.wa_updater import WaCompanionBuilder, WeakAura, WeakAuras
from instawow_wa_updater._core import WaCompanionBuilder, WeakAura, WeakAuras


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion tests/test_wa_updater_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import pytest

from instawow.wa_updater._custom_slpp import ParseError, loads
from instawow_wa_updater._custom_slpp import ParseError, loads


def test_numbers():
Expand Down

0 comments on commit e9b3b44

Please sign in to comment.