Automatically install all ArchiveBox dependencies and extras
(out_dir: Path=OUTPUT_DIR)
| 951 | |
| 952 | @enforce_types |
| 953 | def setup(out_dir: Path=OUTPUT_DIR) -> None: |
| 954 | """Automatically install all ArchiveBox dependencies and extras""" |
| 955 | |
| 956 | if not (out_dir / ARCHIVE_DIR_NAME).exists(): |
| 957 | run_subcommand('init', stdin=None, pwd=out_dir) |
| 958 | |
| 959 | setup_django(out_dir=out_dir, check_db=True) |
| 960 | from core.models import User |
| 961 | |
| 962 | if not User.objects.filter(is_superuser=True).exists(): |
| 963 | stderr('\n[+] Creating new admin user for the Web UI...', color='green') |
| 964 | run_subcommand('manage', subcommand_args=['createsuperuser'], pwd=out_dir) |
| 965 | |
| 966 | stderr('\n[+] Installing enabled ArchiveBox dependencies automatically...', color='green') |
| 967 | |
| 968 | stderr('\n Installing YOUTUBEDL_BINARY automatically using pip...') |
| 969 | if YOUTUBEDL_VERSION: |
| 970 | print(f'{YOUTUBEDL_VERSION} is already installed', YOUTUBEDL_BINARY) |
| 971 | else: |
| 972 | try: |
| 973 | run_shell([ |
| 974 | PYTHON_BINARY, '-m', 'pip', |
| 975 | 'install', |
| 976 | '--upgrade', |
| 977 | '--no-cache-dir', |
| 978 | '--no-warn-script-location', |
| 979 | 'youtube_dl', |
| 980 | ], capture_output=False, cwd=out_dir) |
| 981 | pkg_path = run_shell([ |
| 982 | PYTHON_BINARY, '-m', 'pip', |
| 983 | 'show', |
| 984 | 'youtube_dl', |
| 985 | ], capture_output=True, text=True, cwd=out_dir).stdout.decode().split('Location: ')[-1].split('\n', 1)[0] |
| 986 | NEW_YOUTUBEDL_BINARY = Path(pkg_path) / 'youtube_dl' / '__main__.py' |
| 987 | os.chmod(NEW_YOUTUBEDL_BINARY, 0o777) |
| 988 | assert NEW_YOUTUBEDL_BINARY.exists(), f'youtube_dl must exist inside {pkg_path}' |
| 989 | config(f'YOUTUBEDL_BINARY={NEW_YOUTUBEDL_BINARY}', set=True, out_dir=out_dir) |
| 990 | except BaseException as e: # lgtm [py/catch-base-exception] |
| 991 | stderr(f'[X] Failed to install python packages: {e}', color='red') |
| 992 | raise SystemExit(1) |
| 993 | |
| 994 | if platform.machine() == 'armv7l': |
| 995 | stderr('\n Skip the automatic installation of CHROME_BINARY because playwright is not available on armv7.') |
| 996 | else: |
| 997 | stderr('\n Installing CHROME_BINARY automatically using playwright...') |
| 998 | if CHROME_VERSION: |
| 999 | print(f'{CHROME_VERSION} is already installed', CHROME_BINARY) |
| 1000 | else: |
| 1001 | try: |
| 1002 | run_shell([ |
| 1003 | PYTHON_BINARY, '-m', 'pip', |
| 1004 | 'install', |
| 1005 | '--upgrade', |
| 1006 | '--no-cache-dir', |
| 1007 | '--no-warn-script-location', |
| 1008 | 'playwright', |
| 1009 | ], capture_output=False, cwd=out_dir) |
| 1010 | run_shell([PYTHON_BINARY, '-m', 'playwright', 'install', 'chromium'], capture_output=False, cwd=out_dir) |
no test coverage detected