Repository: kivy/kivy

Issue:
Doc build fails on Windows
The first error is not shown, if the `build` folder is created manually.

``` cmd
make[1]: Entering directory `C:/dev/kivy/doc'
mkdir build\\html build\\doctrees
mkdir: cannot create directory `build\\html': No such file or directory
mkdir: cannot create directory `build\\doctrees': No such file or directory
make[1]: *** [html] Error 1
make[1]: Leaving directory `C:/dev/kivy/doc'
make: *** [html] Error 2
```

And at the end of the build:

``` cmd
copying static files... done
copying extra files... done
dumping search index... done
dumping object inventory... done
build succeeded.
sh: C:\Program: No such file or directory
make[1]: *** [html] Error 127
make[1]: Leaving directory `C:/dev/kivy/doc'
make: *** [html] Error 2
```
## <bountysource-plugin>

Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/5410566-doc-build-fails-on-windows?utm_campaign=plugin&utm_content=tracker%2F42681&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F42681&utm_medium=issues&utm_source=github).
</bountysource-plugin>



Discussion:
I've just checked again with the new stack, i'm getting a new error:

```
$ make html
python setup.py build_ext --inplace
Using distutils
Environ change use_sdl2 -> True
Environ change use_gstreamer -> False

Detected Cython version 0.24
  This version of Cython is untested with Kivy. While this version may
  work perfectly fine, it is possible that you may experience issues. If
  you do have issues, please downgrade to a supported version. It is
  best to use the newest supported version, 0.23, but the minimum
  supported version is 0.20.

  If your platform provides a Cython package, check if you can downgrade
  to a supported version. Otherwise, uninstall the platform package and
  install Cython via pip:

    pip install -I Cython==0.23
User distribution detected, avoid portable command.
Windows platform detected, force GLEW usage.
Using this graphics system: OpenGL
WARNING: A problem occured while running pkg-config --libs --cflags sdl2 SDL2_ttf SDL2_image SDL2_mixer (code 1)

b"'pkg-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"

SDL2: found SDL header at C:\Python34\include\SDL2\SDL.h
SDL2: found SDL_mixer header at C:\Python34\include\SDL2\SDL_mixer.h
SDL2: found SDL_ttf header at C:\Python34\include\SDL2\SDL_ttf.h
SDL2: found SDL_image header at C:\Python34\include\SDL2\SDL_image.h
 C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option: 'setup_requires'
   warnings.warn(msg)
 C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option: 'install_requires'
   warnings.warn(msg)
 C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option: 'dependency_links'
   warnings.warn(msg)
running build_ext
Build configuration is:
 * use_rpi = 0
 * use_mali = 0
 * use_egl = 0
 * use_opengl_es2 = 0
 * use_opengl_debug = 0
 * use_opengl_mock = 0
 * use_glew = 1
 * use_sdl2 = 1
 * use_ios = 0
 * use_mesagl = 0
 * use_x11 = 0
 * use_gstreamer = 0
 * use_avfoundation = 0
 * use_osx_frameworks = 0
 * debug_gl = 0
 * debug = False
