How to use the instawow.resolvers.Defn function in instawow

To help you get started, we’ve selected a few instawow examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github layday / instawow / tests / test_resolvers.py View on Github external
async def test_resolve_curse_deps(manager):
    if manager.config.is_classic:
        pytest.skip('no classic equivalent')

    defns = [Defn('curse', 'mechagon-rare-share', Strategies.default)]
    with_deps = await manager.resolve(defns, with_deps=True)
    assert ['mechagon-rare-share', 'rare-share'] == [d.slug for d in with_deps.values()]
github layday / instawow / tests / test_resolvers.py View on Github external
async def test_resolve_curse_simple_pkgs(manager, request, strategy):
    results = await manager.resolve(
        [
            Defn('curse', 'tomcats', strategy),
            Defn('curse', 'mythic-dungeon-tools', strategy),
            Defn('curse', 'classiccastbars', strategy),
            Defn('curse', 'elkbuffbars', strategy),
        ]
    )
    separate, retail_only, classic_only, flavour_explosion = results.values()

    assert isinstance(separate, Pkg)
    if manager.config.is_classic:
        if strategy is Strategies.any_flavour:
            assert 'classic' not in separate.version
            assert isinstance(retail_only, Pkg)
        else:
            assert 'classic' in separate.version
            assert (
                isinstance(retail_only, E.PkgFileUnavailable)
                and retail_only.message
                == f"no files compatible with classic using '{strategy.name}' strategy"
github layday / instawow / tests / test_matchers.py View on Github external
async def test_multiple_defns_per_addon_contained_in_results(manager, molinari, test_func):
    ((_, matches),) = await test_func(manager, get_folders(manager))
    assert {Defn('curse', '20338'), Defn('wowi', '13188')} == set(matches)
github layday / instawow / tests / test_search.py View on Github external
async def test_search_with_extra_spice(manager):
    results = await manager.search('AtlasLootClassic', limit=5)
    if manager.config.is_classic:
        assert Defn('curse', 'atlaslootclassic') in results
    else:
        assert Defn('curse', 'atlaslootclassic') not in results
github layday / instawow / instawow / resolvers.py View on Github external
    async def resolve(self, defns: List[Defn]) -> Dict[Defn, Any]:
        if self._files is None:
            from .manager import cache_json_response

            files = await cache_json_response(
                self.manager,
                self.list_api_url,
                3600,
                label=f'Synchronising {self.name} catalogue',
            )
            self._files = {i['UID']: i for i in files}

        ids_for_defns = {d: ''.join(takewhile(str.isdigit, d.name)) for d in defns}
        numeric_ids = {i for i in ids_for_defns.values() if i.isdigit()}

        url = self.details_api_url / f'{",".join(numeric_ids)}.json'
        async with self.web_client.get(url) as response:
github layday / instawow / instawow / cli.py View on Github external
def update(obj: M, addons: Sequence[Defn]):
    "Update installed add-ons."

    def report_filter(result: E.ManagerResult):
        # Hide package from output if up to date and ``update`` was invoked without args
        return cast(bool, addons) or not isinstance(result, E.PkgUpToDate)

    defns = addons or list(map(Defn.from_pkg, obj.m.db_session.query(models.Pkg).all()))
    results = obj.m.run(obj.m.update(defns))
    Report(results.items(), report_filter).generate_and_exit()
github layday / instawow / instawow / manager.py View on Github external
more than one level deep.  This is to avoid unnecessary
        complexity for something that I would never expect to
        encounter in the wild.
        """
        pkgs = list(filter(is_pkg, results))
        dep_defns = list(
            filterfalse(
                {(p.source, p.id) for p in pkgs}.__contains__,
                # Using a dict to maintain dep appearance order
                {(p.source, d.id): ... for p in pkgs for d in p.deps},
            )
        )
        if not dep_defns:
            return {}

        deps = await self.resolve(list(starmap(Defn, dep_defns)))
        pretty_deps = {d.with_name(r.slug) if is_pkg(r) else d: r for d, r in deps.items()}
        return pretty_deps
github layday / instawow / instawow / cli.py View on Github external
def format_deps(pkg: models.Pkg):
        deps = (Defn(pkg.source, d.id) for d in pkg.deps)
        deps = (d.with_name(getattr(obj.m.get_pkg(d), 'slug', d.name)) for d in deps)
        return map(str, deps)
github layday / instawow / instawow / cli.py View on Github external
defns = (parse_into_defn(manager, v, raise_invalid=raise_invalid) for v in value)
        return uniq(defns)

    parts: Tuple[str, str]
    delim = ':'
    any_source = '*'

    if delim not in value:
        if raise_invalid:
            raise click.BadParameter(value)

        parts = (any_source, value)
    else:
        maybe_parts = manager.pair_url(value)
        parts = maybe_parts or value.partition(delim)[::2]
    return Defn(*parts)