From 226e26852cbadb3b0715787c352f48949401ca3a Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Sat, 24 Apr 2021 03:28:49 -0400 Subject: [PATCH] dont try to autodetect whether node, chrome, etc are needed during setup --- archivebox/main.py | 173 ++++++++++++++++++++++----------------------- 1 file changed, 85 insertions(+), 88 deletions(-) diff --git a/archivebox/main.py b/archivebox/main.py index 373c8040..4214e205 100755 --- a/archivebox/main.py +++ b/archivebox/main.py @@ -915,97 +915,94 @@ def setup(out_dir: Path=OUTPUT_DIR) -> None: stderr('\n[+] Installing enabled ArchiveBox dependencies automatically...', color='green') stderr('\n Installing YOUTUBEDL_BINARY automatically using pip...') - if USE_YOUTUBEDL: - if YOUTUBEDL_VERSION: - print(f'{YOUTUBEDL_VERSION} is already installed', YOUTUBEDL_BINARY) - else: - try: - run_shell([ - PYTHON_BINARY, '-m', 'pip', - 'install', - '--upgrade', - '--no-cache-dir', - '--no-warn-script-location', - 'youtube_dl', - ], capture_output=False, cwd=out_dir) - pkg_path = run_shell([ - PYTHON_BINARY, '-m', 'pip', - 'show', - 'youtube_dl', - ], capture_output=True, text=True, cwd=out_dir).stdout.split('Location: ')[-1].split('\n', 1)[0] - NEW_YOUTUBEDL_BINARY = Path(pkg_path) / 'youtube_dl' / '__main__.py' - os.chmod(NEW_YOUTUBEDL_BINARY, 0o777) - assert NEW_YOUTUBEDL_BINARY.exists(), f'youtube_dl must exist inside {pkg_path}' - config(f'YOUTUBEDL_BINARY={NEW_YOUTUBEDL_BINARY}', set=True, out_dir=out_dir) - except BaseException as e: - stderr(f'[X] Failed to install python packages: {e}', color='red') - raise SystemExit(1) - - stderr('\n Installing CHROME_BINARY automatically using playwright...') - if USE_CHROME: - if CHROME_VERSION: - print(f'{CHROME_VERSION} is already installed', CHROME_BINARY) - else: - try: - run_shell([ - PYTHON_BINARY, '-m', 'pip', - 'install', - '--upgrade', - '--no-cache-dir', - '--no-warn-script-location', - 'playwright', - ], capture_output=False, cwd=out_dir) - run_shell([PYTHON_BINARY, '-m', 'playwright', 'install', 'chromium'], capture_output=False, cwd=out_dir) - proc = run_shell([PYTHON_BINARY, '-c', 'from playwright.sync_api import sync_playwright; print(sync_playwright().start().chromium.executable_path)'], capture_output=True, text=True, cwd=out_dir) - NEW_CHROME_BINARY = proc.stdout.decode().strip() if isinstance(proc.stdout, bytes) else proc.stdout.strip() - assert NEW_CHROME_BINARY and len(NEW_CHROME_BINARY), 'CHROME_BINARY must contain a path' - config(f'CHROME_BINARY={NEW_CHROME_BINARY}', set=True, out_dir=out_dir) - except BaseException as e: - stderr(f'[X] Failed to install chromium using playwright: {e.__class__.__name__} {e}', color='red') - raise SystemExit(1) - - stderr('\n Installing SINGLEFILE_BINARY, READABILITY_BINARY, MERCURY_BINARY automatically using npm...') - if USE_NODE: - if not NODE_VERSION: - stderr('[X] You must first install node using your system package manager', color='red') - hint([ - 'curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -', - 'or to disable all node-based modules run: archivebox config --set USE_NODE=False', - ]) + if YOUTUBEDL_VERSION: + print(f'{YOUTUBEDL_VERSION} is already installed', YOUTUBEDL_BINARY) + else: + try: + run_shell([ + PYTHON_BINARY, '-m', 'pip', + 'install', + '--upgrade', + '--no-cache-dir', + '--no-warn-script-location', + 'youtube_dl', + ], capture_output=False, cwd=out_dir) + pkg_path = run_shell([ + PYTHON_BINARY, '-m', 'pip', + 'show', + 'youtube_dl', + ], capture_output=True, text=True, cwd=out_dir).stdout.split('Location: ')[-1].split('\n', 1)[0] + NEW_YOUTUBEDL_BINARY = Path(pkg_path) / 'youtube_dl' / '__main__.py' + os.chmod(NEW_YOUTUBEDL_BINARY, 0o777) + assert NEW_YOUTUBEDL_BINARY.exists(), f'youtube_dl must exist inside {pkg_path}' + config(f'YOUTUBEDL_BINARY={NEW_YOUTUBEDL_BINARY}', set=True, out_dir=out_dir) + except BaseException as e: + stderr(f'[X] Failed to install python packages: {e}', color='red') raise SystemExit(1) - if all((SINGLEFILE_VERSION, READABILITY_VERSION, MERCURY_VERSION)): - print('SINGLEFILE_BINARY, READABILITY_BINARY, and MERCURURY_BINARY are already installed') - else: - try: - # clear out old npm package locations - paths = ( - out_dir / 'package.json', - out_dir / 'package_lock.json', - out_dir / 'node_modules', - ) - for path in paths: - if path.is_dir(): - shutil.rmtree(path, ignore_errors=True) - elif path.is_file(): - os.remove(path) + stderr('\n Installing CHROME_BINARY automatically using playwright...') + if CHROME_VERSION: + print(f'{CHROME_VERSION} is already installed', CHROME_BINARY) + else: + try: + run_shell([ + PYTHON_BINARY, '-m', 'pip', + 'install', + '--upgrade', + '--no-cache-dir', + '--no-warn-script-location', + 'playwright', + ], capture_output=False, cwd=out_dir) + run_shell([PYTHON_BINARY, '-m', 'playwright', 'install', 'chromium'], capture_output=False, cwd=out_dir) + proc = run_shell([PYTHON_BINARY, '-c', 'from playwright.sync_api import sync_playwright; print(sync_playwright().start().chromium.executable_path)'], capture_output=True, text=True, cwd=out_dir) + NEW_CHROME_BINARY = proc.stdout.decode().strip() if isinstance(proc.stdout, bytes) else proc.stdout.strip() + assert NEW_CHROME_BINARY and len(NEW_CHROME_BINARY), 'CHROME_BINARY must contain a path' + config(f'CHROME_BINARY={NEW_CHROME_BINARY}', set=True, out_dir=out_dir) + except BaseException as e: + stderr(f'[X] Failed to install chromium using playwright: {e.__class__.__name__} {e}', color='red') + raise SystemExit(1) - shutil.copyfile(PACKAGE_DIR / 'package.json', out_dir / 'package.json') - run_shell([ - 'npm', - 'install', - '--prefix', str(out_dir), - '--force', - '--no-save', - '--no-audit', - '--no-fund', - '--loglevel', 'error', - ], capture_output=False, cwd=out_dir) - os.remove(out_dir / 'package.json') - except BaseException as e: - stderr(f'[X] Failed to install npm packages: {e}', color='red') - hint(f'Try deleting {out_dir}/node_modules and running it again') - raise SystemExit(1) + stderr('\n Installing SINGLEFILE_BINARY, READABILITY_BINARY, MERCURY_BINARY automatically using npm...') + if not NODE_VERSION: + stderr('[X] You must first install node using your system package manager', color='red') + hint([ + 'curl -sL https://deb.nodesource.com/setup_15.x | sudo -E bash -', + 'or to disable all node-based modules run: archivebox config --set USE_NODE=False', + ]) + raise SystemExit(1) + + if all((SINGLEFILE_VERSION, READABILITY_VERSION, MERCURY_VERSION)): + print('SINGLEFILE_BINARY, READABILITY_BINARY, and MERCURURY_BINARY are already installed') + else: + try: + # clear out old npm package locations + paths = ( + out_dir / 'package.json', + out_dir / 'package_lock.json', + out_dir / 'node_modules', + ) + for path in paths: + if path.is_dir(): + shutil.rmtree(path, ignore_errors=True) + elif path.is_file(): + os.remove(path) + + shutil.copyfile(PACKAGE_DIR / 'package.json', out_dir / 'package.json') + run_shell([ + 'npm', + 'install', + '--prefix', str(out_dir), + '--force', + '--no-save', + '--no-audit', + '--no-fund', + '--loglevel', 'error', + ], capture_output=False, cwd=out_dir) + os.remove(out_dir / 'package.json') + except BaseException as e: + stderr(f'[X] Failed to install npm packages: {e}', color='red') + hint(f'Try deleting {out_dir}/node_modules and running it again') + raise SystemExit(1) stderr('\n[√] Set up ArchiveBox and its dependencies successfully.', color='green')