Detected compiler is mingw32
skipping 'kivy\core/audio\audio_sdl2.c' Cython extension (up-to-date)
skipping 'kivy\core/text\text_layout.c' Cython extension (up-to-date)
skipping 'kivy\graphics\texture.c' Cython extension (up-to-date)
skipping 'kivy\graphics\context_instructions.c' Cython extension (up-to-date)
skipping 'kivy\graphics\stencil_instructions.c' Cython extension (up-to-date)
skipping 'kivy\graphics\context.c' Cython extension (up-to-date)
skipping 'kivy\_event.c' Cython extension (up-to-date)
skipping 'kivy\graphics\vertex.c' Cython extension (up-to-date)
skipping 'kivy\graphics\svg.c' Cython extension (up-to-date)
skipping 'kivy\graphics\transformation.c' Cython extension (up-to-date)
skipping 'kivy\core/text\_text_sdl2.c' Cython extension (up-to-date)
skipping 'kivy\graphics\c_opengl_debug.c' Cython extension (up-to-date)
skipping 'kivy\graphics\opengl.c' Cython extension (up-to-date)
skipping 'kivy\graphics\compiler.c' Cython extension (up-to-date)
skipping 'kivy\graphics\vbo.c' Cython extension (up-to-date)
skipping 'kivy\graphics\buffer.c' Cython extension (up-to-date)
skipping 'kivy\graphics\fbo.c' Cython extension (up-to-date)
skipping 'kivy\graphics\gl_instructions.c' Cython extension (up-to-date)
skipping 'kivy\graphics\instructions.c' Cython extension (up-to-date)
skipping 'kivy\weakproxy.c' Cython extension (up-to-date)
skipping 'kivy\graphics\opengl_utils.c' Cython extension (up-to-date)
skipping 'kivy\graphics\shader.c' Cython extension (up-to-date)
skipping 'kivy\graphics\tesselator.c' Cython extension (up-to-date)
skipping 'kivy\core/image\_img_sdl2.c' Cython extension (up-to-date)
skipping 'kivy\core/window\_window_sdl2.c' Cython extension (up-to-date)
skipping 'kivy\graphics\scissor_instructions.c' Cython extension (up-to-date)
skipping 'kivy\properties.c' Cython extension (up-to-date)
skipping 'kivy\core/clipboard\_clipboard_sdl2.c' Cython extension (up-to-date)
skipping 'kivy\graphics\c_opengl_mock.c' Cython extension (up-to-date)
skipping 'kivy\graphics\vertex_instructions.c' Cython extension (up-to-date)
cd doc && C:/Python34/share/mingwpy/bin/mingw32-make html
mingw32-make[1]: Entering directory 'E:/dev/prs/kivy/doc'
mkdir -p build/html build/doctrees
python autobuild.py silenced=yes
[INFO              ] [Logger      ] Record log in C:\Users\prc\.kivy\logs\kivy_16-05-07_0.txt
[INFO              ] [Kivy        ] v1.9.2-dev0
[INFO              ] [Python      ] v3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)]
[INFO              ] [Factory     ] 193 symbols loaded
[INFO              ] [OSC         ] using <thread> for socket
[ERROR             ] [Input       ] AndroidJoystick is not supported by your version of linux
Traceback (most recent call last):
  File "E:\dev\prs\kivy\kivy\input\providers\__init__.py", line 57, in <module>
    import kivy.input.providers.androidjoystick
  File "E:\dev\prs\kivy\kivy\input\providers\androidjoystick.py", line 27, in <module>
    import pygame.joystick
ImportError: No module named 'pygame'
 Traceback (most recent call last):
   File "autobuild.py", line 64, in <module>
     from kivy.lib import osc, ddsfile, mtdev
   File "E:\dev\prs\kivy\kivy\lib\mtdev.py", line 27, in <module>
     libmtdev = cdll.LoadLibrary('libmtdev.so.1')
   File "C:\Python34\lib\ctypes\__init__.py", line 429, in LoadLibrary
     return self._dlltype(name)
   File "C:\Python34\lib\ctypes\__init__.py", line 351, in __init__
     self._handle = _dlopen(self._name, mode)
 OSError: [WinError 126] The specified module could not be found
