classification
Title: Option to ignore or substitute ~/.pydistutils.cfg
Type: feature request
Components: Distutils Versions: Python 2.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: hoffman, loewis, pfein, pje, slinkp
Priority: normal Keywords: easy, patch

Created on 2007-09-19 19:58 by hoffman, last changed 2008-06-25 21:56 by pje.

Files
File name Uploaded Description Edit Remove
python_distutils_1180.patch slinkp, 2008-04-27 17:54 patch with monkeypatches in setup/teardown
python_distutils_1180_2.patch slinkp, 2008-04-27 17:55 patch using dependency injection
python_distutils_1180_3.patch slinkp, 2008-04-28 14:33 patch w/ monkeypatches in setup, simplified
Messages
msg56044 (view) Author: Michael Hoffman (hoffman) Date: 2007-09-19 20:00
It would be useful if setup.py instances had an option to ignore
~/.pydistutils.cfg or substitute it with another file. For example, this
would be highly useful to people who maintain a system site-packages
directory along with one in their own home directory.
msg63685 (view) Author: Paul Winkler (slinkp) Date: 2008-03-17 17:29
I'm working on this (at the pycon sprint).
msg64041 (view) Author: Paul Winkler (slinkp) Date: 2008-03-19 05:16
The attached patch implements a command-line option to disable loading
of $HOME/.pydistutils.cfg.

After talking to Martin Loewis, I decided not to implement the override
part, because if it's a one-time thing you can just pass the settings on
the command line; and if you have two configurations you want to use
frequently, you can just use two user accounts.

The hard part was writing tests, since the existing code was untested
and is environment-sensitive. See the comments in the patch re. what I
still don't like about it. I would like to have a less evil test setup
and teardown, but I'm going on vacation tomorrow so I won't be able to
look at this again until April.
msg64047 (view) Author: Michael Hoffman (hoffman) Date: 2008-03-19 07:39
That is up to you of course, and being able to ignore is better than
nothing. But creating a new account is not really an option for
everyone. On the system I would like to use this feature the most, I am
not a system administrator, so I cannot create new user accounts. I
maintain a directory for production use of people in my workgroup. I
also maintain my own for testing and development.

Thanks for your work on this patch. At least being able to use
--no-user-cfg will be very helpful.
msg64054 (view) Author: Martin v. Löwis (loewis) Date: 2008-03-19 13:12
We thought that the added value for specifying another configuration 
file is relatively minor: if you have to set command line options 
anyway, just put anything you want to specify on the command line, 
rather than into the other configuration file.

Out of curiosity: what kinds of settings do you put into the 
configuration file?
msg64056 (view) Author: Michael Hoffman (hoffman) Date: 2008-03-19 14:06
Here's an example of a configuration file I use:

====
[build_ext]
include_dirs = /nfs/acari/mh5/include/python2.5:/nfs/acari/mh5/include

[install]
prefix = ~
exec_prefix = ~/arch/$ARCH
install_platlib = $platbase/lib/python$py_version_short
install_purelib = $base/lib/python$py_version_short
install_scripts = $platbase/bin

[easy_install]
install_dir = $platbase/lib/python$py_version_short
script_dir = $platbase/bin
====

I am installing software on a filesystem that is shared between
different architectures (i386 and x86_64), so I must have separate
directories for extensions on each platform. Because of this, using
--home=~ doesn't cut it.

I don't want to be a pain, if the --no-user-cfg can go in sooner, that
would be very helpful.
msg65783 (view) Author: Paul Winkler (slinkp) Date: 2008-04-25 14:16
Here's an alternate patch that uses a bit of dependency injection to
avoid the need for monkeypatches in setup/teardown. This means some
trivial changes to Distribution.__init__().  I slightly prefer this
approach, but some might argue it's an example of "test logic in
production".

I also added a line about the new option in Doc/install/index.rst.

