distribute / setuptools / tests / test_easy_install.py

The branch 'default' does not exist.
tarek 70526ce 

tarek 7dea3f1 
Jason R. Coombs 90ae16b 



Ronny Pfannschmi… 3ea27d2 
Jason R. Coombs 06f2cf0 
Jason R. Coombs 342e978 
Jason R. Coombs 8f93340 
Jason R. Coombs 60aeb2c 
Jason R. Coombs 94e2308 
Jason R. Coombs 90ae16b 
Erik Bray 4f7c0c7 
tarek bdbddd9 
Ronny Pfannschmi… 9b52947 
Ronny Pfannschmi… 3ea27d2 
tarek 70526ce 
Erik Bray 98a9f9d 
Ronny Pfannschmi… 9b52947 
Jason R. Coombs 6bd872c 
Erik Bray 98a9f9d 
tarek 70526ce 
Tarek Ziadé 8cfcd77 
Jason R. Coombs 90ae16b 

Tarek Ziadé 8cfcd77 







tarek 7dea3f1 





















tarek bdbddd9 





tarek 70526ce 









Lennart Regebro c28e86d 
tarek 70526ce 


tarek 7dea3f1 




guyroz aa59f50 
tarek 7dea3f1 


Lennart Regebro c28e86d 
tarek 7dea3f1 
tarek bdbddd9 


















Jason R. Coombs 45912a9 
tarek bdbddd9 






Erik Bray 4f7c0c7 


tarek bdbddd9 


Jason R. Coombs 45912a9 
tarek bdbddd9 
Tarek Ziadé 1cec439 




Jason R. Coombs 90ae16b 
Tarek Ziadé 1cec439 




Lennart Regebro c28e86d 
Tarek Ziadé 1cec439 


Jason R. Coombs 90ae16b 
Tarek Ziadé 1cec439 





Lennart Regebro c28e86d 
Tarek Ziadé 1cec439 

Ronny Pfannschmi… 9b52947 

Tarek Ziadé 2878280 
Ronny Pfannschmi… 9b52947 


Lennart Regebro c28e86d 
Ronny Pfannschmi… 9b52947 
Lennart Regebro c28e86d 
Ronny Pfannschmi… 9b52947 

guyroz c75973e 




Lennart Regebro c28e86d 
guyroz c75973e 
Lennart Regebro c28e86d 
Ronny Pfannschmi… 9b52947 
Ronny Pfannschmi… 3ea27d2 











Ronny Pfannschmi… 129e2f3 
Ronny Pfannschmi… d5a9297 
Ronny Pfannschmi… 3ea27d2 
Ronny Pfannschmi… 8dcf337 
Ronny Pfannschmi… 3ea27d2 
Ronny Pfannschmi… 8dcf337 
Ronny Pfannschmi… d5a9297 
Ronny Pfannschmi… 3ea27d2 



Jason R. Coombs 90ae16b 
Ronny Pfannschmi… 3ea27d2 

Ronny Pfannschmi… 8dcf337 

Ronny Pfannschmi… 129e2f3 
Ronny Pfannschmi… d5a9297 
Ronny Pfannschmi… 3ea27d2 
Ronny Pfannschmi… 633c6df 
Ronny Pfannschmi… 129e2f3 
Ronny Pfannschmi… 8dcf337 
Ronny Pfannschmi… 3ea27d2 
Ronny Pfannschmi… d5a9297 
Ronny Pfannschmi… 3ea27d2 


Ronny Pfannschmi… 8dcf337 
Ronny Pfannschmi… 3ea27d2 
Ronny Pfannschmi… d5a9297 

Tarek Ziadé 8cfcd77 




Ronny Pfannschmi… 633c6df 
Ronny Pfannschmi… 129e2f3 
Ronny Pfannschmi… 633c6df 








Tarek Ziadé aa5216d 










Arfrever Frehtes… 5061b9e 
Tarek Ziadé aa5216d 



guyroz c75973e 
Tarek Ziadé aa5216d 








Lennart Regebro 9498c59 
Erik Bray 4f7c0c7 
Tarek Ziadé aa5216d 

guyroz c75973e 






Tarek Ziadé aa5216d 



Jason R. Coombs 6bd872c 
Erik Bray 4f7c0c7 







Erik Bray 98a9f9d 

Erik Bray 4f7c0c7 

Erik Bray 98a9f9d 



Erik Bray 4f7c0c7 


Jason R. Coombs 6bd872c 










Jason R. Coombs 8f93340 
Jason R. Coombs b69f072 

Jason R. Coombs 0b9206f 



Jason R. Coombs b743987 









