Esempio n. 1
0
def make_distribution(name='my_project', zipped=False, zip_safe=True):
  interp = {'project_name': name}
  if zip_safe:
    interp['content'] = dedent('''
    def do_something():
      print('hello world!')
    ''')
  else:
    interp['content'] = dedent('''
    if __file__ == 'derp.py':
      print('i am an idiot')
    ''')
  with temporary_content(PROJECT_CONTENT, interp=interp) as td:
    installer = Installer(td)
    distribution = installer.distribution()
    distiller = Distiller(distribution, debug=True)
    dist_location = distiller.distill(into=safe_mkdtemp())
    if zipped:
      yield DistributionHelper.distribution_from_path(dist_location)
    else:
      with temporary_dir() as td:
        extract_path = os.path.join(td, os.path.basename(dist_location))
        with contextlib.closing(zipfile.ZipFile(dist_location)) as zf:
          zf.extractall(extract_path)
        yield DistributionHelper.distribution_from_path(extract_path)
Esempio n. 2
0
def make_distribution(name='my_project', zipped=False, zip_safe=True):
    interp = {'project_name': name}
    if zip_safe:
        interp['content'] = dedent('''
    def do_something():
      print('hello world!')
    ''')
    else:
        interp['content'] = dedent('''
    if __file__ == 'derp.py':
      print('i am an idiot')
    ''')
    with temporary_content(PROJECT_CONTENT, interp=interp) as td:
        installer = Installer(td)
        distribution = installer.distribution()
        distiller = Distiller(distribution, debug=True)
        dist_location = distiller.distill(into=safe_mkdtemp())
        if zipped:
            yield DistributionHelper.distribution_from_path(dist_location)
        else:
            with temporary_dir() as td:
                extract_path = os.path.join(td,
                                            os.path.basename(dist_location))
                with contextlib.closing(zipfile.ZipFile(dist_location)) as zf:
                    zf.extractall(extract_path)
                yield DistributionHelper.distribution_from_path(extract_path)
Esempio n. 3
0
def make_distribution(name='my_project', zipped=False, zip_safe=True):
  interp = {'project_name': name, 'zip_safe': zip_safe}
  with temporary_content(PROJECT_CONTENT, interp=interp) as td:
    installer = EggInstaller(td)
    dist_location = installer.bdist()
    if zipped:
      yield DistributionHelper.distribution_from_path(dist_location)
    else:
      with temporary_dir() as td:
        extract_path = os.path.join(td, os.path.basename(dist_location))
        with contextlib.closing(zipfile.ZipFile(dist_location)) as zf:
          zf.extractall(extract_path)
        yield DistributionHelper.distribution_from_path(extract_path)
Esempio n. 4
0
def make_distribution(name='my_project', zipped=False, zip_safe=True):
    interp = {'project_name': name, 'zip_safe': zip_safe}
    with temporary_content(PROJECT_CONTENT, interp=interp) as td:
        installer = EggInstaller(td)
        dist_location = installer.bdist()
        if zipped:
            yield DistributionHelper.distribution_from_path(dist_location)
        else:
            with temporary_dir() as td:
                extract_path = os.path.join(td,
                                            os.path.basename(dist_location))
                with contextlib.closing(zipfile.ZipFile(dist_location)) as zf:
                    zf.extractall(extract_path)
                yield DistributionHelper.distribution_from_path(extract_path)
def test_pex_builder():
    # test w/ and w/o zipfile dists
    with nested(temporary_dir(), make_distribution("p1", zipped=True)) as (td, p1):
        write_pex(td, exe_main, dists=[p1])

        success_txt = os.path.join(td, "success.txt")
        PEX(td).run(args=[success_txt])
        assert os.path.exists(success_txt)
        with open(success_txt) as fp:
            assert fp.read() == "success"

    # test w/ and w/o zipfile dists
    with nested(temporary_dir(), temporary_dir(), make_distribution("p1", zipped=True)) as (td1, td2, p1):
        target_egg_dir = os.path.join(td2, os.path.basename(p1.location))
        safe_mkdir(target_egg_dir)
        with closing(zipfile.ZipFile(p1.location, "r")) as zf:
            zf.extractall(target_egg_dir)
        p1 = DistributionHelper.distribution_from_path(target_egg_dir)

        write_pex(td1, exe_main, dists=[p1])

        success_txt = os.path.join(td1, "success.txt")
        PEX(td1).run(args=[success_txt])
        assert os.path.exists(success_txt)
        with open(success_txt) as fp:
            assert fp.read() == "success"
Esempio n. 6
0
def test_pex_builder():
    # test w/ and w/o zipfile dists
    with nested(temporary_dir(), make_distribution('p1',
                                                   zipped=True)) as (td, p1):
        write_pex(td, exe_main, dists=[p1])

        success_txt = os.path.join(td, 'success.txt')
        PEX(td).run(args=[success_txt])
        assert os.path.exists(success_txt)
        with open(success_txt) as fp:
            assert fp.read() == 'success'

    # test w/ and w/o zipfile dists
    with nested(temporary_dir(), temporary_dir(),
                make_distribution('p1', zipped=True)) as (td1, td2, p1):
        target_egg_dir = os.path.join(td2, os.path.basename(p1.location))
        safe_mkdir(target_egg_dir)
        with closing(zipfile.ZipFile(p1.location, 'r')) as zf:
            zf.extractall(target_egg_dir)
        p1 = DistributionHelper.distribution_from_path(target_egg_dir)

        write_pex(td1, exe_main, dists=[p1])

        success_txt = os.path.join(td1, 'success.txt')
        PEX(td1).run(args=[success_txt])
        assert os.path.exists(success_txt)
        with open(success_txt) as fp:
            assert fp.read() == 'success'