[setuptools] install data-file in users home-dir
kwpolska at gmail.com
Fri Jul 10 09:39:35 CEST 2015
On 10 July 2015 at 03:11, <c.buhtz at posteo.jp> wrote:
> I am using setuptools to create a wheel file.
> There is a conf-file I want to install into the users config-diretory.
> e.g. /home/user/.config/appname/app.conf
> data_files = [ ('~/.config/appname/', ['app.conf']) ]
> I see two problems here:
> I don't know the users "name". So I have to use a placeholder here.
> Does '~' work here in that case?
It doesn’t. You would have to use os.path.expanduser, but don’t do that.
> To install the wheel-file with pip I need sudo-privilegs on Ubuntu
> 14.04.2. That means while the install script runs I can not ask for the
> users name because it is "root" in that case.
You should NEVER use sudo with pip. Instead, use virtualenvs as a
regular user, or create your own .deb packages.
And you should not create the files in your install script. Instead,
install them to a different data dir (somewhere in 'share/appname', or
alongside your package). When someone runs your app, only then you
should copy this file to user’s config directory (use pkg_resources to
help you get it) if it does not exist yet.
Chris Warrick <https://chriswarrick.com/>
More information about the Python-list