makefile:80: recipe for target 'html' failed
mingw32-make[1]: *** [html] Error 1
mingw32-make[1]: Leaving directory 'E:/dev/prs/kivy/doc'
makefile:71: recipe for target 'html' failed
mingw32-make: *** [html] Error 2
```

Yup, same here. I was wondering how to reproduce that previous error you had.

@dessant 
Fresh python 2.7.11, win7 64bit, mingw32 with msys
Kivy installed with kivy-stable(Factory requirements)

Packages:

<pre>C:\Users\John\kivy docs\kivy>python -m pip list
actdiag (0.5.4)
alabaster (0.7.8)
Babel (2.3.4)
blockdiag (1.5.3)
colorama (0.3.7)
Cython (0.23.4)
docutils (0.12)
funcparserlib (0.3.6)
future (0.15.2)
imagesize (0.7.1)
Jinja2 (2.8)
Kivy (1.9.2.dev0, c:\users\john\kivy docs\kivy)
Kivy-Garden (0.1.4)
kivy.deps.glew (0.1.4)
kivy.deps.glew-dev (0.1.4)
kivy.deps.sdl2 (0.1.12)
kivy.deps.sdl2-dev (0.1.12)
MarkupSafe (0.23)
nwdiag (1.0.4)
pefile (2016.3.28)
Pillow (3.2.0)
pip (8.1.1)
Pygments (2.1.3)
PyInstaller (3.2)
pypiwin32 (219)
pytz (2016.4)
requests (2.10.0)
seqdiag (0.9.5)
setuptools (21.0.0)
six (1.10.0)
snowballstemmer (1.2.1)
Sphinx (1.4.1)
sphinxcontrib-actdiag (0.8.5)
sphinxcontrib-blockdiag (1.5.5)
sphinxcontrib-nwdiag (0.9.5)
sphinxcontrib-seqdiag (0.8.5)
webcolors (1.5)
wget (3.2)
wheel (0.29.0)</pre>
Env:
<pre>C:\Users\John\kivy docs\kivy>set
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\John\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=JOHN-PC
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\John
KIVY_DOC=1
LOCALAPPDATA=C:\Users\John\AppData\Local
LOGONSERVER=\\JOHN-PC
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Path=C:\Users\John\Desktop\python\Scripts;C:\Users\John\Desktop\python;C:\MinGW\
bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\
WindowsPowerShell\v1.0\
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=4501
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\John\AppData\Local\Temp
TMP=C:\Users\John\AppData\Local\Temp
USERDOMAIN=John-PC
USERNAME=John
USERPROFILE=C:\Users\John
USE_SDL2=1
windir=C:\Windows</pre>
Output:
<pre>C:\Users\John\kivy docs\kivy>mingw32-make html
process_begin: CreateProcess(NULL, which git, ...) failed.
python setup.py build_ext --inplace
Using distutils
Environ change use_sdl2 -> True
Detected Cython version 0.23.4
  This version of Cython is untested with Kivy. While this version may
  work perfectly fine, it is possible that you may experience issues. If
  you do have issues, please downgrade to a supported version. It is
  best to use the newest supported version, 0.23, but the minimum
  supported version is 0.20.
  If your platform provides a Cython package, check if you can downgrade
  to a supported version. Otherwise, uninstall the platform package and
  install Cython via pip:
    pip install -I Cython==0.23
User distribution detected, avoid portable command.
Windows platform detected, force GLEW usage.
Using this graphics system: OpenGL
WARNING: A problem occured while running pkg-config --libs --cflags gstreamer-1.
0 (code 1)
'pkg-config' is not recognized as an internal or external command,
operable program or batch file.
WARNING: A problem occured while running pkg-config --libs --cflags sdl2 SDL2_tt
f SDL2_image SDL2_mixer (code 1)
'pkg-config' is not recognized as an internal or external command,
operable program or batch file.
SDL2: found SDL header at C:\Users\John\Desktop\python\include\SDL2\SDL.h
SDL2: found SDL_mixer header at C:\Users\John\Desktop\python\include\SDL2\SDL_mi
xer.h
SDL2: found SDL_ttf header at C:\Users\John\Desktop\python\include\SDL2\SDL_ttf.
h
SDL2: found SDL_image header at C:\Users\John\Desktop\python\include\SDL2\SDL_im
age.h
 C:\Users\John\Desktop\python\lib\distutils\dist.py:267: UserWarning: Unknown di
stribution option: 'setup_requires'
   warnings.warn(msg)
 C:\Users\John\Desktop\python\lib\distutils\dist.py:267: UserWarning: Unknown di
stribution option: 'dependency_links'
   warnings.warn(msg)
 C:\Users\John\Desktop\python\lib\distutils\dist.py:267: UserWarning: Unknown di
stribution option: 'install_requires'
   warnings.warn(msg)
running build_ext
Build configuration is:
 * use_rpi = 0
 * use_mali = 0
 * use_egl = 0
 * use_opengl_es2 = 0
 * use_opengl_debug = 0
 * use_opengl_mock = 0
 * use_glew = 1
 * use_sdl2 = 1
 * use_ios = 0
 * use_mesagl = 0
 * use_x11 = 0
 * use_gstreamer = 0
 * use_avfoundation = 0
 * use_osx_frameworks = 0
 * debug_gl = 0
 * debug = False
Detected compiler is mingw32
skipping 'kivy\core/text\_text_sdl2.c' Cython extension (up-to-date)
skipping 'kivy\graphics\opengl.c' Cython extension (up-to-date)
skipping 'kivy\graphics\stencil_instructions.c' Cython extension (up-to-date)
skipping 'kivy\graphics\transformation.c' Cython extension (up-to-date)
skipping 'kivy\graphics\scissor_instructions.c' Cython extension (up-to-date)
skipping 'kivy\graphics\tesselator.c' Cython extension (up-to-date)
skipping 'kivy\graphics\vertex.c' Cython extension (up-to-date)
skipping 'kivy\graphics\fbo.c' Cython extension (up-to-date)
skipping 'kivy\graphics\context.c' Cython extension (up-to-date)
skipping 'kivy\core/clipboard\_clipboard_sdl2.c' Cython extension (up-to-date)
skipping 'kivy\graphics\buffer.c' Cython extension (up-to-date)
skipping 'kivy\properties.c' Cython extension (up-to-date)
skipping 'kivy\core/image\_img_sdl2.c' Cython extension (up-to-date)
skipping 'kivy\graphics\svg.c' Cython extension (up-to-date)
skipping 'kivy\core/text\text_layout.c' Cython extension (up-to-date)
skipping 'kivy\graphics\opengl_utils.c' Cython extension (up-to-date)
skipping 'kivy\graphics\gl_instructions.c' Cython extension (up-to-date)
skipping 'kivy\_event.c' Cython extension (up-to-date)
skipping 'kivy\graphics\compiler.c' Cython extension (up-to-date)
skipping 'kivy\core/window\_window_sdl2.c' Cython extension (up-to-date)
skipping 'kivy\weakproxy.c' Cython extension (up-to-date)
skipping 'kivy\graphics\context_instructions.c' Cython extension (up-to-date)
skipping 'kivy\graphics\instructions.c' Cython extension (up-to-date)
skipping 'kivy\graphics\vertex_instructions.c' Cython extension (up-to-date)
skipping 'kivy\graphics\c_opengl_debug.c' Cython extension (up-to-date)
skipping 'kivy\graphics\vbo.c' Cython extension (up-to-date)
skipping 'kivy\graphics\shader.c' Cython extension (up-to-date)
skipping 'kivy\graphics\c_opengl_mock.c' Cython extension (up-to-date)
skipping 'kivy\graphics\texture.c' Cython extension (up-to-date)
skipping 'kivy\core/audio\audio_sdl2.c' Cython extension (up-to-date)
cd doc && mingw32-make html
mingw32-make[1]: Entering directory 'C:/Users/John/kivy docs/kivy/doc'
mkdir build\\html build\\doctrees
python gallery.py
[INFO              ] [Logger      ] Record log in C:\Users\John\.kivy\logs\kivy_
16-05-07_56.txt
[INFO              ] [Kivy        ] v1.9.2-dev0
[INFO              ] [Python      ] v2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015,
20:32:19) [MSC v.1500 32 bit (Intel)]
[INFO              ] [gallery.py  ] Created gallery rst documentation pages.
sphinx-build -b html -d build/doctrees  -Q sources build/html
c:\users\john\kivy docs\kivy\kivy\__init__.pyc
[ERROR             ] [Input       ] AndroidJoystick is not supported by your ver
sion of linux
Traceback (most recent call last):
  File "c:\users\john\kivy docs\kivy\kivy\input\providers\__init__.py", line 57,
 in <module>
    import kivy.input.providers.androidjoystick
  File "c:\users\john\kivy docs\kivy\kivy\input\providers\androidjoystick.py", l
ine 27, in <module>
    import pygame.joystick
ImportError: No module named pygame.joystick
ECHO is off.
"Build finished. The HTML pages are in build/html."
mingw32-make[1]: Leaving directory 'C:/Users/John/kivy docs/kivy/doc'</pre>
Change in Makefile:
<pre>AUTOBUILD_STAMP_BASE = autobuild.py --done-with-
AUTOBUILD_STAMP      = $(AUTOBUILD_STAMP_BASE)$(PYTHON)
</pre>

Change in mtdev.py:

<pre># libmtdev = cdll.LoadLibrary('libmtdev.so.1')
# binding
try:
    mtdev_open = libmtdev.mtdev_open
    mtdev_open.argtypes = [POINTER(mtdev), c_int]
    mtdev_get = libmtdev.mtdev_get
    mtdev_get.argtypes = [POINTER(mtdev), c_int, POINTER(input_event), c_int]
    mtdev_idle = libmtdev.mtdev_idle
    mtdev_idle.argtypes = [POINTER(mtdev), c_int, c_int]
    mtdev_close = libmtdev.mtdev_close
    mtdev_close.argtypes = [POINTER(mtdev)]
except: pass</pre>

This needs to be fixed some other way, but it takes the problem away and you don't need that `.so` anyway for docs.

Hope I didn't forget anything important.

Super duper, you could use:

``` python
if 'KIVY_DOC' not in os.environ:
    # do the nasty stuff
