Rev 4773: Mix BZR_CONCURRENCY and --concurrency so both are available. in file:///home/vila/src/bzr/reviews/concurrency_env_variable/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Dec 1 16:53:43 GMT 2009


At file:///home/vila/src/bzr/reviews/concurrency_env_variable/

------------------------------------------------------------
revno: 4773
revision-id: v.ladeuil+lp at free.fr-20091201165342-dlwehwo3cdfu59br
parent: mnordhoff at mattnordhoff.com-20091119184546-4xdqh54nxb3b8ts0
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: concurrency_env_variable
timestamp: Tue 2009-12-01 17:53:42 +0100
message:
  Mix BZR_CONCURRENCY and --concurrency so both are available.
  
  * bzrlib/tests/test_osutils.py:
  (TestConcurrency.setUp): Simplified.
  (TestConcurrency.test_local_concurrency_environment_variable):
  Restore the env varible tests.
  (TestConcurrency.test_option_concurrency): Test the global option.
  
  * bzrlib/tests/__init__.py:
  (TestCase._cleanEnvironment): Add BZR_CONCURRENCY.
  
  * bzrlib/osutils.py:
  (local_concurrency): Simplify implementation: environment variable
  overrides OS specific definition.
  
  * bzrlib/help_topics/__init__.py:
  (_env_variables): Restore the documentation.
  
  * bzrlib/commands.py:
  (run_bzr): Simplify --concurrency handling: it just overrides the
  environment variable.
-------------- next part --------------
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py	2009-11-19 18:45:46 +0000
+++ b/bzrlib/commands.py	2009-12-01 16:53:42 +0000
@@ -939,13 +939,16 @@
 
     --coverage
         Generate line coverage report in the specified directory.
+
+    --concurrency
+        Specify the number of processes that can be run concurrently.
     """
     argv = list(argv)
     trace.mutter("bzr arguments: %r", argv)
 
     opt_lsprof = opt_profile = opt_no_plugins = opt_builtin =  \
                 opt_no_aliases = False
-    opt_lsprof_file = opt_coverage_dir = opt_concurrency = None
+    opt_lsprof_file = opt_coverage_dir = None
 
     # --no-plugins is handled specially at a very early stage. We need
     # to load plugins before doing other command parsing so that they
@@ -970,14 +973,7 @@
         elif a == '--builtin':
             opt_builtin = True
         elif a == '--concurrency':
-            try:
-                opt_concurrency = int(argv[i + 1])
-            except ValueError:
-                raise errors.BzrCommandError(
-                    "--concurrency must be a number")
-            if opt_concurrency < 0:
-                raise errors.BzrCommandError(
-                    "--concurrency cannot be negative")
+            os.environ['BZR_CONCURRENCY'] = argv[i + 1]
             i += 1
         elif a == '--coverage':
             opt_coverage_dir = argv[i + 1]
@@ -988,9 +984,6 @@
             argv_copy.append(a)
         i += 1
 
-    if opt_concurrency is not None:
-        osutils._local_concurrency_override = opt_concurrency
-
     debug.set_debug_flags_from_config()
 
     argv = argv_copy

=== modified file 'bzrlib/help_topics/__init__.py'
--- a/bzrlib/help_topics/__init__.py	2009-11-12 00:35:05 +0000
+++ b/bzrlib/help_topics/__init__.py	2009-12-01 16:53:42 +0000
@@ -559,6 +559,7 @@
 BZR_SSH          SSH client: paramiko (default), openssh, ssh, plink.
 BZR_LOG          Location of .bzr.log (use '/dev/null' to suppress log).
 BZR_LOG (Win32)  Location of .bzr.log (use 'NUL' to suppress log).
+BZR_CONCURRENCY  Number of processes that can be run concurrently.
 ================ =================================================================
 """
 

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2009-11-12 00:35:05 +0000
+++ b/bzrlib/osutils.py	2009-12-01 16:53:42 +0000
@@ -1946,7 +1946,6 @@
 
 
 _cached_local_concurrency = None
-_local_concurrency_override = None
 
 def local_concurrency(use_cache=True):
     """Return how many processes can be run concurrently.
@@ -1956,16 +1955,15 @@
     """
     global _cached_local_concurrency
 
-    if _local_concurrency_override is not None:
-        return _local_concurrency_override
-
     if _cached_local_concurrency is not None and use_cache:
         return _cached_local_concurrency
 
-    try:
-        concurrency = _local_concurrency()
-    except (OSError, IOError):
-        concurrency = None
+    concurrency = os.environ.get('BZR_CONCURRENCY', None)
+    if concurrency is None:
+        try:
+            concurrency = _local_concurrency()
+        except (OSError, IOError):
+            pass
     try:
         concurrency = int(concurrency)
     except (TypeError, ValueError):

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2009-11-12 00:35:05 +0000
+++ b/bzrlib/tests/__init__.py	2009-12-01 16:53:42 +0000
@@ -1541,6 +1541,7 @@
             'BZR_PROGRESS_BAR': None,
             'BZR_LOG': None,
             'BZR_PLUGIN_PATH': None,
+            'BZR_CONCURRENCY': None,
             # Make sure that any text ui tests are consistent regardless of
             # the environment the test case is run in; you may want tests that
             # test other combinations.  'dumb' is a reasonable guess for tests

=== modified file 'bzrlib/tests/test_osutils.py'
--- a/bzrlib/tests/test_osutils.py	2009-11-12 00:35:05 +0000
+++ b/bzrlib/tests/test_osutils.py	2009-12-01 16:53:42 +0000
@@ -1837,23 +1837,29 @@
 
     def setUp(self):
         super(TestConcurrency, self).setUp()
-        self.saved_concurrency_override = osutils._local_concurrency_override
-        self.addCleanup(self.restore_concurrency_override)
-
-    def restore_concurrency_override(self):
-        osutils._local_concurrency_override = self.saved_concurrency_override
+        orig = osutils._cached_local_concurrency
+        def restore():
+            osutils._cached_local_concurrency = orig
+        self.addCleanup(restore)
 
     def test_local_concurrency(self):
         concurrency = osutils.local_concurrency()
         self.assertIsInstance(concurrency, int)
 
-    def test_local_concurrency_option(self):
-        osutils._local_concurrency_override = 2
-        self.assertEqual(2, osutils.local_concurrency(False))
-        osutils._local_concurrency_override = 3
-        self.assertEqual(3, osutils.local_concurrency(False))
-        #os.environ['BZR_CONCURRENCY'] = 'foo'
-        #self.assertEqual(1, osutils.local_concurrency(False))
+    def test_local_concurrency_environment_variable(self):
+        os.environ['BZR_CONCURRENCY'] = '2'
+        self.assertEqual(2, osutils.local_concurrency(use_cache=False))
+        os.environ['BZR_CONCURRENCY'] = '3'
+        self.assertEqual(3, osutils.local_concurrency(use_cache=False))
+        os.environ['BZR_CONCURRENCY'] = 'foo'
+        self.assertEqual(1, osutils.local_concurrency(use_cache=False))
+
+    def test_option_concurrency(self):
+        os.environ['BZR_CONCURRENCY'] = '1'
+        self.run_bzr('rocks --concurrency 42')
+        # Command line overrides envrionment variable
+        self.assertEquals('42', os.environ['BZR_CONCURRENCY'])
+        self.assertEquals(42, osutils.local_concurrency(use_cache=False))
 
 
 class TestFailedToLoadExtension(tests.TestCase):



More information about the bazaar-commits mailing list