@@ -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 ):
0 commit comments