mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
reckless: simplify installer registration
Fixes a bug in installer registration where executable is evaluated before entrypoints and other details are added. ***RECKLESS STDERR*** Traceback (most recent call last): File lightning/tools/reckless, line 382, in <module> INSTALLERS['nodejs'].add_entrypoint('{name}') KeyError: 'nodejs' Reported by @ksedgwic Changelog-None
This commit is contained in:
parent
15795c969a
commit
8163bfc7bd
1 changed files with 20 additions and 28 deletions
|
@ -35,8 +35,7 @@ def unsupported_entry(name) -> list:
|
||||||
|
|
||||||
def entry_guesses(name: str) -> list:
|
def entry_guesses(name: str) -> list:
|
||||||
guesses = []
|
guesses = []
|
||||||
global INSTALLERS
|
for inst in INSTALLERS:
|
||||||
for iname, inst in INSTALLERS.items():
|
|
||||||
for entry in inst.entries:
|
for entry in inst.entries:
|
||||||
guesses.append(entry.format(name=name))
|
guesses.append(entry.format(name=name))
|
||||||
return guesses
|
return guesses
|
||||||
|
@ -62,11 +61,6 @@ class Installer:
|
||||||
self.manager = manager # dependency manager (if required)
|
self.manager = manager # dependency manager (if required)
|
||||||
self.dependency_file = None
|
self.dependency_file = None
|
||||||
self.dependency_call = None
|
self.dependency_call = None
|
||||||
if self.executable():
|
|
||||||
global INSTALLERS
|
|
||||||
if not INSTALLERS:
|
|
||||||
INSTALLERS = {}
|
|
||||||
INSTALLERS[self.name] = self
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return (f'<Installer {self.name}: mimetype: {self.mimetype}, '
|
return (f'<Installer {self.name}: mimetype: {self.mimetype}, '
|
||||||
|
@ -157,7 +151,7 @@ class InstInfo:
|
||||||
# FIXME: This should be easier to implement
|
# FIXME: This should be easier to implement
|
||||||
print(f'entrypoint {g} is not yet supported')
|
print(f'entrypoint {g} is not yet supported')
|
||||||
return False
|
return False
|
||||||
for name, inst in INSTALLERS.items():
|
for inst in INSTALLERS:
|
||||||
# FIXME: Allow multiple depencencies
|
# FIXME: Allow multiple depencencies
|
||||||
for f in tree:
|
for f in tree:
|
||||||
if f['path'] == inst.dependency_file:
|
if f['path'] == inst.dependency_file:
|
||||||
|
@ -334,7 +328,7 @@ class InferInstall():
|
||||||
def match_name(name) -> str:
|
def match_name(name) -> str:
|
||||||
for tier in range(0, 10):
|
for tier in range(0, 10):
|
||||||
# Look for each installers preferred entrypoint format first
|
# Look for each installers preferred entrypoint format first
|
||||||
for n, inst in INSTALLERS.items():
|
for inst in INSTALLERS:
|
||||||
fmt = inst.entries[tier]
|
fmt = inst.entries[tier]
|
||||||
if '{name}' in fmt:
|
if '{name}' in fmt:
|
||||||
pre = fmt.split('{name}')[0]
|
pre = fmt.split('{name}')[0]
|
||||||
|
@ -362,27 +356,25 @@ class InferInstall():
|
||||||
raise Exception(f'plugin entrypoint not found in {self.dir}')
|
raise Exception(f'plugin entrypoint not found in {self.dir}')
|
||||||
|
|
||||||
|
|
||||||
INSTALLERS = {}
|
python3pip = Installer('python3pip', 'text/x-python', exe='python3',
|
||||||
Installer('python3pip', 'text/x-python', exe='python3',
|
|
||||||
manager='pip', entry='{name}.py')
|
manager='pip', entry='{name}.py')
|
||||||
INSTALLERS['python3pip'].add_entrypoint('{name}')
|
python3pip.add_entrypoint('{name}')
|
||||||
INSTALLERS['python3pip'].add_entrypoint('__init__.py')
|
python3pip.add_entrypoint('__init__.py')
|
||||||
INSTALLERS['python3pip'].add_dependency_file('requirements.txt')
|
python3pip.add_dependency_file('requirements.txt')
|
||||||
INSTALLERS['python3pip'].add_dependency_call(['pip', 'install', '-r',
|
python3pip.add_dependency_call(['pip', 'install', '-r', 'requirements.txt'])
|
||||||
'requirements.txt'])
|
|
||||||
|
|
||||||
INSTALLERS['python3pip3'] = INSTALLERS['python3pip'].copy()
|
python3pip3 = python3pip.copy()
|
||||||
INSTALLERS['python3pip3'].manager = 'pip3'
|
python3pip3.manager = 'pip3'
|
||||||
INSTALLERS['python3pip3'].dependency_call = [['pip3', 'install', '-r',
|
python3pip3.dependency_call = [['pip3', 'install', '-r', 'requirements.txt']]
|
||||||
'requirements.txt']]
|
|
||||||
|
|
||||||
# Nodejs plugin installer
|
# Nodejs plugin installer
|
||||||
Installer('nodejs', 'application/javascript', exe='node', manager='npm',
|
nodejs = Installer('nodejs', 'application/javascript', exe='node',
|
||||||
entry='{name}.js')
|
manager='npm', entry='{name}.js')
|
||||||
INSTALLERS['nodejs'].add_entrypoint('{name}')
|
nodejs.add_entrypoint('{name}')
|
||||||
INSTALLERS['nodejs'].add_dependency_call(['npm', 'install', '--omit=dev'])
|
nodejs.add_dependency_call(['npm', 'install', '--omit=dev'])
|
||||||
INSTALLERS['nodejs'].add_dependency_file('package.json')
|
nodejs.add_dependency_file('package.json')
|
||||||
|
|
||||||
|
INSTALLERS = {python3pip, python3pip3, nodejs}
|
||||||
|
|
||||||
def help_alias(targets: list):
|
def help_alias(targets: list):
|
||||||
if len(targets) == 0:
|
if len(targets) == 0:
|
||||||
|
@ -495,13 +487,13 @@ def _install_plugin(src: InstInfo) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Find a suitable installer
|
# Find a suitable installer
|
||||||
for name, inst_method in INSTALLERS.items():
|
for inst_method in INSTALLERS:
|
||||||
if not (inst_method.installable() and inst_method.executable()):
|
if not (inst_method.installable() and inst_method.executable()):
|
||||||
continue
|
continue
|
||||||
if inst_method.dependency_file is not None:
|
if inst_method.dependency_file is not None:
|
||||||
if inst_method.dependency_file not in os.listdir(plugin_path):
|
if inst_method.dependency_file not in os.listdir(plugin_path):
|
||||||
continue
|
continue
|
||||||
logging.debug(f"using installer {name}")
|
logging.debug(f"using installer {inst_method.name}")
|
||||||
INSTALLER = inst_method
|
INSTALLER = inst_method
|
||||||
break
|
break
|
||||||
# try it out
|
# try it out
|
||||||
|
|
Loading…
Add table
Reference in a new issue