예제 #1
0
 def test_patch_sys_executable(self, mock_find_exe):
     original_exe = sys.executable
     with patch('shub.utils.sys.frozen', new=False):
         with utils.patch_sys_executable():
             self.assertEqual(sys.executable, original_exe)
     with utils.patch_sys_executable():
         self.assertEqual(sys.executable, '/my/python')
     # Make sure we properly cleaned up after ourselves
     self.assertEqual(sys.executable, original_exe)
     mock_find_exe.side_effect = NotFoundException
     with self.assertRaises(NotFoundException):
         with utils.patch_sys_executable():
             pass
예제 #2
0
 def test_patch_sys_executable(self, mock_find_exe):
     original_exe = sys.executable
     with patch('shub.utils.sys.frozen', new=False):
         with utils.patch_sys_executable():
             self.assertEqual(sys.executable, original_exe)
     with utils.patch_sys_executable():
         self.assertEqual(sys.executable, '/my/python')
     # Make sure we properly cleaned up after ourselves
     self.assertEqual(sys.executable, original_exe)
     mock_find_exe.side_effect = NotFoundException
     with self.assertRaises(NotFoundException):
         with utils.patch_sys_executable():
             pass
예제 #3
0
def _fetch_from_pypi(pkg):
    tmpdir = tempfile.mkdtemp(prefix='shub-deploy-egg-from-pypi')
    click.echo('Fetching %s from pypi' % pkg)
    with patch_sys_executable():
        pip.main(["install", "-d", tmpdir, pkg, "--no-deps", "--no-use-wheel"])
    click.echo('Package fetched successfully')
    os.chdir(tmpdir)
예제 #4
0
def _download_egg_files(eggs_dir, requirements_file):
    editable_src_dir = tempfile.mkdtemp(prefix='pipsrc')

    click.echo('Downloading eggs...')
    try:
        with patch_sys_executable():
            pip.main(
                ["install", "-d", eggs_dir, "-r", requirements_file, "--src",
                 editable_src_dir, "--no-deps", "--no-use-wheel"]
                )

    finally:
        shutil.rmtree(editable_src_dir, ignore_errors=True)
예제 #5
0
파일: test_utils.py 프로젝트: bbotella/shub
    def test_patch_sys_executable(self):
        def make_mock_find_exe(py2=True, py=True):
            def find_exe(exe_name):
                if exe_name == 'python2' and py2:
                    return '/my/python2'
                elif exe_name == 'python' and py:
                    return '/my/python'
                raise NotFoundException
            return find_exe

        original_exe = sys.executable
        with patch('shub.utils.sys.frozen', new=False):
            with utils.patch_sys_executable():
                self.assertEqual(sys.executable, original_exe)

        with patch('shub.utils.find_exe', new=make_mock_find_exe()), \
                patch('subprocess.check_output') as mock_gco:
            mock_gco.return_value = "Python 2.7.11"
            with utils.patch_sys_executable():
                self.assertEqual(sys.executable, '/my/python2')

        with patch('shub.utils.find_exe', new=make_mock_find_exe(py2=False)), \
                patch('subprocess.check_output') as mock_gco:
            mock_gco.return_value = "Python 2.7.11"
            with utils.patch_sys_executable():
                self.assertEqual(sys.executable, '/my/python')
            mock_gco.return_value = "Python 3.5.1"
            with self.assertRaises(NotFoundException):
                with utils.patch_sys_executable():
                    pass
            # Make sure we properly cleaned up after ourselves
            self.assertEqual(sys.executable, original_exe)

        with patch('shub.utils.find_exe',
                   new=make_mock_find_exe(py2=False, py=False)):
            with self.assertRaises(NotFoundException):
                with utils.patch_sys_executable():
                    pass
