@@ -52,7 +52,9 @@ class Distribution:
5252 ('quiet' , 'q' , "run quietly (turns verbosity off)" ),
5353 ('dry-run' , 'n' , "don't actually do anything" ),
5454 ('help' , 'h' , "show detailed help message" ),
55- ]
55+ ('no-user-cfg' , None ,
56+ 'ignore pydistutils.cfg in your home directory' ),
57+ ]
5658
5759 # 'common_usage' is a short (2-3 line) string describing the common
5860 # usage of the setup script.
@@ -259,6 +261,22 @@ def __init__ (self, attrs=None):
259261 else :
260262 sys .stderr .write (msg + "\n " )
261263
264+ # no-user-cfg is handled before other command line args
265+ # because other args override the config files, and this
266+ # one is needed before we can load the config files.
267+ # If attrs['script_args'] wasn't passed, assume false.
268+ #
269+ # This also make sure we just look at the global options
270+ self .want_user_cfg = True
271+
272+ if self .script_args is not None :
273+ for arg in self .script_args :
274+ if not arg .startswith ('-' ):
275+ break
276+ if arg == '--no-user-cfg' :
277+ self .want_user_cfg = False
278+ break
279+
262280 self .finalize_options ()
263281
264282 def get_option_dict (self , command ):
@@ -310,7 +328,10 @@ def find_config_files(self):
310328 Distutils installation directory (ie. where the top-level
311329 Distutils __inst__.py file lives), a file in the user's home
312330 directory named .pydistutils.cfg on Unix and pydistutils.cfg
313- on Windows/Mac, and setup.cfg in the current directory.
331+ on Windows/Mac; and setup.cfg in the current directory.
332+
333+ The file in the user's home directory can be disabled with the
334+ --no-user-cfg option.
314335 """
315336 files = []
316337 check_environ ()
@@ -330,15 +351,19 @@ def find_config_files(self):
330351 user_filename = "pydistutils.cfg"
331352
332353 # And look for the user config file
333- user_file = os .path .join (os .path .expanduser ('~' ), user_filename )
334- if os .path .isfile (user_file ):
335- files .append (user_file )
354+ if self .want_user_cfg :
355+ user_file = os .path .join (os .path .expanduser ('~' ), user_filename )
356+ if os .path .isfile (user_file ):
357+ files .append (user_file )
336358
337359 # All platforms support local setup.cfg
338360 local_file = "setup.cfg"
339361 if os .path .isfile (local_file ):
340362 files .append (local_file )
341363
364+ if DEBUG :
365+ self .announce ("using config files: %s" % ', ' .join (files ))
366+
342367 return files
343368
344369 def parse_config_files (self , filenames = None ):
0 commit comments