Jason R. Coombs 06f2cf0 
Jason R. Coombs 8f93340 
Jason R. Coombs 06f2cf0 

Jason R. Coombs b743987 

Jason R. Coombs 94e2308 



Jason R. Coombs b743987 





Erik Bray 98a9f9d 
Jason R. Coombs b743987 
Jason R. Coombs 489d366 

Lennart Regebro c28e86d 
Jason R. Coombs 8f93340 
Jason R. Coombs 6bd872c 
Jason R. Coombs b743987 
Jason R. Coombs 06f2cf0 
Jason R. Coombs b743987 

Jason R. Coombs 06f2cf0 
Jason R. Coombs b743987 

Erik Bray 4f7c0c7 









Jason R. Coombs b743987 

Jason R. Coombs 06f2cf0 
Erik Bray 98a9f9d 




























Arfrever Frehtes… 407c037 
Arfrever Frehtes… 5061b9e 
Erik Bray 98a9f9d 











































Erik Bray 4f7c0c7 




















Jason R. Coombs b743987 



Jason R. Coombs 6bd872c 
Jason R. Coombs 06f2cf0 
Jason R. Coombs 6bd872c 
Jason R. Coombs 06f2cf0 
Jason R. Coombs b743987 
Jason R. Coombs 6bd872c 
Jason R. Coombs 06f2cf0 
Jason R. Coombs 6bd872c 

Erik Bray 98a9f9d 
Jason R. Coombs b743987 



Jason R. Coombs 6bd872c 


Jason R. Coombs b743987 
Jason R. Coombs 6bd872c 



Jason R. Coombs 101e09a 
Erik Bray 98a9f9d 
Jason R. Coombs b743987 



Jason R. Coombs 101e09a 

Jason R. Coombs b743987 



Jason R. Coombs 94e2308 
Erik Bray 98a9f9d 
Jason R. Coombs b743987 
Jason R. Coombs 94e2308 







Jason R. Coombs b743987 



Erik Bray 98a9f9d 
















  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
"""Easy install Tests
"""
import sys
import os
import shutil
import tempfile
import unittest
import site
import textwrap
import tarfile
import urlparse
import StringIO
import distutils.core

from setuptools.sandbox import run_setup, SandboxViolation
from setuptools.command.easy_install import easy_install, get_script_args, main
from setuptools.command.easy_install import  PthDistributions
from setuptools.command import easy_install as easy_install_pkg
from setuptools.dist import Distribution
from pkg_resources import working_set, VersionConflict
from pkg_resources import Distribution as PRDistribution
import setuptools.tests.server
import pkg_resources

try:
    # import multiprocessing solely for the purpose of testing its existence
    __import__('multiprocessing')
    import logging
    _LOG = logging.getLogger('test_easy_install')
    logging.basicConfig(level=logging.INFO, stream=sys.stderr)
    _MULTIPROC = True
except ImportError:
    _MULTIPROC = False
    _LOG = None

class FakeDist(object):
    def get_entry_map(self, group):
        if group != 'console_scripts':
            return {}
        return {'name': 'ep'}

    def as_requirement(self):
        return 'spec'

WANTED = """\
#!%s
# EASY-INSTALL-ENTRY-SCRIPT: 'spec','console_scripts','name'
__requires__ = 'spec'
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.exit(
        load_entry_point('spec', 'console_scripts', 'name')()
    )
""" % sys.executable

SETUP_PY = """\
from setuptools import setup

setup(name='foo')
"""

