def test_save_wheels(self, mock_pip_main,
         mock_record_req_cached, mock_is_cache_update_required):
     mock_is_cache_update_required.return_value = False
     mock_pip_main.return_value = 0
     pip_automation.save_wheels('/bootsrap_wheels', ['some', 'packages'], 
             ['first.txt', 'second.txt'])
     self.assertEqual(mock_pip_main.call_count, 2)
Beispiel #2
0
    def test_save_wheels_pip_failure(self, mock_pip_main):

        # Fail the first call to pip.main()
        mock_pip_main.reset_mock()
        mock_pip_main.side_effect = [1, 0]
        with self.assertRaises(ValueError):
            pip_automation.save_wheels('/bootsrap_wheels',
                                       ['some', 'packages'],
                                       ['first.txt', 'second.txt'])
            self.assertEqual(mock_pip_main.call_count, 1)
Beispiel #3
0
    def test_save_wheels_calls_pip_wheel(self, check_call):
        save_wheels('/destination/path',
                    packages=['django', 'wagtail'],
                    requirements_paths=['requirements/base.txt', 'extra.txt'])

        check_call.assert_called_once_with([
            sys.executable,
            '-m',
            'pip',
            'wheel',
            '--wheel-dir=/destination/path',
            'django',
            'wagtail',
            '-rrequirements/base.txt',
            '-rextra.txt',
        ])
Beispiel #4
0
def inject_configuration(cli_args):
    with temp_directory() as staging_dir:
        build_zip_path = os.path.join(staging_dir, 'build.zip')

        shutil.copyfile(cli_args.build_zip, build_zip_path)

        build_zip = zipfile.ZipFile(build_zip_path, mode="a")

        # figuring out where things are in this zip file...
        all_the_wheels = fnmatch.filter(build_zip.namelist(), '*/wheels/*.whl')
        zip_wheel_dir = os.path.dirname(all_the_wheels[0])
        zip_root = os.path.normpath(os.path.join(zip_wheel_dir, '../'))

        # move just the wheels we want into the bundle dir
        wheel_destination = os.path.join(staging_dir, 'wheels')
        if cli_args.requirements_file:
            save_wheels(requirements_paths=[cli_args.requirements_file],
                        destination=wheel_destination)
            wheel_pattern = os.path.join(staging_dir, 'wheels/*.whl')

            saved_wheels = glob.glob(wheel_pattern)

            for wheel_path in saved_wheels:
                name = os.path.join(zip_wheel_dir,
                                    os.path.basename(wheel_path))
                build_zip.write(wheel_path, arcname=name)

        build_zip.write(cli_args.vars,
                        os.path.join(zip_root, 'environment.json'))

        if cli_args.paths:
            build_zip.write(cli_args.paths,
                            os.path.join(zip_root, 'paths.d/1_custom.json'))

        if cli_args.prepend_wsgi:
            build_zip.write(cli_args.prepend_wsgi,
                            os.path.join(zip_root, 'pre-wsgi.py-fragment'))

        if cli_args.append_wsgi:
            build_zip.write(cli_args.append_wsgi,
                            os.path.join(zip_root, 'post-wsgi.py-fragment'))

        build_zip.close()
        build_filename = os.path.basename(cli_args.build_zip)
        name, ext = os.path.splitext(build_filename)
        release_filename = "%s_%s%s" % (name, cli_args.slug, ext)
        shutil.copyfile(build_zip_path, release_filename)
    def test_save_wheels_pip_failure(self, mock_pip_main,
            mock_record_req_cached, mock_is_cache_update_required):
        mock_is_cache_update_required.return_value = False

        # Fail the second call to pip.main()
        mock_pip_main.side_effect = [0, 1]
        with self.assertRaises(ValueError):
            pip_automation.save_wheels('/bootsrap_wheels', ['some', 'packages'], 
                    ['first.txt', 'second.txt'])
            self.assertEqual(mock_pip_main.call_count, 2)

        # Fail the first call to pip.main()
        mock_pip_main.reset_mock()
        mock_pip_main.side_effect = [1, 0]
        with self.assertRaises(ValueError):
            pip_automation.save_wheels('/bootsrap_wheels', ['some', 'packages'], 
                    ['first.txt', 'second.txt'])
            self.assertEqual(mock_pip_main.call_count, 1)
Beispiel #6
0
def stage_bundle(cli_args):
    archive_basename = "%s_%s" % (cli_args.name, cli_args.label)
    executable_path = os.path.join(os.getcwd(), archive_basename + '.zip')

    if os.path.exists(executable_path) and not cli_args.f:
        print("%s already exists, skipping. Call with -f to force rebuild" %
              (executable_path))
        return

    with temp_directory() as staging_dir:
        build_dir = os.path.join(staging_dir, cli_args.label)

        shutil.copytree(build_skel, build_dir)

        # these are wheels needed during activation
        bootstrap_wheels = ['virtualenv', 'pip', 'setuptools']
        bootstrap_wheels_destination = os.path.join(build_dir,
                                                    'bootstrap_wheels')
        save_wheels(packages=bootstrap_wheels,
                    destination=bootstrap_wheels_destination)

        # move just the wheels we want into the bundle dir
        wheel_destination = os.path.join(build_dir, 'wheels')
        if cli_args.r:
            save_wheels(destination=wheel_destination,
                        requirements_paths=cli_args.r)

        # copy django project into bundle dir
        project_complete_path = os.path.join(os.getcwd(),
                                             cli_args.project_path)
        project_norm_path = os.path.normpath(project_complete_path)
        project_slug = os.path.basename(project_norm_path)
        project_destination = os.path.join(build_dir, project_slug)
        shutil.copytree(cli_args.project_path, project_destination)

        # install paths.d/0_build.json, so activate.sh can find the django_root
        paths_d = os.path.join(build_dir, 'paths.d')
        initial_paths_path = os.path.join(paths_d, '0_build.json')

        with open(initial_paths_path, 'w') as initial_paths_file:
            json.dump({'django_root': project_slug}, initial_paths_file)

        if cli_args.static:
            for index, path in enumerate(cli_args.static):
                destination = os.path.join(build_dir, 'static.in/%s/' % index)
                shutil.copytree(path, destination)

        if cli_args.aux:
            aux_root = os.path.join(build_dir, 'aux')
            for aux_spec in cli_args.aux:
                if '=' in aux_spec:
                    slug, src = aux_spec.split('=')
                else:
                    # normalize the path, so that it  will not end in a /
                    # required for basename to get the last path component
                    # would auth_path.split('/')[-1] be simpler? maybe.
                    norm_path = os.path.normpath(aux_spec)
                    slug = os.path.basename(norm_path)
                    src = aux_spec

                destination = os.path.join(aux_root, slug)
                shutil.copytree(src, destination)

        archive_name = shutil.make_archive(archive_basename,
                                           'zip',
                                           root_dir=staging_dir,
                                           base_dir=cli_args.label)

        make_executable(archive_name, prefix=cli_args.label)
        print("generated build at %s" % executable_path)
Beispiel #7
0
 def test_save_wheels_raises_pip_wheel_exception(self, check_call):
     with self.assertRaises(RuntimeError):
         save_wheels('/destination/path')
Beispiel #8
0
 def test_save_wheels(self, mock_pip_main):
     mock_pip_main.return_value = 0
     pip_automation.save_wheels('/bootsrap_wheels', ['some', 'packages'],
                                ['first.txt', 'second.txt'])
     self.assertEqual(mock_pip_main.call_count, 1)