title: How to build sphinx docs for micropython
body: <p>How do I configure sphinx to document modules intended for a MicroPython interpreter?</p>
  
  <p>The fundamental problem I'm facing is that sphinx gets the information it documents from the imported module. Therefore the python interpreter used to document a module must be importable into <em>that</em> interpreter.</p>
  
  <p><strong>First Problem</strong></p>
  
  <p>I'm using a pyboard, so naturally</p>
  
  <pre class="lang-py prettyprint-override"><code>import pyb
  </code></pre>
  
  <p>cannot find module <code>pyb</code>...
  So I added to <code>conf.py</code></p>
  
  <pre class="lang-py prettyprint-override"><code>from unittest.mock import MagicMock
  sys.modules['pyb'] = MagicMock()  # and many more
  </code></pre>
  
  <p><strong>Second Problem</strong></p>
  
  <p>One of my MicroPython libraries is called <code>cmd</code></p>
  
  <pre><code>Exception occurred:
    File "/usr/lib/python3.5/pdb.py", line 135, in &lt;module&gt;
      class Pdb(bdb.Bdb, cmd.Cmd):
  AttributeError: module 'cmd' has no attribute 'Cmd'
  </code></pre>
  
  <p>So that makes sense... I changed the name of the module to <code>ucmd</code>, and that appears to be working... but it's suuuuuper dodgy.</p>
  
  <p><strong>Question</strong></p>
  
  <p>Is there a <em>proper</em> way to do this?
  To sphinx document a module <em>not designed</em> for the platform running the <code>sphinx-build</code> command?</p>
  
  <p>Phrased more practically: if I wanted to document a MicroPython module called <code>collections</code>, <code>subprocess</code>, or <code>io</code> (all of which are used by the <code>sphinx</code> library), is it possible to use sphinx to do so?</p>
  
  <p>Or would I simply have to be content with naming them <code>ucollections</code>, <code>usubprocess</code>, and <code>uio</code> respectively?</p>