class TestEasyInstallTest(unittest.TestCase):

    def test_install_site_py(self):
        dist = Distribution()
        cmd = easy_install(dist)
        cmd.sitepy_installed = False
        cmd.install_dir = tempfile.mkdtemp()
        try:
            cmd.install_site_py()
            sitepy = os.path.join(cmd.install_dir, 'site.py')
            self.assertTrue(os.path.exists(sitepy))
        finally:
            shutil.rmtree(cmd.install_dir)

    def test_get_script_args(self):
        dist = FakeDist()

        old_platform = sys.platform
        try:
            name, script = [i for i in get_script_args(dist).next()][0:2]
        finally:
            sys.platform = old_platform

        self.assertEqual(script, WANTED)

    def test_no_setup_cfg(self):
        # makes sure easy_install as a command (main)
        # doesn't use a setup.cfg file that is located
        # in the current working directory
        dir = tempfile.mkdtemp()
        setup_cfg = open(os.path.join(dir, 'setup.cfg'), 'w')
        setup_cfg.write('[easy_install]\nfind_links = http://example.com')
        setup_cfg.close()
        setup_py = open(os.path.join(dir, 'setup.py'), 'w')
        setup_py.write(SETUP_PY)
        setup_py.close()

        from setuptools.dist import Distribution

        def _parse_command_line(self):
            msg = 'Error: a local setup.cfg was used'
            opts = self.command_options
            if 'easy_install' in opts:
                assert 'find_links' not in opts['easy_install'], msg
            return self._old_parse_command_line()

        Distribution._old_parse_command_line = Distribution.parse_command_line
        Distribution.parse_command_line = _parse_command_line

        old_wd = os.getcwd()
        try:
            os.chdir(dir)
            reset_setup_stop_context(
                lambda: self.assertRaises(SystemExit, main, [])
            )
        finally:
            os.chdir(old_wd)
            shutil.rmtree(dir)
            Distribution.parse_command_line = Distribution._old_parse_command_line

    def test_no_find_links(self):
        # new option '--no-find-links', that blocks find-links added at
        # the project level
        dist = Distribution()
        cmd = easy_install(dist)
        cmd.check_pth_processing = lambda: True
        cmd.no_find_links = True
        cmd.find_links = ['link1', 'link2']
        cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
        cmd.args = ['ok']
        cmd.ensure_finalized()
        self.assertEqual(cmd.package_index.scanned_urls, {})

        # let's try without it (default behavior)
        cmd = easy_install(dist)
        cmd.check_pth_processing = lambda: True
        cmd.find_links = ['link1', 'link2']
        cmd.install_dir = os.path.join(tempfile.mkdtemp(), 'ok')
        cmd.args = ['ok']
        cmd.ensure_finalized()
        keys = cmd.package_index.scanned_urls.keys()
        keys.sort()
        self.assertEqual(keys, ['link1', 'link2'])


class TestPTHFileWriter(unittest.TestCase):
    def test_add_from_cwd_site_sets_dirty(self):
        '''a pth file manager should set dirty
        if a distribution is in site but also the cwd
        '''
        pth = PthDistributions('does-not_exist', [os.getcwd()])
        self.assertTrue(not pth.dirty)
        pth.add(PRDistribution(os.getcwd()))
        self.assertTrue(pth.dirty)

    def test_add_from_site_is_ignored(self):
        if os.name != 'nt':
            location = '/test/location/does-not-have-to-exist'
        else:
            location = 'c:\\does_not_exist'
        pth = PthDistributions('does-not_exist', [location, ])
        self.assertTrue(not pth.dirty)
        pth.add(PRDistribution(location))
        self.assertTrue(not pth.dirty)


class TestUserInstallTest(unittest.TestCase):

    def setUp(self):
        self.dir = tempfile.mkdtemp()
        setup = os.path.join(self.dir, 'setup.py')
        f = open(setup, 'w')
        f.write(SETUP_PY)
        f.close()
        self.old_cwd = os.getcwd()
        os.chdir(self.dir)
        if sys.version >= "2.6":
            self.old_has_site = easy_install_pkg.HAS_USER_SITE
            self.old_file = easy_install_pkg.__file__
            self.old_base = site.USER_BASE
            site.USER_BASE = tempfile.mkdtemp()
            self.old_site = site.USER_SITE
            site.USER_SITE = tempfile.mkdtemp()
            easy_install_pkg.__file__ = site.USER_SITE

    def tearDown(self):
        os.chdir(self.old_cwd)
        shutil.rmtree(self.dir)
        if sys.version >= "2.6":
            shutil.rmtree(site.USER_BASE)
            shutil.rmtree(site.USER_SITE)
            site.USER_BASE = self.old_base
            site.USER_SITE = self.old_site
            easy_install_pkg.HAS_USER_SITE = self.old_has_site
            easy_install_pkg.__file__ = self.old_file

    def test_user_install_implied(self):
        easy_install_pkg.HAS_USER_SITE = True # disabled sometimes
        #XXX: replace with something meaningfull
        if sys.version < "2.6":
            return #SKIP
        dist = Distribution()
        dist.script_name = 'setup.py'
        cmd = easy_install(dist)
        cmd.args = ['py']
        cmd.ensure_finalized()
        self.assertTrue(cmd.user, 'user should be implied')

    def test_multiproc_atexit(self):
        if not _MULTIPROC:
            return
        _LOG.info('this should not break')

    def test_user_install_not_implied_without_usersite_enabled(self):
        easy_install_pkg.HAS_USER_SITE = False # usually enabled
        #XXX: replace with something meaningfull
        if sys.version < "2.6":
            return #SKIP
        dist = Distribution()
        dist.script_name = 'setup.py'
        cmd = easy_install(dist)
        cmd.args = ['py']
        cmd.initialize_options()
        self.assertFalse(cmd.user, 'NOT user should be implied')

    def test_local_index(self):
        # make sure the local index is used
        # when easy_install looks for installed
        # packages
        new_location = tempfile.mkdtemp()
        target = tempfile.mkdtemp()
        egg_file = os.path.join(new_location, 'foo-1.0.egg-info')
        f = open(egg_file, 'w')
        try:
            f.write('Name: foo\n')
        finally:
            f.close()

        sys.path.append(target)
        old_ppath = os.environ.get('PYTHONPATH')
        os.environ['PYTHONPATH'] = os.path.pathsep.join(sys.path)
        try:
            dist = Distribution()
            dist.script_name = 'setup.py'
            cmd = easy_install(dist)
            cmd.install_dir = target
            cmd.args = ['foo']
            cmd.ensure_finalized()
            cmd.local_index.scan([new_location])
            res = cmd.easy_install('foo')
            self.assertEqual(os.path.realpath(res.location),
                             os.path.realpath(new_location))
        finally:
            sys.path.remove(target)
            for basedir in [new_location, target, ]:
                if not os.path.exists(basedir) or not os.path.isdir(basedir):
                    continue
                try:
                    shutil.rmtree(basedir)
                except:
                    pass
            if old_ppath is not None:
                os.environ['PYTHONPATH'] = old_ppath
            else:
                del os.environ['PYTHONPATH']

    def test_setup_requires(self):
        """Regression test for issue #318

        Ensures that a package with setup_requires can be installed when
        distribute is installed in the user site-packages without causing a
        SandboxViolation.
        """

        test_pkg = create_setup_requires_package(self.dir)
        test_setup_py = os.path.join(test_pkg, 'setup.py')

        try:
            quiet_context(
                lambda: reset_setup_stop_context(
                    lambda: run_setup(test_setup_py, ['install'])
            ))
        except SandboxViolation:
            self.fail('Installation caused SandboxViolation')


