Datasets:
tools: unify wrappers and optimize fetch/metadata scripts
Browse files- ADDING_NEW_UD_VERSION.md +4 -1
- tools/00_fetch_ud_codes_and_flags.sh +64 -23
- tools/02_generate_metadata.py +5 -7
- tools/03_generate_README.py +1 -1
- tools/04_generate_parquet.py +14 -28
- tools/05_validate_parquet.py +14 -36
- tools/README.md +2 -1
- tools/_ud_hfp_wrapper.py +70 -0
ADDING_NEW_UD_VERSION.md
CHANGED
|
@@ -99,9 +99,12 @@ cat .env
|
|
| 99 |
|
| 100 |
# This creates:
|
| 101 |
# - etc/codes_and_flags-2.18.yaml
|
| 102 |
-
# - etc/codes_and_flags-latest.yaml
|
| 103 |
```
|
| 104 |
|
|
|
|
|
|
|
|
|
|
| 105 |
**Before running**, update the script with the docs-automation commit hash:
|
| 106 |
|
| 107 |
1. Open `00_fetch_ud_codes_and_flags.sh`
|
|
|
|
| 99 |
|
| 100 |
# This creates:
|
| 101 |
# - etc/codes_and_flags-2.18.yaml
|
| 102 |
+
# - etc/codes_and_flags-latest.yaml
|
| 103 |
```
|
| 104 |
|
| 105 |
+
By default, the script fetches the configured `UD_VER` and `latest`.
|
| 106 |
+
Use `--all` only when you want to refresh all mapped versions.
|
| 107 |
+
|
| 108 |
**Before running**, update the script with the docs-automation commit hash:
|
| 109 |
|
| 110 |
1. Open `00_fetch_ud_codes_and_flags.sh`
|
tools/00_fetch_ud_codes_and_flags.sh
CHANGED
|
@@ -1,6 +1,14 @@
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
#
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# This is a manual mapping of versions of codes_and_flags.yaml from:
|
| 5 |
# * https://github.com/UniversalDependencies/docs-automation/commits/master/codes_and_flags.yaml
|
| 6 |
# (identified by commit hash) matched to the closest date of UD versions from:
|
|
@@ -25,8 +33,8 @@ VER_MAPPING["latest"]="e3847a587baa2a5a7345049b8b2c109ad2162c21"
|
|
| 25 |
# USAGE
|
| 26 |
#
|
| 27 |
usage() { OUTPUT=${1:-"verbose"}
|
| 28 |
-
echo "Usage: $0 [-o]" >&2
|
| 29 |
-
[ $OUTPUT = "short" ] && exit 0
|
| 30 |
>&2 cat << EOF
|
| 31 |
|
| 32 |
Download versions of
|
|
@@ -44,6 +52,8 @@ German:
|
|
| 44 |
Options:
|
| 45 |
-h Print this help message
|
| 46 |
-o|--online Enable online mode: (re-fetch files from GitHub)
|
|
|
|
|
|
|
| 47 |
EOF
|
| 48 |
}
|
| 49 |
#
|
|
@@ -52,41 +62,72 @@ EOF
|
|
| 52 |
##################
|
| 53 |
|
| 54 |
ONLINE_MODE=false
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
VALID_ARGS=$(getopt -o
|
| 57 |
if [[ $? -ne 0 ]]; then
|
| 58 |
usage "short"
|
| 59 |
-
exit 1
|
| 60 |
fi
|
| 61 |
eval set -- "$VALID_ARGS"
|
| 62 |
while [ : ]
|
| 63 |
do
|
| 64 |
case "$1" in
|
| 65 |
-o | --online) ONLINE_MODE=true; shift ;;
|
|
|
|
|
|
|
| 66 |
-h | --help) usage; shift ; exit 0;;
|
| 67 |
--) shift ; break ;;
|
| 68 |
*) >&2 echo Unsupported option: $1; usage; exit 1;;
|
| 69 |
esac
|
| 70 |
done
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
| 91 |
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
done
|
|
|
|
| 1 |
#!/usr/bin/env bash
|
| 2 |
#
|
| 3 |
|
| 4 |
+
set -euo pipefail
|
| 5 |
+
|
| 6 |
+
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
| 7 |
+
ETC_DIR="${SCRIPT_DIR}/etc"
|
| 8 |
+
ENV_FILE="${SCRIPT_DIR}/.env"
|
| 9 |
+
|
| 10 |
+
[ -e "${ENV_FILE}" ] && . "${ENV_FILE}"
|
| 11 |
+
|
| 12 |
# This is a manual mapping of versions of codes_and_flags.yaml from:
|
| 13 |
# * https://github.com/UniversalDependencies/docs-automation/commits/master/codes_and_flags.yaml
|
| 14 |
# (identified by commit hash) matched to the closest date of UD versions from:
|
|
|
|
| 33 |
# USAGE
|
| 34 |
#
|
| 35 |
usage() { OUTPUT=${1:-"verbose"}
|
| 36 |
+
echo "Usage: $0 [-o] [-r VER] [-a]" >&2
|
| 37 |
+
[ "${OUTPUT}" = "short" ] && exit 0
|
| 38 |
>&2 cat << EOF
|
| 39 |
|
| 40 |
Download versions of
|
|
|
|
| 52 |
Options:
|
| 53 |
-h Print this help message
|
| 54 |
-o|--online Enable online mode: (re-fetch files from GitHub)
|
| 55 |
+
-r|--rev VER Download one version (default: UD_VER from .env)
|
| 56 |
+
-a|--all Download all mapped versions
|
| 57 |
EOF
|
| 58 |
}
|
| 59 |
#
|
|
|
|
| 62 |
##################
|
| 63 |
|
| 64 |
ONLINE_MODE=false
|
| 65 |
+
ALL_MODE=false
|
| 66 |
+
TARGET_VER="${UD_VER:-2.17}"
|
| 67 |
|
| 68 |
+
VALID_ARGS=$(getopt -o hoar: --long help,online,all,rev: -- "$@")
|
| 69 |
if [[ $? -ne 0 ]]; then
|
| 70 |
usage "short"
|
| 71 |
+
exit 1
|
| 72 |
fi
|
| 73 |
eval set -- "$VALID_ARGS"
|
| 74 |
while [ : ]
|
| 75 |
do
|
| 76 |
case "$1" in
|
| 77 |
-o | --online) ONLINE_MODE=true; shift ;;
|
| 78 |
+
-a | --all) ALL_MODE=true; shift ;;
|
| 79 |
+
-r | --rev) TARGET_VER="$2"; shift 2 ;;
|
| 80 |
-h | --help) usage; shift ; exit 0;;
|
| 81 |
--) shift ; break ;;
|
| 82 |
*) >&2 echo Unsupported option: $1; usage; exit 1;;
|
| 83 |
esac
|
| 84 |
done
|
| 85 |
|
| 86 |
+
download_codes_and_flags() {
|
| 87 |
+
local ver="$1"
|
| 88 |
+
local git_hash="$2"
|
| 89 |
+
local codes_and_flags_fn="${ETC_DIR}/codes_and_flags-${ver}.yaml"
|
| 90 |
+
local codes_and_flags_raw_url="https://raw.githubusercontent.com/UniversalDependencies/docs-automation/${git_hash}/codes_and_flags.yaml"
|
| 91 |
+
|
| 92 |
+
if [[ "${ONLINE_MODE}" != true ]] && [[ -e "${codes_and_flags_fn}" ]]; then
|
| 93 |
+
return 0
|
| 94 |
+
fi
|
| 95 |
+
|
| 96 |
+
if command -v curl >/dev/null 2>&1; then
|
| 97 |
+
curl -fL --retry 3 --retry-delay 1 "${codes_and_flags_raw_url}" -o "${codes_and_flags_fn}"
|
| 98 |
+
elif command -v wget >/dev/null 2>&1; then
|
| 99 |
+
wget "${codes_and_flags_raw_url}" -O "${codes_and_flags_fn}"
|
| 100 |
+
else
|
| 101 |
+
python3 - "${codes_and_flags_raw_url}" "${codes_and_flags_fn}" <<'PY'
|
| 102 |
+
import sys
|
| 103 |
+
from urllib.request import urlretrieve
|
| 104 |
+
|
| 105 |
+
urlretrieve(sys.argv[1], sys.argv[2])
|
| 106 |
+
PY
|
| 107 |
fi
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
mkdir -p "${ETC_DIR}"
|
| 111 |
+
|
| 112 |
+
declare -a TARGET_VERSIONS=()
|
| 113 |
+
if [[ "${ALL_MODE}" == true ]]; then
|
| 114 |
+
mapfile -t TARGET_VERSIONS < <(printf '%s\n' "${!VER_MAPPING[@]}" | awk '/^[0-9]+\.[0-9]+$/' | sort -V)
|
| 115 |
+
if [[ -n "${VER_MAPPING[latest]:-}" ]]; then
|
| 116 |
+
TARGET_VERSIONS+=("latest")
|
| 117 |
+
fi
|
| 118 |
+
else
|
| 119 |
+
if [[ -z "${VER_MAPPING[${TARGET_VER}]:-}" ]]; then
|
| 120 |
+
>&2 echo "Unsupported version: ${TARGET_VER}"
|
| 121 |
+
>&2 echo "Available versions: $(printf '%s ' "${!VER_MAPPING[@]}" | sed 's/ $//')"
|
| 122 |
+
exit 1
|
| 123 |
+
fi
|
| 124 |
+
TARGET_VERSIONS+=("${TARGET_VER}")
|
| 125 |
+
# Keep codes_and_flags-latest.yaml in sync when downloading a single version.
|
| 126 |
+
if [[ "${TARGET_VER}" != "latest" ]] && [[ -n "${VER_MAPPING[latest]:-}" ]]; then
|
| 127 |
+
TARGET_VERSIONS+=("latest")
|
| 128 |
+
fi
|
| 129 |
+
fi
|
| 130 |
+
|
| 131 |
+
for ver in "${TARGET_VERSIONS[@]}"; do
|
| 132 |
+
download_codes_and_flags "${ver}" "${VER_MAPPING[${ver}]}"
|
| 133 |
done
|
tools/02_generate_metadata.py
CHANGED
|
@@ -268,17 +268,17 @@ def traverse_directory(directory):
|
|
| 268 |
# 2. sets without a summary, files or license
|
| 269 |
if not results[item]["summary"]:
|
| 270 |
del results[item]
|
| 271 |
-
|
| 272 |
|
| 273 |
if not any([value["files"] for value in
|
| 274 |
results[item]["splits"].values()]):
|
| 275 |
-
|
| 276 |
del results[item]
|
| 277 |
-
|
| 278 |
|
| 279 |
if not results[item]["license"]:
|
| 280 |
del results[item]
|
| 281 |
-
|
| 282 |
|
| 283 |
# Swap keys and key.value()["name"]; add old key as key.value()["dirname"]
|
| 284 |
for key in list(results.keys()):
|
|
@@ -317,9 +317,7 @@ if __name__ == '__main__':
|
|
| 317 |
results[name]["blocked"] = False
|
| 318 |
|
| 319 |
for name, metadata in results.items():
|
| 320 |
-
|
| 321 |
-
# print(metadata)
|
| 322 |
-
# print('---')
|
| 323 |
|
| 324 |
# Write the metadata to json
|
| 325 |
output_fn = f"metadata-{UD_VER}.json"
|
|
|
|
| 268 |
# 2. sets without a summary, files or license
|
| 269 |
if not results[item]["summary"]:
|
| 270 |
del results[item]
|
| 271 |
+
logging.warning("ITEM DELETED - no summary: %s", item)
|
| 272 |
|
| 273 |
if not any([value["files"] for value in
|
| 274 |
results[item]["splits"].values()]):
|
| 275 |
+
logging.debug(results[item]["splits"])
|
| 276 |
del results[item]
|
| 277 |
+
logging.warning("ITEM DELETED - no files: %s", item)
|
| 278 |
|
| 279 |
if not results[item]["license"]:
|
| 280 |
del results[item]
|
| 281 |
+
logging.warning("ITEM DELETED - no license: %s", item)
|
| 282 |
|
| 283 |
# Swap keys and key.value()["name"]; add old key as key.value()["dirname"]
|
| 284 |
for key in list(results.keys()):
|
|
|
|
| 317 |
results[name]["blocked"] = False
|
| 318 |
|
| 319 |
for name, metadata in results.items():
|
| 320 |
+
logging.debug("Directory: %s", metadata["dirname"])
|
|
|
|
|
|
|
| 321 |
|
| 322 |
# Write the metadata to json
|
| 323 |
output_fn = f"metadata-{UD_VER}.json"
|
tools/03_generate_README.py
CHANGED
|
@@ -7,7 +7,7 @@ import json
|
|
| 7 |
import argparse
|
| 8 |
import logging
|
| 9 |
from os import getenv
|
| 10 |
-
from pathlib import Path
|
| 11 |
|
| 12 |
import jinja2
|
| 13 |
from dotenv import load_dotenv
|
|
|
|
| 7 |
import argparse
|
| 8 |
import logging
|
| 9 |
from os import getenv
|
| 10 |
+
from pathlib import Path
|
| 11 |
|
| 12 |
import jinja2
|
| 13 |
from dotenv import load_dotenv
|
tools/04_generate_parquet.py
CHANGED
|
@@ -29,10 +29,14 @@ Note for developers:
|
|
| 29 |
import argparse
|
| 30 |
import os
|
| 31 |
import sys
|
| 32 |
-
from pathlib import Path
|
| 33 |
|
| 34 |
from dotenv import load_dotenv
|
| 35 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
|
| 38 |
# Load environment variables
|
|
@@ -40,11 +44,7 @@ load_dotenv()
|
|
| 40 |
UD_VER = os.getenv("UD_VER", "2.17")
|
| 41 |
|
| 42 |
# Project paths
|
| 43 |
-
|
| 44 |
-
METADATA_FILE = REPO_ROOT / f"metadata.json"
|
| 45 |
-
UD_REPOS_DIR = REPO_ROOT / "tools" / "UD_repos"
|
| 46 |
-
OUTPUT_DIR = REPO_ROOT / "parquet"
|
| 47 |
-
BLOCKED_TREEBANKS_FILE = REPO_ROOT / "tools" / "blocked_treebanks.yaml"
|
| 48 |
|
| 49 |
|
| 50 |
def main():
|
|
@@ -62,39 +62,25 @@ def main():
|
|
| 62 |
args = parser.parse_args()
|
| 63 |
|
| 64 |
# Use default blocked treebanks file if not specified
|
| 65 |
-
blocked_treebanks_path = args.blocked_treebanks or str(
|
| 66 |
|
| 67 |
# Build arguments for ud-hf-parquet-tools
|
| 68 |
tool_args = [
|
| 69 |
"ud-hfp-tools",
|
| 70 |
"generate",
|
| 71 |
-
"--metadata", str(
|
| 72 |
-
"--ud-repos-dir", str(
|
| 73 |
-
"--output-dir", str(
|
| 74 |
"--blocked-treebanks", blocked_treebanks_path,
|
| 75 |
]
|
| 76 |
|
| 77 |
-
|
| 78 |
-
tool_args.append("--test")
|
| 79 |
-
|
| 80 |
-
if args.treebanks:
|
| 81 |
-
tool_args.extend(["--treebanks", args.treebanks])
|
| 82 |
|
| 83 |
if args.overwrite:
|
| 84 |
tool_args.append("--overwrite")
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
elif args.verbose:
|
| 89 |
-
tool_args.append("--verbose")
|
| 90 |
-
|
| 91 |
-
# Replace sys.argv and call the library's main function
|
| 92 |
-
original_argv = sys.argv
|
| 93 |
-
try:
|
| 94 |
-
sys.argv = tool_args
|
| 95 |
-
return ud_tools_main()
|
| 96 |
-
finally:
|
| 97 |
-
sys.argv = original_argv
|
| 98 |
|
| 99 |
|
| 100 |
if __name__ == "__main__":
|
|
|
|
| 29 |
import argparse
|
| 30 |
import os
|
| 31 |
import sys
|
|
|
|
| 32 |
|
| 33 |
from dotenv import load_dotenv
|
| 34 |
+
from _ud_hfp_wrapper import (
|
| 35 |
+
append_common_selection_args,
|
| 36 |
+
append_common_verbosity_args,
|
| 37 |
+
get_repo_paths,
|
| 38 |
+
run_ud_tools,
|
| 39 |
+
)
|
| 40 |
|
| 41 |
|
| 42 |
# Load environment variables
|
|
|
|
| 44 |
UD_VER = os.getenv("UD_VER", "2.17")
|
| 45 |
|
| 46 |
# Project paths
|
| 47 |
+
PATHS = get_repo_paths(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
|
| 50 |
def main():
|
|
|
|
| 62 |
args = parser.parse_args()
|
| 63 |
|
| 64 |
# Use default blocked treebanks file if not specified
|
| 65 |
+
blocked_treebanks_path = args.blocked_treebanks or str(PATHS.blocked_treebanks_file)
|
| 66 |
|
| 67 |
# Build arguments for ud-hf-parquet-tools
|
| 68 |
tool_args = [
|
| 69 |
"ud-hfp-tools",
|
| 70 |
"generate",
|
| 71 |
+
"--metadata", str(PATHS.metadata_file),
|
| 72 |
+
"--ud-repos-dir", str(PATHS.ud_repos_dir),
|
| 73 |
+
"--output-dir", str(PATHS.parquet_dir),
|
| 74 |
"--blocked-treebanks", blocked_treebanks_path,
|
| 75 |
]
|
| 76 |
|
| 77 |
+
append_common_selection_args(args, tool_args)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
if args.overwrite:
|
| 80 |
tool_args.append("--overwrite")
|
| 81 |
|
| 82 |
+
append_common_verbosity_args(args, tool_args)
|
| 83 |
+
return run_ud_tools(tool_args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
|
| 86 |
if __name__ == "__main__":
|
tools/05_validate_parquet.py
CHANGED
|
@@ -45,10 +45,14 @@ Note for developers:
|
|
| 45 |
import argparse
|
| 46 |
import os
|
| 47 |
import sys
|
| 48 |
-
from pathlib import Path
|
| 49 |
|
| 50 |
from dotenv import load_dotenv
|
| 51 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
# Load environment variables
|
|
@@ -56,10 +60,7 @@ load_dotenv()
|
|
| 56 |
UD_VER = os.getenv("UD_VER", "2.17")
|
| 57 |
|
| 58 |
# Project paths
|
| 59 |
-
|
| 60 |
-
METADATA_FILE = REPO_ROOT / "metadata.json"
|
| 61 |
-
UD_REPOS_DIR = REPO_ROOT / "tools" / "UD_repos"
|
| 62 |
-
PARQUET_DIR = REPO_ROOT / "parquet"
|
| 63 |
|
| 64 |
|
| 65 |
def main():
|
|
@@ -78,50 +79,27 @@ def main():
|
|
| 78 |
parser.add_argument("-q", "--quiet", action="store_true", help="Quiet mode")
|
| 79 |
|
| 80 |
args = parser.parse_args()
|
|
|
|
| 81 |
|
| 82 |
# Build arguments for ud-hf-parquet-tools
|
| 83 |
tool_args = [
|
| 84 |
"ud-hfp-tools",
|
| 85 |
"validate",
|
| 86 |
-
"--metadata",
|
| 87 |
-
"--ud-repos-dir", str(
|
| 88 |
]
|
| 89 |
|
| 90 |
# Handle parquet directory
|
| 91 |
if args.parquet_dir:
|
| 92 |
tool_args.extend(["--parquet-dir", args.parquet_dir])
|
| 93 |
elif args.local:
|
| 94 |
-
tool_args.extend(["--parquet-dir", str(
|
| 95 |
else:
|
| 96 |
# Remote validation
|
| 97 |
tool_args.extend(["--revision", args.revision])
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
tool_args.extend(["--metadata", args.metadata])
|
| 102 |
-
elif args.local:
|
| 103 |
-
tool_args.extend(["--metadata", str(METADATA_FILE)])
|
| 104 |
-
|
| 105 |
-
if args.test:
|
| 106 |
-
tool_args.append("--test")
|
| 107 |
-
|
| 108 |
-
if args.treebanks:
|
| 109 |
-
tool_args.extend(["--treebanks", args.treebanks])
|
| 110 |
-
|
| 111 |
-
if args.very_verbose:
|
| 112 |
-
tool_args.append("-vv")
|
| 113 |
-
elif args.quiet:
|
| 114 |
-
tool_args.append("--quiet")
|
| 115 |
-
elif args.verbose:
|
| 116 |
-
tool_args.append("--verbose")
|
| 117 |
-
|
| 118 |
-
# Replace sys.argv and call the library's main function
|
| 119 |
-
original_argv = sys.argv
|
| 120 |
-
try:
|
| 121 |
-
sys.argv = tool_args
|
| 122 |
-
return ud_tools_main()
|
| 123 |
-
finally:
|
| 124 |
-
sys.argv = original_argv
|
| 125 |
|
| 126 |
|
| 127 |
if __name__ == "__main__":
|
|
|
|
| 45 |
import argparse
|
| 46 |
import os
|
| 47 |
import sys
|
|
|
|
| 48 |
|
| 49 |
from dotenv import load_dotenv
|
| 50 |
+
from _ud_hfp_wrapper import (
|
| 51 |
+
append_common_selection_args,
|
| 52 |
+
append_common_verbosity_args,
|
| 53 |
+
get_repo_paths,
|
| 54 |
+
run_ud_tools,
|
| 55 |
+
)
|
| 56 |
|
| 57 |
|
| 58 |
# Load environment variables
|
|
|
|
| 60 |
UD_VER = os.getenv("UD_VER", "2.17")
|
| 61 |
|
| 62 |
# Project paths
|
| 63 |
+
PATHS = get_repo_paths(__file__)
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
def main():
|
|
|
|
| 79 |
parser.add_argument("-q", "--quiet", action="store_true", help="Quiet mode")
|
| 80 |
|
| 81 |
args = parser.parse_args()
|
| 82 |
+
metadata_path = args.metadata or str(PATHS.metadata_file)
|
| 83 |
|
| 84 |
# Build arguments for ud-hf-parquet-tools
|
| 85 |
tool_args = [
|
| 86 |
"ud-hfp-tools",
|
| 87 |
"validate",
|
| 88 |
+
"--metadata", metadata_path,
|
| 89 |
+
"--ud-repos-dir", str(PATHS.ud_repos_dir),
|
| 90 |
]
|
| 91 |
|
| 92 |
# Handle parquet directory
|
| 93 |
if args.parquet_dir:
|
| 94 |
tool_args.extend(["--parquet-dir", args.parquet_dir])
|
| 95 |
elif args.local:
|
| 96 |
+
tool_args.extend(["--parquet-dir", str(PATHS.parquet_dir)])
|
| 97 |
else:
|
| 98 |
# Remote validation
|
| 99 |
tool_args.extend(["--revision", args.revision])
|
| 100 |
+
append_common_selection_args(args, tool_args)
|
| 101 |
+
append_common_verbosity_args(args, tool_args)
|
| 102 |
+
return run_ud_tools(tool_args)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
|
| 105 |
if __name__ == "__main__":
|
tools/README.md
CHANGED
|
@@ -40,7 +40,8 @@ git add ../parquet ../README.md ../metadata.json
|
|
| 40 |
|
| 41 |
**00_fetch_ud_codes_and_flags.sh**
|
| 42 |
- Downloads language codes and flags from UD docs-automation
|
| 43 |
-
-
|
|
|
|
| 44 |
- Update `VER_MAPPING` for new versions
|
| 45 |
|
| 46 |
### 01 - Fetch Snapshot
|
|
|
|
| 40 |
|
| 41 |
**00_fetch_ud_codes_and_flags.sh**
|
| 42 |
- Downloads language codes and flags from UD docs-automation
|
| 43 |
+
- Default output: `etc/codes_and_flags-{UD_VER}.yaml`, `etc/codes_and_flags-latest.yaml`
|
| 44 |
+
- `--all` output: all mapped `etc/codes_and_flags-{VER}.yaml` files
|
| 45 |
- Update `VER_MAPPING` for new versions
|
| 46 |
|
| 47 |
### 01 - Fetch Snapshot
|
tools/_ud_hfp_wrapper.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env -S uv run
|
| 2 |
+
"""
|
| 3 |
+
Shared wrapper utilities for ud-hf-parquet-tools entrypoint scripts.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from dataclasses import dataclass
|
| 7 |
+
import sys
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@dataclass(frozen=True)
|
| 12 |
+
class RepoPaths:
|
| 13 |
+
repo_root: Path
|
| 14 |
+
metadata_file: Path
|
| 15 |
+
ud_repos_dir: Path
|
| 16 |
+
parquet_dir: Path
|
| 17 |
+
blocked_treebanks_file: Path
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def get_repo_paths(script_file: str) -> RepoPaths:
|
| 21 |
+
"""
|
| 22 |
+
Resolve repository paths from a script file path.
|
| 23 |
+
"""
|
| 24 |
+
repo_root = Path(script_file).parent.parent.resolve()
|
| 25 |
+
return RepoPaths(
|
| 26 |
+
repo_root=repo_root,
|
| 27 |
+
metadata_file=repo_root / "metadata.json",
|
| 28 |
+
ud_repos_dir=repo_root / "tools" / "UD_repos",
|
| 29 |
+
parquet_dir=repo_root / "parquet",
|
| 30 |
+
blocked_treebanks_file=repo_root / "tools" / "blocked_treebanks.yaml",
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def append_common_selection_args(args, tool_args: list[str]) -> None:
|
| 35 |
+
"""
|
| 36 |
+
Append common subset-selection flags.
|
| 37 |
+
"""
|
| 38 |
+
if getattr(args, "test", False):
|
| 39 |
+
tool_args.append("--test")
|
| 40 |
+
|
| 41 |
+
treebanks = getattr(args, "treebanks", None)
|
| 42 |
+
if treebanks:
|
| 43 |
+
tool_args.extend(["--treebanks", treebanks])
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def append_common_verbosity_args(args, tool_args: list[str]) -> None:
|
| 47 |
+
"""
|
| 48 |
+
Append common verbosity flags with consistent precedence.
|
| 49 |
+
"""
|
| 50 |
+
if getattr(args, "very_verbose", False):
|
| 51 |
+
tool_args.append("-vv")
|
| 52 |
+
elif getattr(args, "quiet", False):
|
| 53 |
+
tool_args.append("--quiet")
|
| 54 |
+
elif getattr(args, "verbose", False):
|
| 55 |
+
tool_args.append("--verbose")
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def run_ud_tools(tool_args: list[str]) -> int:
|
| 59 |
+
"""
|
| 60 |
+
Run ud-hf-parquet-tools by emulating command-line invocation.
|
| 61 |
+
"""
|
| 62 |
+
# Lazy import keeps wrapper help usable even when runtime deps are absent.
|
| 63 |
+
from ud_hf_parquet_tools.cli import main as ud_tools_main
|
| 64 |
+
|
| 65 |
+
original_argv = sys.argv
|
| 66 |
+
try:
|
| 67 |
+
sys.argv = tool_args
|
| 68 |
+
return int(ud_tools_main())
|
| 69 |
+
finally:
|
| 70 |
+
sys.argv = original_argv
|