-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmake_init.sh
30 lines (26 loc) · 930 Bytes
/
make_init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# Set the package directory
PACKAGE_DIR="fusionlab"
# Find all directories in the package
DIRS=$(find $PACKAGE_DIR -type d)
# Create __init__.py files in all directories
for DIR in $DIRS; do
touch $DIR/__init__.py
done
# Add import statements to __init__.py files
for DIR in $DIRS; do
# Get the relative path of the directory
RELATIVE_PATH=${DIR#$PACKAGE_DIR/}
# Get the list of subdirectories and files in the directory
SUBDIRS=$(find $DIR -maxdepth 1 -type d ! -path $DIR)
FILES=$(find $DIR -maxdepth 1 -type f -name "*.py" ! -name "__init__.py")
# Add import statements for subdirectories and files
for SUBDIR in $SUBDIRS; do
MODULE_NAME=${SUBDIR#$DIR/}
echo "from .$MODULE_NAME import *" >> $DIR/__init__.py
done
for FILE in $FILES; do
MODULE_NAME=$(basename $FILE .py)
echo "from .$MODULE_NAME import *" >> $DIR/__init__.py
done
done