class TestSetupRequires(unittest.TestCase):

    def test_setup_requires_honors_fetch_params(self):
        """
        When easy_install installs a source distribution which specifies
        setup_requires, it should honor the fetch parameters (such as
        allow-hosts, index-url, and find-links).
        """
        # set up a server which will simulate an alternate package index.
        p_index = setuptools.tests.server.MockServer()
        p_index.start()
        netloc = 1
        p_index_loc = urlparse.urlparse(p_index.url)[netloc]
        if p_index_loc.endswith(':0'):
            # Some platforms (Jython) don't find a port to which to bind,
            #  so skip this test for them.
            return

        # I realize this is all-but-impossible to read, because it was
        #  ported from some well-factored, safe code using 'with'. If you
        #  need to maintain this code, consider making the changes in
        #  the parent revision (of this comment) and then port the changes
        #  back for Python 2.4 (or deprecate Python 2.4).

        def install(dist_file):
            def install_at(temp_install_dir):
                def install_env():
                    ei_params = ['--index-url', p_index.url,
                        '--allow-hosts', p_index_loc,
                        '--exclude-scripts', '--install-dir', temp_install_dir,
                        dist_file]
                    def install_clean_reset():
                        def install_clean_argv():
                            # attempt to install the dist. It should fail because
                            #  it doesn't exist.
                            self.assertRaises(SystemExit,
                                easy_install_pkg.main, ei_params)
                        argv_context(install_clean_argv, ['easy_install'])
                    reset_setup_stop_context(install_clean_reset)
                environment_context(install_env, PYTHONPATH=temp_install_dir)
            tempdir_context(install_at)

        # create an sdist that has a build-time dependency.
        quiet_context(lambda: self.create_sdist(install))

        # there should have been two or three requests to the server
        #  (three happens on Python 3.3a)
        self.assertTrue(2 <= len(p_index.requests) <= 3)
        self.assertEqual(p_index.requests[0].path, '/does-not-exist/')

    def create_sdist(self, installer):
        """
        Create an sdist with a setup_requires dependency (of something that
        doesn't exist) and invoke installer on it.
        """
        def build_sdist(dir):
            dist_path = os.path.join(dir, 'distribute-test-fetcher-1.0.tar.gz')
            make_trivial_sdist(
                dist_path,
                textwrap.dedent("""
                    import setuptools
                    setuptools.setup(
                        name="distribute-test-fetcher",
                        version="1.0",
                        setup_requires = ['does-not-exist'],
                    )
                """).lstrip())
            installer(dist_path)
        tempdir_context(build_sdist)

    def test_setup_requires_overrides_version_conflict(self):
        """
        Regression test for issue #323.

        Ensures that a distribution's setup_requires requirements can still be
        installed and used locally even if a conflicting version of that
        requirement is already on the path.
        """

        pr_state = pkg_resources.__getstate__()
        fake_dist = PRDistribution('does-not-matter', project_name='foobar',
                                   version='0.0')
        working_set.add(fake_dist)

        def setup_and_run(temp_dir):
            test_pkg = create_setup_requires_package(temp_dir)
            test_setup_py = os.path.join(test_pkg, 'setup.py')
            try:
                stdout, stderr = quiet_context(
                    lambda: reset_setup_stop_context(
                        # Don't even need to install the package, just running
                        # the setup.py at all is sufficient
                        lambda: run_setup(test_setup_py, ['--name'])
                ))
            except VersionConflict:
                self.fail('Installing setup.py requirements caused '
                          'VersionConflict')

            lines = stdout.splitlines()
            self.assertTrue(len(lines) > 0)
            self.assertTrue(lines[-1].strip(), 'test_pkg')

        try:
            tempdir_context(setup_and_run)
        finally:
            pkg_resources.__setstate__(pr_state)


