| 1 |
#!/usr/bin/env python3 |
| 2 |
import argparse |
| 3 |
import os |
| 4 |
from typing import Any, List, Optional, Text, TYPE_CHECKING |
| 5 |
|
| 6 |
from . import manifest |
| 7 |
from . import vcs |
| 8 |
from .log import get_logger, enable_debug_logging |
| 9 |
from .download import download_from_github |
| 10 |
if TYPE_CHECKING: |
| 11 |
from .manifest import Manifest # avoid cyclic import |
| 12 |
|
| 13 |
|
| 14 |
here = os.path.dirname(__file__) |
| 15 |
|
| 16 |
wpt_root = os.path.abspath(os.path.join(here, os.pardir, os.pardir)) |
| 17 |
|
| 18 |
logger = get_logger() |
| 19 |
|
| 20 |
|
| 21 |
def update(tests_root: str, |
| 22 |
manifest: "Manifest", |
| 23 |
manifest_path: Optional[str] = None, |
| 24 |
working_copy: bool = True, |
| 25 |
cache_root: Optional[str] = None, |
| 26 |
paths_to_update: Optional[List[Text]] = None, |
| 27 |
rebuild: bool = False, |
| 28 |
parallel: bool = True |
| 29 |
) -> bool: |
| 30 |
logger.warning("Deprecated; use manifest.load_and_update instead") |
| 31 |
logger.info("Updating manifest") |
| 32 |
|
| 33 |
tree = vcs.get_tree(tests_root, manifest, manifest_path, cache_root, |
| 34 |
paths_to_update, working_copy, rebuild) |
| 35 |
return manifest.update(tree, parallel) |
| 36 |
|
| 37 |
|
| 38 |
def update_from_cli(**kwargs: Any) -> None: |
| 39 |
tests_root = kwargs["tests_root"] |
| 40 |
path = kwargs["path"] |
| 41 |
assert tests_root is not None |
| 42 |
|
| 43 |
if not kwargs["rebuild"] and kwargs["download"]: |
| 44 |
download_from_github(path, tests_root) |
| 45 |
|
| 46 |
paths_to_update = [] |
| 47 |
for path_to_update in kwargs["tests"]: |
| 48 |
if path_to_update.startswith(tests_root): |
| 49 |
paths_to_update.append(os.path.relpath(path_to_update, tests_root)) |
| 50 |
else: |
| 51 |
logger.warning(f"{path_to_update} is not a WPT path") |
| 52 |
|
| 53 |
manifest.load_and_update(tests_root, |
| 54 |
path, |
| 55 |
kwargs["url_base"], |
| 56 |
paths_to_update=paths_to_update, |
| 57 |
update=True, |
| 58 |
rebuild=kwargs["rebuild"], |
| 59 |
cache_root=kwargs["cache_root"], |
| 60 |
parallel=kwargs["parallel"]) |
| 61 |
|
| 62 |
|
| 63 |
def abs_path(path: str) -> str: |
| 64 |
return os.path.abspath(os.path.expanduser(path)) |
| 65 |
|
| 66 |
|
| 67 |
def create_parser() -> argparse.ArgumentParser: |
| 68 |
parser = argparse.ArgumentParser() |
| 69 |
parser.add_argument( |
| 70 |
"-v", "--verbose", action="store_true", |
| 71 |
help="Turn on verbose logging") |
| 72 |
parser.add_argument( |
| 73 |
"-p", "--path", type=abs_path, help="Path to manifest file.") |
| 74 |
parser.add_argument( |
| 75 |
"--tests-root", type=abs_path, default=wpt_root, help="Path to root of tests.") |
| 76 |
parser.add_argument( |
| 77 |
"-r", "--rebuild", action="store_true", |
| 78 |
help="Force a full rebuild of the manifest.") |
| 79 |
parser.add_argument( |
| 80 |
"--url-base", default="/", |
| 81 |
help="Base url to use as the mount point for tests in this manifest.") |
| 82 |
parser.add_argument( |
| 83 |
"--no-download", dest="download", action="store_false", |
| 84 |
help="Never attempt to download the manifest.") |
| 85 |
parser.add_argument( |
| 86 |
"--cache-root", default=os.path.join(wpt_root, ".wptcache"), |
| 87 |
help="Path in which to store any caches (default <tests_root>/.wptcache/)") |
| 88 |
parser.add_argument( |
| 89 |
"--no-parallel", dest="parallel", action="store_false", |
| 90 |
help="Do not parallelize building the manifest") |
| 91 |
parser.add_argument('tests', |
| 92 |
type=abs_path, |
| 93 |
nargs='*', |
| 94 |
help=('Test files or directories to update. ' |
| 95 |
'Omit to update all items under the test root.')) |
| 96 |
return parser |
| 97 |
|
| 98 |
|
| 99 |
def run(*args: Any, **kwargs: Any) -> None: |
| 100 |
if kwargs["path"] is None: |
| 101 |
kwargs["path"] = os.path.join(kwargs["tests_root"], "MANIFEST.json") |
| 102 |
if kwargs["verbose"]: |
| 103 |
enable_debug_logging() |
| 104 |
update_from_cli(**kwargs) |
| 105 |
|
| 106 |
|
| 107 |
def main() -> None: |
| 108 |
opts = create_parser().parse_args() |
| 109 |
|
| 110 |
run(**vars(opts)) |