title: Avoiding pylint complaints when importing Python packages from submodules
body: <p><strong>Background</strong></p>
  
  <p>I have a Python application dependent upon another package which is provided as a git submodule, yielding a directory structure similar to the following:</p>
  
  <pre><code>foo/
      bar/
          bar/
              __init__.py
              eggs.py
          test/
          setup.py
      foo/
          __init__.py
          ham.py
      main.py
  </code></pre>
  
  <p>Accessing the <code>foo</code> package is simple enough, as <code>main.py</code> is executed from the toplevel <code>foo/</code> directory; but the <code>bar</code> package is nested within another <code>bar</code> directory and is not directly importable.</p>
  
  <p>This is solvable readily enough, by modifying <code>sys.path</code> at the beginning of <code>main.py</code>:</p>
  
  <pre><code>import sys
  
  # Or sys.path.append()
  sys.path.insert(0, './bar')
  
  from bar.eggs import Eggs
  from foo.ham import Ham
  </code></pre>
  
  <p>(Note: this code example assumes that <code>main.py</code> will always be invoked from <code>foo/</code>; in cases where this may not be the case, <code>'.bar'</code> could be replaced with <code>os.path.join(os.path.dirname(__file__), 'bar')</code> though this is clearly more unwieldy.)</p>
  
  <p><strong>The Problem</strong></p>
  
  <p>Unfortunately, pylint doesn't like this solution. While the code works, the linter considers the <code>sys.path</code> modifications to be a block of code ending the "top of the module" and gives an undesirable <code>wrong-import-position</code> warning:</p>
  
  <pre><code>C: 6, 0: Import "from bar.eggs import Eggs" should be placed at the top of the module (wrong-import-position)
  C: 7, 0: Import "from foo.ham import Ham" should be placed at the top of the module (wrong-import-position)
  </code></pre>
  
  <hr>
  
  <p><strong>Similar questions</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/44732819/adding-a-path-to-sys-path-in-python-and-pylint">Adding a path to sys.path in python and pylint</a></p>
  
  <p>This questioner has an issue with pylint failing to correctly parse the imports altogether. The lone answer to the this question suggests adding to pylint's internal path; this does nothing to avoid complaints about an interleaved <code>sys.path</code> modification.</p>