예제 #6
0
파일: test_utils.py 프로젝트: cans/shub
    def test_patch_sys_executable(self):
        def make_mock_find_exe(py2=True, py=True):
            def find_exe(exe_name):
                if exe_name == 'python2' and py2:
                    return '/my/python2'
                elif exe_name == 'python' and py:
                    return '/my/python'
                raise NotFoundException
            return find_exe

        original_exe = sys.executable
        with patch('shub.utils.sys.frozen', new=False):
            with utils.patch_sys_executable():
                self.assertEqual(sys.executable, original_exe)

        with patch('shub.utils.find_exe', new=make_mock_find_exe()), \
                patch('subprocess.check_output') as mock_gco:
            mock_gco.return_value = "Python 2.7.11"
            with utils.patch_sys_executable():
                self.assertEqual(sys.executable, '/my/python2')

        with patch('shub.utils.find_exe', new=make_mock_find_exe(py2=False)), \
                patch('subprocess.check_output') as mock_gco:
            mock_gco.return_value = "Python 2.7.11"
            with utils.patch_sys_executable():
                self.assertEqual(sys.executable, '/my/python')
            mock_gco.return_value = "Python 3.5.1"
            with self.assertRaises(NotFoundException):
                with utils.patch_sys_executable():
                    pass
            # Make sure we properly cleaned up after ourselves
            self.assertEqual(sys.executable, original_exe)

        with patch('shub.utils.find_exe',
                   new=make_mock_find_exe(py2=False, py=False)):
            with self.assertRaises(NotFoundException):
                with utils.patch_sys_executable():
                    pass
예제 #7
0
파일: deploy.py 프로젝트: bbotella/shub
def _build_egg():
    closest = closest_file('scrapy.cfg')
    os.chdir(os.path.dirname(closest))
    if not os.path.exists('setup.py'):
        settings = get_config().get('settings', 'default')
        _create_default_setup_py(settings=settings)
    d = tempfile.mkdtemp(prefix="shub-deploy-")
    with open(os.path.join(d, "stdout"), "wb") as o, \
            open(os.path.join(d, "stderr"), "wb") as e, \
            patch_sys_executable():
        retry_on_eintr(
            check_call,
            [sys.executable, 'setup.py', 'clean', '-a', 'bdist_egg', '-d', d],
            stdout=o, stderr=e,
        )
    egg = glob.glob(os.path.join(d, '*.egg'))[0]
    return egg, d
예제 #8
0
파일: deploy.py 프로젝트: bopopescu/vinalo
def _build_egg():
    closest = closest_file('scrapy.cfg')
    os.chdir(os.path.dirname(closest))
    if not os.path.exists('setup.py'):
        settings = get_config().get('settings', 'default')
        _create_default_setup_py(settings=settings)
    d = tempfile.mkdtemp(prefix="shub-deploy-")
    with open(os.path.join(d, "stdout"), "wb") as o, \
            open(os.path.join(d, "stderr"), "wb") as e, \
            patch_sys_executable():
        retry_on_eintr(
            check_call,
            [sys.executable, 'setup.py', 'clean', '-a', 'bdist_egg', '-d', d],
            stdout=o,
            stderr=e,
        )
    egg = glob.glob(os.path.join(d, '*.egg'))[0]
    return egg, d
예제 #9
0
파일: deploy.py 프로젝트: pawelmhm/shub
def _build_egg():
    closest = closest_file("scrapy.cfg")
    os.chdir(os.path.dirname(closest))
    if not os.path.exists("setup.py"):
        settings = get_config().get("settings", "default")
        _create_default_setup_py(settings=settings)
    d = tempfile.mkdtemp(prefix="shub-deploy-")
    with open(os.path.join(d, "stdout"), "wb") as o, open(os.path.join(d, "stderr"), "wb") as e, patch_sys_executable():
        retry_on_eintr(
            check_call, [sys.executable, "setup.py", "clean", "-a", "bdist_egg", "-d", d], stdout=o, stderr=e
        )
    egg = glob.glob(os.path.join(d, "*.egg"))[0]
    return egg, d