Skip to content

Commit

Permalink
Fix parse-examples script to use a stable sha of numpy repo
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed Sep 8, 2020
1 parent 6109e4e commit 58f5724
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions script/parse-examples
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,31 @@ set -e

cd "$(dirname "$0")/.."

# Clone example repo and check out a known sha
repo=examples/numpy
if [ ! -d "$repo" ]; then
git clone https://github.com/numpy/numpy "$repo"
else
pushd "$repo" && git fetch
git reset --hard 058851c5cfc98f50f11237b1c13d77cfd1f40475
function checkout() {
repo=$1; url=$2; sha=$3

if [ ! -d "$repo" ]; then
git clone "https://github.com/$url" "$repo"
fi

pushd "$repo"
git fetch && git reset --hard "$sha"
popd
fi
}

tree-sitter parse examples/*.py -qt
checkout examples/numpy numpy/numpy 058851c5cfc98f50f11237b1c13d77cfd1f40475

# TODO: Fix known issues in known_failures.txt
known_failures=$(cat script/known_failures.txt)
examples_to_parse=$(
for example in $(find "$repo" -name '*.py'); do
if [[ ! $known_failures == *$example* ]]; then
echo $example
fi
done
)
known_failures="$(cat script/known_failures.txt)"

echo $examples_to_parse | xargs -n 5000 tree-sitter parse -q
tree-sitter parse -q \
'examples/**/*.py' \
$(for file in $known_failures; do echo "!${file}"; done)

skipped=$( echo $known_failures | wc -w )
parsed=$( echo $examples_to_parse | wc -w )
total=$((parsed+skipped))
percent=$(bc -l <<< "100*$parsed/$total")
example_count=$(find examples -name '*.py' | wc -l)
failure_count=$(wc -w <<< "$known_failures")
success_count=$(( $example_count - $failure_count ))
success_percent=$(bc -l <<< "100*${success_count}/${example_count}")

printf "Successfully parsed %.2f%% of $repo (%d of %d files)\n" $percent $parsed $total
printf \
"Successfully parsed %d of %d example files (%.1f%%)\n" \
$success_count $example_count $success_percent

0 comments on commit 58f5724

Please sign in to comment.