Esempio n. 1
0
def assert_pex_args_shebang(shebang):
    # type: (str) -> None
    with make_project() as project_dir:
        pex_args = '--pex-args=--python-shebang="{}"'.format(shebang)
        with bdist_pex(project_dir, bdist_args=[pex_args]) as my_app_pex:
            with open(my_app_pex, "rb") as fp:
                assert fp.readline().decode().rstrip() == shebang
Esempio n. 2
0
def test_unwriteable_contents():
  my_app_setup_py = dedent("""
      from setuptools import setup

      setup(
        name='my_app',
        version='0.0.0',
        zip_safe=True,
        packages=['my_app'],
        include_package_data=True,
        package_data={'my_app': ['unwriteable.so']},
      )
    """)

  UNWRITEABLE_PERMS = 0o400
  with temporary_content({'setup.py': my_app_setup_py,
                          'my_app/__init__.py': '',
                          'my_app/unwriteable.so': 'so contents'},
                         perms=UNWRITEABLE_PERMS) as my_app_project_dir:
    my_app_whl = WheelBuilder(my_app_project_dir).bdist()

    with make_project(name='uses_my_app', install_reqs=['my_app']) as uses_my_app_project_dir:
      pex_args = '--pex-args=--disable-cache --no-pypi -f {}'.format(os.path.dirname(my_app_whl))
      with bdist_pex(uses_my_app_project_dir, bdist_args=[pex_args]) as uses_my_app_pex:
        with open_zip(uses_my_app_pex) as zf:
          unwriteable_sos = [path for path in zf.namelist()
                             if path.endswith('my_app/unwriteable.so')]
          assert 1 == len(unwriteable_sos)
          unwriteable_so = unwriteable_sos.pop()
          zf.extract(unwriteable_so, path=uses_my_app_project_dir)
          extract_dest = os.path.join(uses_my_app_project_dir, unwriteable_so)
          with open(extract_dest) as fp:
            assert 'so contents' == fp.read()
Esempio n. 3
0
def assert_entry_points(entry_points):
    with make_project(name='my_app', entry_points=entry_points) as project_dir:
        with bdist_pex(project_dir) as my_app_pex:
            process = subprocess.Popen([my_app_pex], stdout=subprocess.PIPE)
            stdout, _ = process.communicate()
            assert '{pex_root}' not in os.listdir(project_dir)
            assert 0 == process.returncode
            assert stdout == b'hello world!\n'
Esempio n. 4
0
def assert_entry_points(entry_points):
    # type: (Union[str, Dict[str, List[str]]]) -> None
    with make_project(name="my_app", entry_points=entry_points) as project_dir:
        with bdist_pex(project_dir) as my_app_pex:
            process = subprocess.Popen([my_app_pex], stdout=subprocess.PIPE)
            stdout, _ = process.communicate()
            assert "{pex_root}" not in os.listdir(project_dir)
            assert 0 == process.returncode
            assert stdout == b"hello world!\n"
Esempio n. 5
0
def create_sdist(*args, **kwargs):
    dist_dir = safe_mkdtemp()

    with make_project(*args, **kwargs) as project_dir:
        cmd = ['setup.py', 'sdist', '--dist-dir={}'.format(dist_dir)]
        spawn_python_job(args=cmd,
                         cwd=project_dir,
                         expose=['setuptools'],
                         stdout=subprocess.PIPE,
                         stderr=subprocess.PIPE).communicate()

    dists = os.listdir(dist_dir)
    assert len(dists) == 1
    return os.path.join(dist_dir, dists[0])
Esempio n. 6
0
def create_sdist(**kwargs):
    # type: (**Any) -> str
    dist_dir = safe_mkdtemp()

    with make_project(**kwargs) as project_dir:
        cmd = ["setup.py", "sdist", "--dist-dir={}".format(dist_dir)]
        spawn_python_job(
            args=cmd,
            cwd=project_dir,
            expose=["setuptools"],
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        ).communicate()

    dists = os.listdir(dist_dir)
    assert len(dists) == 1
    return os.path.join(dist_dir, dists[0])