Since I don't have checkin privileges, I will stop here. Can somebody
upstream (Martin?) please take one of these patches and apply it? Or
suggest further changes to either of these patches?  Or ... ?
Thanks.
msg65854 (view) Author: Phillip J. Eby (pje) Date: 2008-04-26 21:09
Both versions of the patch have a problem, in that the Distribution
object is looking for an option directly in sys.argv.  At the very
least, this should be looking at the 'script_args' attribute of the
Distribution instead (if not actually parsing the command line enough to
find the option).
msg65886 (view) Author: Paul Winkler (slinkp) Date: 2008-04-27 17:53
Phillip, thanks, I missed that script_args is always passed by
core.setup(). I'm replacing the patches with two new versions that check
self.script_args instead of sys.argv (and assumes false if for some
reason script_args isn't passed).

We can't check for it in Distribution.parse_command_line() because that
doesn't get called until after loading the config files.
msg65887 (view) Author: Paul Winkler (slinkp) Date: 2008-04-27 17:55
and here's the revised version of the dependency-injection approach.
msg65891 (view) Author: Phillip J. Eby (pje) Date: 2008-04-27 18:25
I much prefer the simpler of the two patches - better to monkeypatch in
the tests than adding complications to the already over-complicated
distutils.dist.  I don't find monkeypatching in tests to be horrible at
all, but if it really bothers you, just create a temporary directory for
HOME to point to, and test a Distribution subclass with an overridden
check_environ. 

By the way, the patch could be simpler if you just made the "if 'HOME'
in os.environ" read "if not self.no_user_cfg and 'HOME' in os.environ",
rather than reworking the entire code region.  On the other hand, if
you'd rather have ultra-clean unit tests, you could split the
functionality of find_config_files() into two methods: one that creates
the candidate list and the other that filters it by existence.

Personally, my vote is to keep the monkeypatching in the tests and make
the barest minimal changes to the Distribution class though.
msg65920 (view) Author: Paul Winkler (slinkp) Date: 2008-04-28 14:33
Phillip, here's another revision of the monkeypatch-in-setUp() approach,
simplified per your suggestions.
msg65921 (view) Author: Phillip J. Eby (pje) Date: 2008-04-28 15:49
It looks like you can drop the change to distutils.core, too, since 
it's just a change in the comment, and the changed comment is 
inaccurate, AFAICT.  Apart from that, it looks good.
msg65955 (view) Author: Paul Winkler (slinkp) Date: 2008-04-29 04:06
In what way is the comment in core.py inaccurate? I only added the
phrase "and override config files", which is an important side effect of
parse_command_line().
msg65967 (view) Author: Phillip J. Eby (pje) Date: 2008-04-29 13:58
Oh, I thought you meant that it overrides *which* config files -- 
i.e., implied that it was handling --no-user-config.
msg68739 (view) Author: Peter Fein (pfein) Date: 2008-06-25 17:47
Is this going to make the 2.6 release?  The lack of this option causes 
grief on MacPorts.  Just wondering if there's anything I could do to move 
this along, as a cursory reading shows everyone to be happy...
msg68755 (view) Author: Martin v. Löwis (loewis) Date: 2008-06-25 20:29
Formally, the beta deadline has passed, so no new features can be
admitted. If pje is now happy with the code as it stands (not clear from
the last message), I can ask for permission to commit it, anyway.
msg68761 (view) Author: Phillip J. Eby (pje) Date: 2008-06-25 21:56
I'm good with it; the issue with the comment in core.py was my only 
remaining objection.
History
Date User Action Args
2008-06-25 21:56:42pjesetmessages: + msg68761
2008-06-25 20:29:31loewissetmessages: + msg68755
2008-06-25 17:47:41pfeinsetnosy: + pfein
messages: + msg68739
2008-04-29 13:58:13pjesetmessages: + msg65967
2008-04-29 04:06:12slinkpsetmessages: + msg65955
2008-04-28 15:49:50pjesetmessages: + msg65921
2008-04-28 14:33:32slinkpsetfiles: + python_distutils_1180_3.patch
messages: + msg65920
2008-04-27 18:25:43pjesetmessages: + msg65891
2008-04-27 17:55:35slinkpsetfiles: + python_distutils_1180_2.patch
messages: + msg65887
2008-04-27 17:54:42slinkpsetfiles: - python_distutils_1180.patch
2008-04-27 17:54:25slinkpsetfiles: + python_distutils_1180.patch
messages: + msg65886
2008-04-27 17:15:34slinkpsetfiles: - python_distutils_1180_2.patch
2008-04-26 21:09:38pjesetnosy: + pje
messages: + msg65854
2008-04-25 14:16:56slinkpsetfiles: + python_distutils_1180_2.patch
messages: + msg65783
2008-03-19 14:06:55hoffmansetmessages: + msg64056
2008-03-19 13:12:28loewissetmessages: + msg64054
2008-03-19 07:39:32hoffmansetmessages: + msg64047
2008-03-19 05:20:09slinkpsetfiles: + python_distutils_1180.patch
2008-03-19 05:19:28slinkpsetfiles: - python_distutils_1180.patch
2008-03-19 05:16:36slinkpsetfiles: + python_distutils_1180.patch
keywords: + patch
messages: + msg64041
2008-03-18 16:45:48slinkpsetnosy: + loewis
2008-03-17 17:29:14slinkpsetnosy: + slinkp
messages: + msg63685
2008-01-12 01:58:10christian.heimessetkeywords: + easy
2007-09-19 20:14:03jafosetpriority: normal
2007-09-19 20:00:26hoffmansettitle: Option to ignore ~/.pydistutils.cfg -> Option to ignore or substitute ~/.pydistutils.cfg
2007-09-19 20:00:08hoffmansetnosy: + hoffman
messages: + msg56044
2007-09-19 19:58:22hoffmancreate