```


Resolving patch:
diff --git a/kivy/lib/mtdev.py b/kivy/lib/mtdev.py
--- a/kivy/lib/mtdev.py
+++ b/kivy/lib/mtdev.py
@@ -24,7 +24,8 @@
                    c_void_p, pointer, POINTER, byref
 
 # load library
-libmtdev = cdll.LoadLibrary('libmtdev.so.1')
+if 'KIVY_DOC' not in os.environ:
+    libmtdev = cdll.LoadLibrary('libmtdev.so.1')
 
 # from linux/input.h
 MTDEV_CODE_SLOT          = 0x2f  # MT slot being modified
@@ -122,14 +123,15 @@ class mtdev(Structure):
     ]
 
 # binding
-mtdev_open = libmtdev.mtdev_open
-mtdev_open.argtypes = [POINTER(mtdev), c_int]
-mtdev_get = libmtdev.mtdev_get
-mtdev_get.argtypes = [POINTER(mtdev), c_int, POINTER(input_event), c_int]
-mtdev_idle = libmtdev.mtdev_idle
-mtdev_idle.argtypes = [POINTER(mtdev), c_int, c_int]
-mtdev_close = libmtdev.mtdev_close
-mtdev_close.argtypes = [POINTER(mtdev)]
+if 'KIVY_DOC' not in os.environ:
+    mtdev_open = libmtdev.mtdev_open
+    mtdev_open.argtypes = [POINTER(mtdev), c_int]
+    mtdev_get = libmtdev.mtdev_get
+    mtdev_get.argtypes = [POINTER(mtdev), c_int, POINTER(input_event), c_int]
+    mtdev_idle = libmtdev.mtdev_idle
+    mtdev_idle.argtypes = [POINTER(mtdev), c_int, c_int]
+    mtdev_close = libmtdev.mtdev_close
+    mtdev_close.argtypes = [POINTER(mtdev)]
 
 
 class Device:


Test patch: