# Custom extension that zips all the examples for download.
from zipfile import ZipFile
from os import path
import glob


def zip_examples(app):
    glob_patterns = [
        "examples/**/*.c3",
        "examples/**/*.asm",
        "examples/**/*.mmap",
        "examples/**/build.xml",
        "librt/*.c3"]
    my_path = path.dirname(path.abspath(__file__))
    root_path = path.abspath(path.join(my_path, '..', '..'))
    zip_filename = path.join(root_path, 'docs', 'examples.zip')
    with ZipFile(zip_filename, 'w') as myzip:
        for glob_pattern in glob_patterns:
            pat = path.join(path.join(root_path, glob_pattern))
            for filename in glob.iglob(pat, recursive=True):
                zfn = path.relpath(filename, root_path)
                app.info('zipping {} as {}'.format(filename, zfn))
                myzip.write(filename, zfn)


def setup(app):
    app.connect('builder-inited', zip_examples)
    return {'version': '0.1'}

@@ -81,16 +81,31 @@
 ZipFile%0A
+import fnmatch%0A
 from os 
@@ -119,20 +119,425 @@
 path
-%0Aimport glob
+, walk%0A%0A%0Amy_path = path.dirname(path.abspath(__file__))%0Aroot_path = path.abspath(path.join(my_path, '..', '..'))%0Azip_filename = path.join(root_path, 'docs', 'examples.zip')%0A%0A%0Adef my_glob(folder, ext):%0A    %22%22%22 glob does not work recursively in all python versions %22%22%22%0A    for root, dirnames, filenames in walk(folder):%0A        for filename in fnmatch.filter(filenames, ext):%0A            yield path.join(root, filename)
 %0A%0A%0Ad
@@ -580,32 +580,33 @@
 rns = %5B%0A        
+(
 %22examples/**/*.c
@@ -602,17 +602,18 @@
 ples
-/**/
+%22, %22
 *.c3%22
+)
 ,%0A  
@@ -610,32 +610,33 @@
 *.c3%22),%0A        
+(
 %22examples/**/*.a
@@ -632,18 +632,19 @@
 ples
-/**/
+%22, %22
 *.asm%22
+)
 ,%0A  
@@ -641,32 +641,33 @@
 .asm%22),%0A        
+(
 %22examples/**/*.m
@@ -663,19 +663,20 @@
 ples
-/**/
+%22, %22
 *.mmap%22
+)
 ,%0A  
@@ -681,16 +681,17 @@
         
+(
 %22example
@@ -695,12 +695,12 @@
 ples
-/**/
+%22, %22
 buil
@@ -705,16 +705,17 @@
 ild.xml%22
+)
 ,%0A      
@@ -720,197 +720,26 @@
     
+(
 %22librt
-/*.c3%22%5D%0A    my_path = path.dirname(path.abspath(__file__))%0A    root_path = path.abspath(path.join(my_path, '..', '..'))%0A    zip_filename = path.join(root_path, 'docs', 'examples.zip')
+%22, %22*.c3%22)%5D
 %0A   
@@ -793,28 +793,27 @@
     for 
-glob_pattern
+folder, ext
  in glob
@@ -872,28 +872,22 @@
 t_path, 
-glob_patt
+fold
 er
-n
 ))%0A     
@@ -913,14 +913,11 @@
  in 
-glob.i
+my_
 glob
@@ -926,22 +926,11 @@
 at, 
-recursive=True
+ext
 ):%0A 

Fix docs build