예제 #1
0
def test_build_wheel_preserve_permission(tmp_path: Path) -> None:
    with build_fixture_project("demo-package"):
        wheel_name = api.build_wheel(tmp_path.as_posix())
        with zipfile.ZipFile(tmp_path / wheel_name) as zf:
            info = zf.getinfo("my_package/executable")
            filemode = info.external_attr >> 16
            assert filemode & 0o111
예제 #2
0
def test_build_single_module(tmp_path: Path) -> None:
    with build_fixture_project("demo-module"):
        wheel_name = api.build_wheel(tmp_path.as_posix())
        sdist_name = api.build_sdist(tmp_path.as_posix())
        assert api.get_requires_for_build_sdist() == []
        assert api.get_requires_for_build_wheel() == []
        assert sdist_name == "demo-module-0.1.0.tar.gz"
        assert wheel_name == "demo_module-0.1.0-py3-none-any.whl"
        tar_names = get_tarball_names(tmp_path / sdist_name)
        for name in [
            "foo_module.py",
            "bar_module.py",
            "LICENSE",
            "pyproject.toml",
            "PKG-INFO",
            "README.md",
        ]:
            assert f"demo-module-0.1.0/{name}" in tar_names

        zip_names = get_wheel_names(tmp_path / wheel_name)
        for name in ["foo_module.py", "bar_module.py"]:
            assert name in zip_names

        for name in ("pyproject.toml", "LICENSE"):
            assert name not in zip_names
예제 #3
0
def test_build_package_with_modules_in_src(tmp_path):
    with build_fixture_project("demo-src-pymodule"):
        wheel_name = api.build_wheel(tmp_path.as_posix())
        sdist_name = api.build_sdist(tmp_path.as_posix())

        tar_names = get_tarball_names(tmp_path / sdist_name)
        assert "demo-module-0.1.0/src/foo_module.py" in tar_names

        zip_names = get_wheel_names(tmp_path / wheel_name)
        assert "foo_module.py" in zip_names
예제 #4
0
def test_build_purelib_project_with_build(tmp_path: Path) -> None:
    with build_fixture_project("demo-purelib-with-build"):
        wheel_name = api.build_wheel(tmp_path.as_posix())
        assert wheel_name == "demo_package-0.1.0-py3-none-any.whl"

        with zipfile.ZipFile(tmp_path / wheel_name) as zf:
            wheel_metadata = email.message_from_bytes(
                zf.read("demo_package-0.1.0.dist-info/WHEEL")
            )
            assert wheel_metadata["Root-Is-Purelib"] == "True"
예제 #5
0
def test_project_with_combined_extras(fixture_project):
    project = fixture_project("demo-combined-extras")
    (project.root / "build").mkdir(exist_ok=True)
    with cd(project.root.as_posix()):
        wheel_name = build_wheel(str(project.root / "build"))
        wheel = distlib.wheel.Wheel(str(project.root / "build" / wheel_name))

    all_requires = filter_requirements_with_extras(wheel.metadata.run_requires,
                                                   ("all", ))
    for dep in ("urllib3", "chardet", "idna"):
        assert dep in all_requires
예제 #6
0
def test_build_src_package(tmp_path):
    with build_fixture_project("demo-src-package"):
        wheel_name = api.build_wheel(tmp_path.as_posix())
        sdist_name = api.build_sdist(tmp_path.as_posix())
        assert sdist_name == "demo-package-0.1.0.tar.gz"
        assert wheel_name == "demo_package-0.1.0-py3-none-any.whl"

        tar_names = get_tarball_names(tmp_path / sdist_name)
        zip_names = get_wheel_names(tmp_path / wheel_name)
        assert "demo-package-0.1.0/src/my_package/__init__.py" in tar_names
        assert "demo-package-0.1.0/src/my_package/data.json" in tar_names

        assert "my_package/__init__.py" in zip_names
        assert "my_package/data.json" in zip_names
예제 #7
0
def test_namespace_package_by_include(tmp_path: Path) -> None:
    with build_fixture_project("demo-pep420-package"):
        wheel_name = api.build_wheel(tmp_path.as_posix())
        sdist_name = api.build_sdist(tmp_path.as_posix())
        assert sdist_name == "demo-package-0.1.0.tar.gz"
        assert wheel_name == "demo_package-0.1.0-py3-none-any.whl"

        tar_names = get_tarball_names(tmp_path / sdist_name)
        zip_names = get_wheel_names(tmp_path / wheel_name)
        assert "demo-package-0.1.0/foo/my_package/__init__.py" in tar_names
        assert "demo-package-0.1.0/foo/my_package/data.json" in tar_names

        assert "foo/my_package/__init__.py" in zip_names
        assert "foo/my_package/data.json" in zip_names
