0

I would like to install a config file in a users .config directory. I've tried

# setup.py
from setuptools import setup
import os

setup(
  # ...
  data_files=[(
    '{}/.config/foobar/'.format(os.environ['HOME']), 
    ['config/foobar.config']
  )]
)

but this strips the leading / and installs the file at

$HOME/.local/lib/python3.8/site-packages/home/johndoe/.config/foobar/foobar.config

How to install into the ~/.config dir? Bonus points if it works with a setup.cfg file.

Nico Schlömer
  • 53,797
  • 27
  • 201
  • 249
  • 2
    If pip installation would be able to write to absolute paths at install time, it would be quite a big security hole. I'd personally consider doing that the bootstrap phase of your code by checking if the foobar/foobar.config exists before it is loaded and write it then .. – rasjani Apr 30 '20 at 14:46
  • I'd also have to check if the contents are equal, for updates. This is less than ideal. – Nico Schlömer Apr 30 '20 at 16:03
  • 1
    Check out [Copy configuration file on installation](https://stackoverflow.com/q/47460804/2650249). tl;dr: don't try copying files outside of site dir on installation. Instead, install new config template, check whether current config is up to date on program start, if not, copy new config over. – hoefling Apr 30 '20 at 21:27

0 Answers0