mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
support per source plugin configuration and support different registry for the npm source
This commit is contained in:
parent
121b94a7eb
commit
cd1cbfde30
6 changed files with 41 additions and 3 deletions
|
@ -79,3 +79,18 @@ put results in :attr:`result_q <nvchecker.api.BaseWorker.result_q>`. See
|
||||||
``nvchecker_source/aur.py`` for a complete, batching example.
|
``nvchecker_source/aur.py`` for a complete, batching example.
|
||||||
|
|
||||||
For details about these objects, see :mod:`the API documentation <nvchecker.api>`.
|
For details about these objects, see :mod:`the API documentation <nvchecker.api>`.
|
||||||
|
|
||||||
|
You can also receive a configuration section from the configuration as
|
||||||
|
``__config__.source.SOURCE_NAME``, where ``SOURCE_None`` is what your plugin is
|
||||||
|
called. This can be used to specify a mirror site for your plugin to use, e.g.
|
||||||
|
the ``npm`` plugin accepts the following config::
|
||||||
|
|
||||||
|
[__config__.source.npm]
|
||||||
|
registry = "https://registry.npm.taobao.org"
|
||||||
|
|
||||||
|
When such a configuration exists for your plugin, you need to define a function
|
||||||
|
named ``configure`` to receive it::
|
||||||
|
|
||||||
|
def configure(config):
|
||||||
|
'''use the "config" dict in some way'''
|
||||||
|
...
|
||||||
|
|
|
@ -446,6 +446,12 @@ Check `NPM Registry <https://registry.npmjs.org/>`_ for updates.
|
||||||
npm
|
npm
|
||||||
The name used on NPM Registry, e.g. ``coffee-script``.
|
The name used on NPM Registry, e.g. ``coffee-script``.
|
||||||
|
|
||||||
|
To configure which registry to query, a source plugin option is available.
|
||||||
|
You can specify like this::
|
||||||
|
|
||||||
|
[__config__.source.npm]
|
||||||
|
registry = "https://registry.npm.taobao.org"
|
||||||
|
|
||||||
Check Hackage
|
Check Hackage
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
::
|
::
|
||||||
|
|
|
@ -50,6 +50,7 @@ def main() -> None:
|
||||||
futures = core.dispatch(
|
futures = core.dispatch(
|
||||||
entries, task_sem, result_q,
|
entries, task_sem, result_q,
|
||||||
keymanager, args.tries,
|
keymanager, args.tries,
|
||||||
|
options.source_configs,
|
||||||
)
|
)
|
||||||
except ModuleNotFoundError as e:
|
except ModuleNotFoundError as e:
|
||||||
sys.exit(f'Error: {e}')
|
sys.exit(f'Error: {e}')
|
||||||
|
|
|
@ -11,7 +11,7 @@ import logging
|
||||||
import argparse
|
import argparse
|
||||||
from typing import (
|
from typing import (
|
||||||
Tuple, NamedTuple, Optional, List, Union,
|
Tuple, NamedTuple, Optional, List, Union,
|
||||||
cast, Dict, Awaitable, Sequence,
|
cast, Dict, Awaitable, Sequence, Any,
|
||||||
)
|
)
|
||||||
import types
|
import types
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -139,6 +139,7 @@ class Options(NamedTuple):
|
||||||
max_concurrency: int
|
max_concurrency: int
|
||||||
proxy: Optional[str]
|
proxy: Optional[str]
|
||||||
keymanager: KeyManager
|
keymanager: KeyManager
|
||||||
|
source_configs: Dict[str, Dict[str, Any]]
|
||||||
|
|
||||||
class FileLoadError(Exception):
|
class FileLoadError(Exception):
|
||||||
def __init__(self, kind, exc):
|
def __init__(self, kind, exc):
|
||||||
|
@ -159,6 +160,7 @@ def load_file(
|
||||||
|
|
||||||
ver_files: Optional[Tuple[Path, Path]] = None
|
ver_files: Optional[Tuple[Path, Path]] = None
|
||||||
keymanager = KeyManager(None)
|
keymanager = KeyManager(None)
|
||||||
|
source_configs = {}
|
||||||
|
|
||||||
if '__config__' in config:
|
if '__config__' in config:
|
||||||
c = config.pop('__config__')
|
c = config.pop('__config__')
|
||||||
|
@ -184,6 +186,9 @@ def load_file(
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise FileLoadError('keyfile', e)
|
raise FileLoadError('keyfile', e)
|
||||||
|
|
||||||
|
if 'source' in c:
|
||||||
|
source_configs = c['source']
|
||||||
|
|
||||||
max_concurrency = c.get('max_concurrency', 20)
|
max_concurrency = c.get('max_concurrency', 20)
|
||||||
proxy = c.get('proxy')
|
proxy = c.get('proxy')
|
||||||
else:
|
else:
|
||||||
|
@ -191,7 +196,9 @@ def load_file(
|
||||||
proxy = None
|
proxy = None
|
||||||
|
|
||||||
return cast(Entries, config), Options(
|
return cast(Entries, config), Options(
|
||||||
ver_files, max_concurrency, proxy, keymanager)
|
ver_files, max_concurrency, proxy, keymanager,
|
||||||
|
source_configs,
|
||||||
|
)
|
||||||
|
|
||||||
def dispatch(
|
def dispatch(
|
||||||
entries: Entries,
|
entries: Entries,
|
||||||
|
@ -199,6 +206,7 @@ def dispatch(
|
||||||
result_q: Queue[RawResult],
|
result_q: Queue[RawResult],
|
||||||
keymanager: KeyManager,
|
keymanager: KeyManager,
|
||||||
tries: int,
|
tries: int,
|
||||||
|
source_configs: Dict[str, Dict[str, Any]],
|
||||||
) -> List[asyncio.Future]:
|
) -> List[asyncio.Future]:
|
||||||
mods: Dict[str, Tuple[types.ModuleType, List]] = {}
|
mods: Dict[str, Tuple[types.ModuleType, List]] = {}
|
||||||
ctx_tries.set(tries)
|
ctx_tries.set(tries)
|
||||||
|
@ -210,6 +218,9 @@ def dispatch(
|
||||||
mod = import_module('nvchecker_source.' + source)
|
mod = import_module('nvchecker_source.' + source)
|
||||||
tasks: List[Tuple[str, Entry]] = []
|
tasks: List[Tuple[str, Entry]] = []
|
||||||
mods[source] = mod, tasks
|
mods[source] = mod, tasks
|
||||||
|
config = source_configs.get(source)
|
||||||
|
if config and getattr(mod, 'configure'):
|
||||||
|
mod.configure(config) # type: ignore
|
||||||
else:
|
else:
|
||||||
tasks = mods[source][1]
|
tasks = mods[source][1]
|
||||||
tasks.append((name, entry))
|
tasks.append((name, entry))
|
||||||
|
|
|
@ -7,6 +7,11 @@ from nvchecker.api import session
|
||||||
|
|
||||||
NPM_URL = 'https://registry.npmjs.org/%s'
|
NPM_URL = 'https://registry.npmjs.org/%s'
|
||||||
|
|
||||||
|
def configure(config):
|
||||||
|
global NPM_URL
|
||||||
|
if url := config.get('registry'):
|
||||||
|
NPM_URL = f'{url.rstrip("/")}/%s'
|
||||||
|
|
||||||
async def get_first_1k(url):
|
async def get_first_1k(url):
|
||||||
headers = {
|
headers = {
|
||||||
"Accept": "application/vnd.npm.install-v1+json",
|
"Accept": "application/vnd.npm.install-v1+json",
|
||||||
|
|
|
@ -29,7 +29,7 @@ async def run(
|
||||||
|
|
||||||
futures = core.dispatch(
|
futures = core.dispatch(
|
||||||
entries, task_sem, result_q,
|
entries, task_sem, result_q,
|
||||||
keymanager, 1,
|
keymanager, 1, {},
|
||||||
)
|
)
|
||||||
|
|
||||||
oldvers: VersData = {}
|
oldvers: VersData = {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue