Path: blob/develop/src/doc/en/reference/make_module_list.sh
4112 views
#!/bin/bash12# This script traverses files with .py and .pyx suffixes in src/<directory>3# tree of the Sage library and store the module names sorted by their path4# and titles.5#6# EXAMPLE:7#8# $ src/doc/en/reference/make_module_list.sh sage/combinat910if [ $# -ne 1 ]; then11echo "Usage: $0 <directory>"12echo "Example: $0 sage/combinat"13exit 114fi1516module_dir="$1"17input_dir="$SAGE_ROOT/src/$1"1819if [ ! -d "$input_dir" ]; then20echo "Error: Directory '$input_dir' not found."21exit 122fi2324tmpfile=$(mktemp)2526cd "$input_dir"2728# Find all .py and .pyx files inside the given directory, excluding __init__.py29find . -type f \( -name "*.py" -o -name "*.pyx" \) ! -name "__init__.py" | while read -r file; do30# Extract first line after the first triple quotes31title=$(awk 'BEGIN {found=0}32/^[rR]?"""/ {if (found == 0) {found=1; next}}33found && NF {print; exit}' "$file")3435# Format module name: Remove .py or .pyx, replace directory prefix36mod_name=$(echo "$file" | sed -E "s/\.(pyx|py)$//; s|^\./| $module_dir/|")37path_name=$(dirname "$file")3839# Store sorting path/title and module name in temporary file40printf "%s\t%s\n" "$path_name,$title" "$mod_name" >> "$tmpfile"41done4243# Sort and output module names to /tmp/module_list.rst44LC_ALL=C sort "$tmpfile" | cut -f2 > /tmp/module_list4546rm -f "$tmpfile"4748echo "Sorted module list saved to /tmp/module_list"495051