fix LIB_NPM provider loading and euid

This commit is contained in:
Nick Sweeting 2024-10-09 03:19:31 -07:00
parent 861b9cd16f
commit f4f9ae2f28
No known key found for this signature in database
4 changed files with 10 additions and 9 deletions

View file

@ -2,7 +2,6 @@ __package__ = 'plugins_extractor.mercury'
from typing import List, Optional, Dict
from pathlib import Path
from subprocess import run
from pydantic import InstanceOf, Field
from pydantic_pkgr import BinProvider, BinName, BinProviderName, ProviderLookupDict, bin_abspath
@ -42,11 +41,10 @@ class MercuryBinary(BaseBinary):
provider_overrides: Dict[BinProviderName, ProviderLookupDict] = {
LIB_NPM_BINPROVIDER.name: {
'packages': lambda: ['@postlight/parser@^2.2.3'],
'version': lambda: run([str(LIB_NPM_BINPROVIDER.INSTALLER_BIN_ABSPATH), f'--prefix={LIB_NPM_BINPROVIDER.npm_prefix}', 'info', '@postlight/parser', 'version'], text=True, capture_output=True).stdout.strip(),
},
SYS_NPM_BINPROVIDER.name: {
'packages': lambda: [], # never try to install things globally
'version': lambda: run([str(SYS_NPM_BINPROVIDER.INSTALLER_BIN_ABSPATH), '-g', 'info', '@postlight/parser', 'version'], text=True, capture_output=True).stdout.strip(),
'packages': lambda: ['@postlight/parser@^2.2.3'],
'install': lambda: False, # never try to install things into global prefix
},
env.name: {
'version': lambda: '999.999.999' if bin_abspath('postlight-parser', PATH=env.PATH) else None,

View file

@ -35,12 +35,12 @@ NPM_CONFIG = NpmDependencyConfigs(**DEFAULT_GLOBAL_CONFIG)
OLD_NODE_BIN_PATH = DATA_DIR / 'node_modules' / '.bin'
NEW_NODE_BIN_PATH = CONSTANTS.LIB_NPM_DIR / 'node_modules' / '.bin'
class SystemNpmProvider(NpmProvider, BaseBinProvider):
class SystemNpmBinProvider(NpmProvider, BaseBinProvider):
name: BinProviderName = "sys_npm"
npm_prefix: Optional[Path] = None
class LibNpmProvider(NpmProvider, BaseBinProvider):
class LibNpmBinProvider(NpmProvider, BaseBinProvider):
name: BinProviderName = "lib_npm"
PATH: PATHStr = f'{NEW_NODE_BIN_PATH}:{OLD_NODE_BIN_PATH}'
@ -52,8 +52,8 @@ class LibNpmProvider(NpmProvider, BaseBinProvider):
return self
SYS_NPM_BINPROVIDER = SystemNpmProvider()
LIB_NPM_BINPROVIDER = LibNpmProvider()
SYS_NPM_BINPROVIDER = SystemNpmBinProvider()
LIB_NPM_BINPROVIDER = LibNpmBinProvider()
npm = LIB_NPM_BINPROVIDER
class NodeBinary(BaseBinary):

View file

@ -17,6 +17,7 @@ from pydantic_pkgr import (
)
from archivebox.config import CONSTANTS
from archivebox.config.permissions import ARCHIVEBOX_USER
# Depends on other Django apps:
from abx.archivebox.base_plugin import BasePlugin
@ -60,6 +61,8 @@ class PuppeteerBinProvider(BaseBinProvider):
INSTALLER_BIN: BinName = "npx"
PATH: PATHStr = str(CONSTANTS.LIB_BIN_DIR)
euid: Optional[int] = ARCHIVEBOX_USER
puppeteer_browsers_dir: Optional[Path] = LIB_DIR_BROWSERS
puppeteer_install_args: List[str] = ["@puppeteer/browsers", "install", "--path", str(LIB_DIR_BROWSERS)]

@ -1 +1 @@
Subproject commit 830b3738f49109a05c8068df12f1e2167901953f
Subproject commit ec4c2d5f5a034ea6c10a5337c3115fbe1504f52b