[setuptools] install data-file in users home-dir

Chris Warrick 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
>
> setup(...,
>       data_files = [ ('~/.config/appname/', ['app.conf']) ]
>      )
>
> I see two problems here:
>
> 1.
> 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.

> 2.
> 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.
> --
> https://mail.python.org/mailman/listinfo/python-list

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/>
PGP: 5EAAEA16


More information about the Python-list mailing list