speed up version command by checking if quiet is passed

This commit is contained in:
Nick Sweeting 2024-09-30 18:33:43 -07:00
parent 31ce490321
commit 51fe4c38c2
No known key found for this signature in database
2 changed files with 88 additions and 80 deletions

View file

@ -8,17 +8,17 @@ import argparse
from pathlib import Path from pathlib import Path
from typing import Optional, List, IO from typing import Optional, List, IO
from archivebox.misc.util import docstring # from archivebox.misc.util import docstring
from archivebox.config import DATA_DIR from archivebox.config import DATA_DIR, VERSION
from ..logging_util import SmartFormatter, reject_stdin from ..logging_util import SmartFormatter, reject_stdin
from ..main import version
@docstring(version.__doc__) # @docstring(version.__doc__)
def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None: def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional[str]=None) -> None:
"""Print the ArchiveBox version and dependency information"""
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog=__command__, prog=__command__,
description=version.__doc__, description="Print the ArchiveBox version and dependency information", # version.__doc__,
add_help=True, add_help=True,
formatter_class=SmartFormatter, formatter_class=SmartFormatter,
) )
@ -30,6 +30,13 @@ def main(args: Optional[List[str]]=None, stdin: Optional[IO]=None, pwd: Optional
command = parser.parse_args(args or ()) command = parser.parse_args(args or ())
reject_stdin(__command__, stdin) reject_stdin(__command__, stdin)
# for speed reasons, check if quiet flag was set and just return simple version immediately if so
if command.quiet:
print(VERSION)
return
# otherwise do big expensive import to get the full version
from ..main import version
version( version(
quiet=command.quiet, quiet=command.quiet,
out_dir=Path(pwd) if pwd else DATA_DIR, out_dir=Path(pwd) if pwd else DATA_DIR,

View file

@ -169,13 +169,14 @@ def version(quiet: bool=False,
"""Print the ArchiveBox version and dependency information""" """Print the ArchiveBox version and dependency information"""
from rich import print from rich import print
print(VERSION)
if quiet:
return
from plugins_auth.ldap.apps import LDAP_CONFIG from plugins_auth.ldap.apps import LDAP_CONFIG
from django.conf import settings from django.conf import settings
print(VERSION)
if not quiet:
# 0.7.1 # 0.7.1
# ArchiveBox v0.7.1+editable COMMIT_HASH=951bba5 BUILD_TIME=2023-12-17 16:46:05 1702860365 # ArchiveBox v0.7.1+editable COMMIT_HASH=951bba5 BUILD_TIME=2023-12-17 16:46:05 1702860365
# IN_DOCKER=False IN_QEMU=False ARCH=arm64 OS=Darwin PLATFORM=macOS-14.2-arm64-arm-64bit PYTHON=Cpython # IN_DOCKER=False IN_QEMU=False ARCH=arm64 OS=Darwin PLATFORM=macOS-14.2-arm64-arm-64bit PYTHON=Cpython