]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #19544 and Issue #1180: Restore global option to ignore ~/.pydistutils.cfg...
authorAndrew Kuchling <amk@amk.ca>
Sun, 10 Nov 2013 23:11:00 +0000 (18:11 -0500)
committerAndrew Kuchling <amk@amk.ca>
Sun, 10 Nov 2013 23:11:00 +0000 (18:11 -0500)
Doc/distutils/builtdist.rst
Lib/distutils/core.py
Lib/distutils/dist.py
Lib/distutils/tests/test_dist.py
Misc/NEWS

index d1ab7dbce9292d57931e3dada687f090414f7c38..83c68ae20c75fda51b54b8b37d748f5e948e1b77 100644 (file)
@@ -239,7 +239,8 @@ tedious and error-prone, so it's usually best to put them in the setup
 configuration file, :file:`setup.cfg`\ ---see section :ref:`setup-config`.  If
 you distribute or package many Python module distributions, you might want to
 put options that apply to all of them in your personal Distutils configuration
-file (:file:`~/.pydistutils.cfg`).
+file (:file:`~/.pydistutils.cfg`).  If you want to temporarily disable
+this file, you can pass the :option:`--no-user-cfg` option to :file:`setup.py`.
 
 There are three steps to building a binary RPM package, all of which are
 handled automatically by the Distutils:
index 91e5132934bd071fb526f138bb8b91603cd0f958..c811d5bd9c46892661f47b19ef9b56e5632e824d 100644 (file)
@@ -128,8 +128,9 @@ def setup (**attrs):
     if _setup_stop_after == "config":
         return dist
 
-    # Parse the command line; any command-line errors are the end user's
-    # fault, so turn them into SystemExit to suppress tracebacks.
+    # Parse the command line and override config files; any
+    # command-line errors are the end user's fault, so turn them into
+    # SystemExit to suppress tracebacks.
     try:
         ok = dist.parse_command_line()
     except DistutilsArgError as msg:
index 11a210279e96e36964d46e0c78449c3c749a9bfc..7eb04bc3f59814355325f5fbb87e2dd75e1ecfff 100644 (file)
@@ -52,7 +52,9 @@ class Distribution:
                       ('quiet', 'q', "run quietly (turns verbosity off)"),
                       ('dry-run', 'n', "don't actually do anything"),
                       ('help', 'h', "show detailed help message"),
-                     ]
+                      ('no-user-cfg', None,
+                       'ignore pydistutils.cfg in your home directory'),
+    ]
 
     # 'common_usage' is a short (2-3 line) string describing the common
     # usage of the setup script.
@@ -259,6 +261,22 @@ Common commands: (see '--help-commands' for more)
                     else:
                         sys.stderr.write(msg + "\n")
 
+        # no-user-cfg is handled before other command line args
+        # because other args override the config files, and this
+        # one is needed before we can load the config files.
+        # If attrs['script_args'] wasn't passed, assume false.
+        #
+        # This also make sure we just look at the global options
+        self.want_user_cfg = True
+
+        if self.script_args is not None:
+            for arg in self.script_args:
+                if not arg.startswith('-'):
+                    break
+                if arg == '--no-user-cfg':
+                    self.want_user_cfg = False
+                    break
+
         self.finalize_options()
 
     def get_option_dict(self, command):
@@ -310,7 +328,10 @@ Common commands: (see '--help-commands' for more)
         Distutils installation directory (ie. where the top-level
         Distutils __inst__.py file lives), a file in the user's home
         directory named .pydistutils.cfg on Unix and pydistutils.cfg
-        on Windows/Mac, and setup.cfg in the current directory.
+        on Windows/Mac; and setup.cfg in the current directory.
+
+        The file in the user's home directory can be disabled with the
+        --no-user-cfg option.
         """
         files = []
         check_environ()
@@ -330,15 +351,19 @@ Common commands: (see '--help-commands' for more)
             user_filename = "pydistutils.cfg"
 
         # And look for the user config file
-        user_file = os.path.join(os.path.expanduser('~'), user_filename)
-        if os.path.isfile(user_file):
-            files.append(user_file)
+        if self.want_user_cfg:
+            user_file = os.path.join(os.path.expanduser('~'), user_filename)
+            if os.path.isfile(user_file):
+                files.append(user_file)
 
         # All platforms support local setup.cfg
         local_file = "setup.cfg"
         if os.path.isfile(local_file):
             files.append(local_file)
 
+        if DEBUG:
+            self.announce("using config files: %s" % ', '.join(files))
+
         return files
 
     def parse_config_files(self, filenames=None):
index 9a8ca19902d464848b7ed1b7e3bb22a686cfe645..102c553db979724b669df63702200992bc6af0b0 100644 (file)
@@ -39,6 +39,7 @@ class TestDistribution(Distribution):
 
 
 class DistributionTestCase(support.LoggingSilencer,
+                           support.TempdirManager,
                            support.EnvironGuard,
                            unittest.TestCase):
 
@@ -213,6 +214,34 @@ class DistributionTestCase(support.LoggingSilencer,
         self.assertRaises(ValueError, dist.announce, args, kwargs)
 
 
+    def test_find_config_files_disable(self):
+        # Ticket #1180: Allow user to disable their home config file.
+        temp_home = self.mkdtemp()
+        if os.name == 'posix':
+            user_filename = os.path.join(temp_home, ".pydistutils.cfg")
+        else:
+            user_filename = os.path.join(temp_home, "pydistutils.cfg")
+
+        with open(user_filename, 'w') as f:
+            f.write('[distutils]\n')
+
+        def _expander(path):
+            return temp_home
+
+        old_expander = os.path.expanduser
+        os.path.expanduser = _expander
+        try:
+            d = Distribution()
+            all_files = d.find_config_files()
+
+            d = Distribution(attrs={'script_args': ['--no-user-cfg']})
+            files = d.find_config_files()
+        finally:
+            os.path.expanduser = old_expander
+
+        # make sure --no-user-cfg disables the user cfg file
+        self.assertEquals(len(all_files)-1, len(files))
+
 class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
                        unittest.TestCase):
 
index dddf7ca02d333726ce920ffcf374c17f693ee461..0cfdd133115d47b43f53e52927e22e003d743104 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -47,6 +47,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #19544 and Issue #1180: Restore global option to ignore
+  ~/.pydistutils.cfg in Distutils, accidentally removed in backout of
+  distutils2 changes.
+
 - Issue #19523: Closed FileHandler leak which occurred when delay was set.
 
 - Issue #19544 and #6516: Restore support for --user and --group parameters to