def create_setup_requires_package(path):
    """Creates a source tree under path for a trivial test package that has a
    single requirement in setup_requires--a tarball for that requirement is
    also created and added to the dependency_links argument.
    """

    test_setup_attrs = {
        'name': 'test_pkg', 'version': '0.0',
        'setup_requires': ['foobar==0.1'],
        'dependency_links': [os.path.abspath(path)]
    }

    test_pkg = os.path.join(path, 'test_pkg')
    test_setup_py = os.path.join(test_pkg, 'setup.py')
    test_setup_cfg = os.path.join(test_pkg, 'setup.cfg')
    os.mkdir(test_pkg)

    f = open(test_setup_py, 'w')
    f.write(textwrap.dedent("""\
        import setuptools
        setuptools.setup(**%r)
    """ % test_setup_attrs))
    f.close()

    foobar_path = os.path.join(path, 'foobar-0.1.tar.gz')
    make_trivial_sdist(
        foobar_path,
        textwrap.dedent("""\
            import setuptools
            setuptools.setup(
                name='foobar',
                version='0.1'
            )
        """))

    return test_pkg


def make_trivial_sdist(dist_path, setup_py):
    """Create a simple sdist tarball at dist_path, containing just a
    setup.py, the contents of which are provided by the setup_py string.
    """

    setup_py_file = tarfile.TarInfo(name='setup.py')
    try:
        # Python 3 (StringIO gets converted to io module)
        MemFile = StringIO.BytesIO
    except AttributeError:
        MemFile = StringIO.StringIO
    setup_py_bytes = MemFile(setup_py.encode('utf-8'))
    setup_py_file.size = len(setup_py_bytes.getvalue())
    dist = tarfile.open(dist_path, 'w:gz')
    try:
        dist.addfile(setup_py_file, fileobj=setup_py_bytes)
    finally:
        dist.close()


def tempdir_context(f, cd=lambda dir:None):
    """
    Invoke f in the context
    """
    temp_dir = tempfile.mkdtemp()
    orig_dir = os.getcwd()
    try:
        cd(temp_dir)
        f(temp_dir)
    finally:
        cd(orig_dir)
        shutil.rmtree(temp_dir)


def environment_context(f, **updates):
    """
    Invoke f in the context
    """
    old_env = os.environ.copy()
    os.environ.update(updates)
    try:
        f()
    finally:
        for key in updates:
            del os.environ[key]
        os.environ.update(old_env)


def argv_context(f, repl):
    """
    Invoke f in the context
    """
    old_argv = sys.argv[:]
    sys.argv[:] = repl
    try:
        f()
    finally:
        sys.argv[:] = old_argv


def reset_setup_stop_context(f):
    """
    When the distribute tests are run using setup.py test, and then
    one wants to invoke another setup() command (such as easy_install)
    within those tests, it's necessary to reset the global variable
    in distutils.core so that the setup() command will run naturally.
    """
    setup_stop_after = distutils.core._setup_stop_after
    distutils.core._setup_stop_after = None
    try:
        f()
    finally:
        distutils.core._setup_stop_after = setup_stop_after


def quiet_context(f):
    """
    Redirect stdout/stderr to StringIO objects to prevent console output from
    distutils commands.
    """

    old_stdout = sys.stdout
    old_stderr = sys.stderr
    new_stdout = sys.stdout = StringIO.StringIO()
    new_stderr = sys.stderr = StringIO.StringIO()
    try:
        f()
    finally:
        sys.stdout = old_stdout
        sys.stderr = old_stderr
    return new_stdout.getvalue(), new_stderr.getvalue()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.