title: Proper way to copy configuration files during installation?
body: <p>I am trying to distribute a <code>mplstyle</code> I wrote such that I can share it easily. It boils down to copying a text file to the proper configuration direction (which is known for any architecture) during installation. I want to be able to install using either <code>python setup.py install</code> or <code>pip install ...</code>. Currently I do not seem to get either of the two ways robust (see current approach below).</p>
  
  <ul>
  <li>Installing with <code>pip install ...</code> does not seem to invoke the copying at all.</li>
  <li><p>Installing with <code>python setup.py install</code> works well on my machine, but ReadTheDocs gives me the following error:</p>
  
  <pre><code>python setup.py install --force
  
  running install
  error: [Errno 2] No such file or directory: u'/home/docs/.config/matplotlib/stylelib/goose.mplsty
  </code></pre></li>
  </ul>
  
  <p>What is the proper way to copy configuration files during installation in a robust way? </p>
  
  <h1>Current approach</h1>
  
  <h2>File structure</h2>
  
  <pre><code>setup.py
  goosempl/
  | __init__.py
  | stylelib/
    | goose.mplstyle
    | ...
  </code></pre>
  
  <h2><code>setup.py</code></h2>
  
  <pre><code>from setuptools                 import setup
  from setuptools.command.install import install
  
  class PostInstallCommand(install):
  
    def run(self):
  
      import goosempl
      goosempl.copy_style()
  
      install.run(self)
  
  setup(
    name              = 'goosempl',
    ...,
    install_requires  = ['matplotlib&gt;=2.0.0'],
    packages          = ['goosempl'],
    cmdclass          = {'install': PostInstallCommand},
    package_data      = {'goosempl/stylelib':['goosempl/stylelib/goose.mplstyle']},
  )
  </code></pre>
  
  <h2><code>goosempl/__init__.py</code></h2>
  
  <pre><code>def copy_style():
  
    import os
    import matplotlib
  
    from pkg_resources import resource_string
  
    files = [
      'stylelib/goose.mplstyle',
    ]
  
    for fname in files:
      path = os.path.join(matplotlib.get_configdir(),fname)
      text = resource_string(__name__,fname).decode()
  
      print(path, text)
  
      open(path,'w').write(text)
  </code></pre>
  
  <h2>Upload to PyPi</h2>
  
  <pre><code>python setup.py bdist_wheel --universal
  twine upload dist/*
  </code></pre>