Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93627

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

References <3mSGXb0tfQzFpW3@dovecot04.posteo.de>
Date 2015-07-10 09:39 +0200
Subject Re: [setuptools] install data-file in users home-dir
From Chris Warrick <kwpolska@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.388.1436513985.3674.python-list@python.org> (permalink)

Show all headers | View raw


On 10 July 2015 at 03:11,  <c.buhtz@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: [setuptools] install data-file in users home-dir Chris Warrick <kwpolska@gmail.com> - 2015-07-10 09:39 +0200

csiph-web