Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c7c71ff

Browse files
author
Tarek Ziadé
committed
Merged revisions 75893 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r75893 | tarek.ziade | 2009-10-28 00:06:10 +0100 (Wed, 28 Oct 2009) | 1 line Fixed #1180: Option to ignore ~/.pydistutils.cfg in Distutils ........
1 parent 70ec8ee commit c7c71ff

7 files changed

Lines changed: 73 additions & 9 deletions

File tree

Doc/ACKS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ [email protected]), and we'll be glad to correct the problem.
208208
* Mats Wichmann
209209
* Gerry Wiener
210210
* Timothy Wild
211+
* Paul Winkler
211212
* Collin Winter
212213
* Blake Winton
213214
* Dan Wolfe

Doc/distutils/builtdist.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ tedious and error-prone, so it's usually best to put them in the setup
241241
configuration file, :file:`setup.cfg`\ ---see section :ref:`setup-config`. If
242242
you distribute or package many Python module distributions, you might want to
243243
put options that apply to all of them in your personal Distutils configuration
244-
file (:file:`~/.pydistutils.cfg`).
244+
file (:file:`~/.pydistutils.cfg`). If you want to temporarily disable
245+
this file, you can pass the --no-user-cfg option to setup.py.
245246

246247
There are three steps to building a binary RPM package, all of which are
247248
handled automatically by the Distutils:

Doc/install/index.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,9 @@ And on Windows, the configuration files are:
691691
| local | :file:`setup.cfg` | \(3) |
692692
+--------------+-------------------------------------------------+-------+
693693

694+
On all platforms, the "personal" file can be temporarily disabled by
695+
passing the `--no-user-cfg` option.
696+
694697
Notes:
695698

696699
(1)

Lib/distutils/core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ class found in 'cmdclass' is used in place of the default, which is
129129
if _setup_stop_after == "config":
130130
return dist
131131

132-
# Parse the command line; any command-line errors are the end user's
133-
# fault, so turn them into SystemExit to suppress tracebacks.
132+
# Parse the command line and override config files; any
133+
# command-line errors are the end user's fault, so turn them into
134+
# SystemExit to suppress tracebacks.
134135
try:
135136
ok = dist.parse_command_line()
136137
except DistutilsArgError as msg:

Lib/distutils/dist.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ class Distribution:
5353
('quiet', 'q', "run quietly (turns verbosity off)"),
5454
('dry-run', 'n', "don't actually do anything"),
5555
('help', 'h', "show detailed help message"),
56-
]
56+
('no-user-cfg', None,
57+
'ignore pydistutils.cfg in your home directory'),
58+
]
5759

5860
# 'common_usage' is a short (2-3 line) string describing the common
5961
# usage of the setup script.
@@ -260,6 +262,22 @@ def __init__ (self, attrs=None):
260262
else:
261263
sys.stderr.write(msg + "\n")
262264

265+
# no-user-cfg is handled before other command line args
266+
# because other args override the config files, and this
267+
# one is needed before we can load the config files.
268+
# If attrs['script_args'] wasn't passed, assume false.
269+
#
270+
# This also make sure we just look at the global options
271+
self.want_user_cfg = True
272+
273+
if self.script_args is not None:
274+
for arg in self.script_args:
275+
if not arg.startswith('-'):
276+
break
277+
if arg == '--no-user-cfg':
278+
self.want_user_cfg = False
279+
break
280+
263281
self.finalize_options()
264282

265283
def get_option_dict(self, command):
@@ -311,7 +329,10 @@ def find_config_files(self):
311329
Distutils installation directory (ie. where the top-level
312330
Distutils __inst__.py file lives), a file in the user's home
313331
directory named .pydistutils.cfg on Unix and pydistutils.cfg
314-
on Windows/Mac, and setup.cfg in the current directory.
332+
on Windows/Mac; and setup.cfg in the current directory.
333+
334+
The file in the user's home directory can be disabled with the
335+
--no-user-cfg option.
315336
"""
316337
files = []
317338
check_environ()
@@ -331,15 +352,19 @@ def find_config_files(self):
331352
user_filename = "pydistutils.cfg"
332353

333354
# And look for the user config file
334-
user_file = os.path.join(os.path.expanduser('~'), user_filename)
335-
if os.path.isfile(user_file):
336-
files.append(user_file)
355+
if self.want_user_cfg:
356+
user_file = os.path.join(os.path.expanduser('~'), user_filename)
357+
if os.path.isfile(user_file):
358+
files.append(user_file)
337359

338360
# All platforms support local setup.cfg
339361
local_file = "setup.cfg"
340362
if os.path.isfile(local_file):
341363
files.append(local_file)
342364

365+
if DEBUG:
366+
self.announce("using config files: %s" % ', '.join(files))
367+
343368
return files
344369

345370
def parse_config_files(self, filenames=None):

Lib/distutils/tests/test_dist.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def find_config_files(self):
3737
return self._config_files
3838

3939

40-
class DistributionTestCase(support.LoggingSilencer,
40+
class DistributionTestCase(support.TempdirManager,
41+
support.LoggingSilencer,
4142
support.EnvironGuard,
4243
unittest.TestCase):
4344

@@ -180,6 +181,35 @@ def test_announce(self):
180181
kwargs = {'level': 'ok2'}
181182
self.assertRaises(ValueError, dist.announce, args, kwargs)
182183

184+
def test_find_config_files_disable(self):
185+
# Ticket #1180: Allow user to disable their home config file.
186+
temp_home = self.mkdtemp()
187+
if os.name == 'posix':
188+
user_filename = os.path.join(temp_home, ".pydistutils.cfg")
189+
else:
190+
user_filename = os.path.join(temp_home, "pydistutils.cfg")
191+
192+
with open(user_filename, 'w') as f:
193+
f.write('[distutils]\n')
194+
195+
def _expander(path):
196+
return temp_home
197+
198+
old_expander = os.path.expanduser
199+
os.path.expanduser = _expander
200+
try:
201+
d = distutils.dist.Distribution()
202+
all_files = d.find_config_files()
203+
204+
d = distutils.dist.Distribution(attrs={'script_args':
205+
['--no-user-cfg']})
206+
files = d.find_config_files()
207+
finally:
208+
os.path.expanduser = old_expander
209+
210+
# make sure --no-user-cfg disables the user cfg file
211+
self.assertEquals(len(all_files)-1, len(files))
212+
183213
class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
184214
unittest.TestCase):
185215

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ C-API
117117
Library
118118
-------
119119

120+
- Issue #1180: Added a new global option to ignore ~/.pydistutils.cfg in
121+
Distutils.
122+
120123
- Issue #7218: Fix test_site for win32, the directory comparison was done with
121124
an uppercase.
122125

0 commit comments

Comments
 (0)