@@ -65,14 +65,17 @@ if [[ "${JOB_BASE_NAME}" == *worker_* ]]; then
6565 rm beginner_source/aws_distributed_training_tutorial.py || true
6666
6767 # Step 2: Keep certain tutorials based on file count, and remove runnable code in all other tutorials
68+ # IMPORTANT NOTE: We assume that each tutorial has a UNIQUE filename.
6869 export WORKER_ID=$( echo " ${JOB_BASE_NAME} " | tr -dc ' 0-9' )
6970 count=0
71+ FILES_TO_RUN=()
7072 for filename in $( find beginner_source/ -name ' *.py' -not -path ' */data/*' ) ; do
7173 if [ $(( $count % $NUM_WORKERS )) != $WORKER_ID ]; then
7274 echo " Removing runnable code from " $filename
7375 python $DIR /remove_runnable_code.py $filename $filename
7476 else
7577 echo " Keeping " $filename
78+ FILES_TO_RUN+=($( basename $filename .py) )
7679 fi
7780 count=$(( count+ 1 ))
7881 done
@@ -82,6 +85,7 @@ if [[ "${JOB_BASE_NAME}" == *worker_* ]]; then
8285 python $DIR /remove_runnable_code.py $filename $filename
8386 else
8487 echo " Keeping " $filename
88+ FILES_TO_RUN+=($( basename $filename .py) )
8589 fi
8690 count=$(( count+ 1 ))
8791 done
@@ -91,28 +95,58 @@ if [[ "${JOB_BASE_NAME}" == *worker_* ]]; then
9195 python $DIR /remove_runnable_code.py $filename $filename
9296 else
9397 echo " Keeping " $filename
98+ FILES_TO_RUN+=($( basename $filename .py) )
9499 fi
95100 count=$(( count+ 1 ))
96101 done
102+ echo " FILES_TO_RUN: " ${FILES_TO_RUN[@]}
97103
98104 # Step 3: Run `make docs` to generate HTML files and static files for these tutorials
99105 make docs
100106
101- # Step 4: Remove all HTML files generated from Python files that don't contain runnable code
102- for filename in $( find docs/beginner -name ' *.html' ) ; do
103- python $DIR /delete_html_file_with_runnable_code_removed.py $filename
107+ # Step 4: If any of the generated files are not related the tutorial files we want to run,
108+ # then we remove them
109+ for filename in $( find docs/beginner docs/intermediate docs/advanced -name ' *.html' ) ; do
110+ file_basename=$( basename $filename .html)
111+ if [[ ! " ${FILES_TO_RUN[@]} " =~ " ${file_basename} " ]]; then
112+ rm $filename
113+ fi
104114 done
105- for filename in $( find docs/intermediate -name ' *.html' ) ; do
106- python $DIR /delete_html_file_with_runnable_code_removed.py $filename
115+ for filename in $( find docs/beginner docs/intermediate docs/advanced -name ' *.rst' ) ; do
116+ file_basename=$( basename $filename .rst)
117+ if [[ ! " ${FILES_TO_RUN[@]} " =~ " ${file_basename} " ]]; then
118+ rm $filename
119+ fi
107120 done
108- for filename in $( find docs/advanced -name ' *.html' ) ; do
109- python $DIR /delete_html_file_with_runnable_code_removed.py $filename
121+ for filename in $( find docs/_downloads -name ' *.py' ) ; do
122+ file_basename=$( basename $filename .py)
123+ if [[ ! " ${FILES_TO_RUN[@]} " =~ " ${file_basename} " ]]; then
124+ rm $filename
125+ fi
126+ done
127+ for filename in $( find docs/_downloads -name ' *.ipynb' ) ; do
128+ file_basename=$( basename $filename .ipynb)
129+ if [[ ! " ${FILES_TO_RUN[@]} " =~ " ${file_basename} " ]]; then
130+ rm $filename
131+ fi
132+ done
133+ for filename in $( find docs/_sources/beginner docs/_sources/intermediate docs/_sources/advanced -name ' *.rst.txt' ) ; do
134+ file_basename=$( basename $filename .rst.txt)
135+ if [[ ! " ${FILES_TO_RUN[@]} " =~ " ${file_basename} " ]]; then
136+ rm $filename
137+ fi
138+ done
139+ for filename in $( find docs/.doctrees/beginner docs/.doctrees/intermediate docs/.doctrees/advanced -name ' *.doctree' ) ; do
140+ file_basename=$( basename $filename .doctree)
141+ if [[ ! " ${FILES_TO_RUN[@]} " =~ " ${file_basename} " ]]; then
142+ rm $filename
143+ fi
110144 done
111145
112- # Step 5: Remove INVISIBLE_CODE_BLOCK from all HTML files
146+ # Step 5: Remove INVISIBLE_CODE_BLOCK from .html/.rst.txt/.ipynb/.py files
113147 bash $DIR /remove_invisible_code_block_batch.sh docs
114148
115- # Step 6: Copy generated HTML files and static files to S3, tag with commit ID
149+ # Step 6: Copy generated files to S3, tag with commit ID
116150 7z a worker_${WORKER_ID} .7z docs
117151 aws s3 cp worker_${WORKER_ID} .7z s3://${BUCKET_NAME} /${COMMIT_ID} /worker_${WORKER_ID} .7z --acl public-read
118152elif [[ " ${JOB_BASE_NAME} " == * manager ]]; then
@@ -151,14 +185,17 @@ elif [[ "${JOB_BASE_NAME}" == *manager ]]; then
151185 done
152186
153187 # Step 5: Copy all static files into docs
154- rsync -av docs_with_plot/docs/ docs --exclude beginner --exclude intermediate --exclude advanced
188+ rsync -av docs_with_plot/docs/ docs
189+
190+ # Step 6: Remove INVISIBLE_CODE_BLOCK from .html/.rst.txt/.ipynb/.py files
191+ bash $DIR /remove_invisible_code_block_batch.sh docs
155192
156- # Step 6 : Copy generated HTML files and static files to S3
193+ # Step 7 : Copy generated HTML files and static files to S3
157194 7z a manager.7z docs
158195 aws s3 cp manager.7z s3://${BUCKET_NAME} /${COMMIT_ID} /manager.7z --acl public-read
159196
160197 # yf225 TODO: re-enable this after tutorial build is fixed
161- # # Step 7 : push new HTML files and static files to gh-pages
198+ # # Step 8 : push new HTML files and static files to gh-pages
162199 # if [[ "$COMMIT_SOURCE" == master ]]; then
163200 # git clone https://github.com/pytorch/tutorials.git -b gh-pages gh-pages
164201 # cp -r docs/* gh-pages/
0 commit comments