예제 #8
0
def test_build_with_cextension_in_src(tmp_path):
    with build_fixture_project("demo-cextension-in-src"):
        wheel_name = api.build_wheel(tmp_path.as_posix())
        sdist_name = api.build_sdist(tmp_path.as_posix())

        zip_names = get_wheel_names(tmp_path / wheel_name)
        assert "my_package/__init__.py" in zip_names
        assert ("my_package/hellomodule.c"
                not in zip_names), "Not collect c files while building wheel"

        tar_names = get_tarball_names(tmp_path / sdist_name)
        assert "demo-package-0.1.0/src/my_package/__init__.py" in tar_names
        assert ("demo-package-0.1.0/src/my_package/hellomodule.c"
                in tar_names), "Collect c files while building sdist"
        assert not any(
            path.startswith("build") for path in
            tar_names), 'Not collect c files in temporary directory "./build"'
예제 #9
0
def test_build_legacypackage(tmp_path):
    with build_fixture_project("demo-legacy"):
        wheel_name = api.build_wheel(tmp_path.as_posix())
        sdist_name = api.build_sdist(tmp_path.as_posix())
        assert sdist_name == "demo-legacy-0.1.0.tar.gz"
        assert wheel_name == "demo_legacy-0.1.0-py3-none-any.whl"

        tar_names = get_tarball_names(tmp_path / sdist_name)
        assert "demo-legacy-0.1.0/my_package/__init__.py" in tar_names
        assert "demo-legacy-0.1.0/my_package/data.json" in tar_names
        assert "demo-legacy-0.1.0/single_module.py" not in tar_names
        assert "demo-legacy-0.1.0/data_out.json" not in tar_names

        zip_names = get_wheel_names(tmp_path / wheel_name)
        assert "my_package/__init__.py" in zip_names
        assert "my_package/data.json" in zip_names
        assert "single_module.py" not in zip_names
        assert "data_out.json" not in zip_names
예제 #10
0
def test_build_package_include(tmp_path):
    with build_fixture_project("demo-package-include"):
        wheel_name = api.build_wheel(tmp_path.as_posix())
        sdist_name = api.build_sdist(tmp_path.as_posix())
        assert sdist_name == "demo-package-0.1.0.tar.gz"
        assert wheel_name == "demo_package-0.1.0-py3-none-any.whl"

        tar_names = get_tarball_names(tmp_path / sdist_name)
        zip_names = get_wheel_names(tmp_path / wheel_name)

        assert "demo-package-0.1.0/my_package/__init__.py" in tar_names
        assert "demo-package-0.1.0/my_package/data.json" not in tar_names
        assert "demo-package-0.1.0/requirements.txt" in tar_names
        assert "demo-package-0.1.0/data_out.json" in tar_names

        assert "my_package/__init__.py" in zip_names
        assert "my_package/data.json" not in zip_names
        assert "requirements.txt" in zip_names
        assert "data_out.json" in zip_names
예제 #11
0
def test_build_with_cextension(tmp_path):
    with build_fixture_project("demo-cextension"):
        wheel_name = api.build_wheel(tmp_path.as_posix())
        sdist_name = api.build_sdist(tmp_path.as_posix())
        assert api.get_requires_for_build_sdist() == []
        assert api.get_requires_for_build_wheel() == ["setuptools>=40.8.0"]

        zip_names = get_wheel_names(tmp_path / wheel_name)
        assert "my_package/__init__.py" in zip_names
        assert ("my_package/hellomodule.c"
                not in zip_names), "Not collect c files while building wheel"

        tar_names = get_tarball_names(tmp_path / sdist_name)
        assert "demo-package-0.1.0/my_package/__init__.py" in tar_names
        assert ("demo-package-0.1.0/my_package/hellomodule.c"
                in tar_names), "Collect c files while building sdist"
        assert not any(
            path.startswith("build") for path in
            tar_names), 'Not collect c files in temporary directory "./build"'