Beispiel #1
0
def test_with_src_module_dir():
    poetry = Poetry.create(project("source_package"))

    builder = SdistBuilder(poetry, NullVenv(), NullIO())

    # Check setup.py
    setup = builder.build_setup()
    setup_ast = ast.parse(setup)

    setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
    ns = {}
    exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
    assert ns["package_dir"] == {"": "src"}
    assert ns["packages"] == ["package_src"]

    builder.build()

    sdist = fixtures_dir / "source_package" / "dist" / "package-src-0.1.tar.gz"

    assert sdist.exists()

    tar = tarfile.open(str(sdist), "r")

    assert "package-src-0.1/src/package_src/__init__.py" in tar.getnames()
    assert "package-src-0.1/src/package_src/module.py" in tar.getnames()
Beispiel #2
0
def test_with_src_module_dir():
    poetry = Poetry.create(project('source_package'))

    builder = SdistBuilder(poetry, NullVenv(), NullIO())

    # Check setup.py
    setup = builder.build_setup()
    setup_ast = ast.parse(setup)

    setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
    ns = {}
    exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
    assert ns['package_dir'] == {'': 'src'}
    assert ns['packages'] == [
        'package_src',
    ]

    builder.build()

    sdist = fixtures_dir / 'source_package' / 'dist' / 'package-src-0.1.tar.gz'

    assert sdist.exists()

    tar = tarfile.open(str(sdist), 'r')

    assert 'package-src-0.1/src/package_src/__init__.py' in tar.getnames()
    assert 'package-src-0.1/src/package_src/module.py' in tar.getnames()
Beispiel #3
0
def test_src_excluded_nested_data():
    module_path = fixtures_dir / "exclude_nested_data_toml"
    poetry = Factory().create_poetry(module_path)

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    builder.build()

    sdist = module_path / "dist" / "my-package-1.2.3.tar.gz"

    assert sdist.exists()

    with tarfile.open(str(sdist), "r") as tar:
        names = tar.getnames()
        assert len(names) == len(set(names))
        assert "my-package-1.2.3/LICENSE" in names
        assert "my-package-1.2.3/README.rst" in names
        assert "my-package-1.2.3/pyproject.toml" in names
        assert "my-package-1.2.3/setup.py" in names
        assert "my-package-1.2.3/PKG-INFO" in names
        assert "my-package-1.2.3/my_package/__init__.py" in names
        assert "my-package-1.2.3/my_package/data/sub_data/data2.txt" not in names
        assert "my-package-1.2.3/my_package/data/sub_data/data3.txt" not in names
        assert "my-package-1.2.3/my_package/data/data1.txt" not in names
        assert "my-package-1.2.3/my_package/puplic/publicdata.txt" in names
        assert "my-package-1.2.3/my_package/public/item1/itemdata1.txt" not in names
        assert (
            "my-package-1.2.3/my_package/public/item1/subitem/subitemdata.txt"
            not in names
        )
        assert "my-package-1.2.3/my_package/public/item2/itemdata2.txt" not in names
Beispiel #4
0
def test_prelease():
    poetry = Poetry.create(project("prerelease"))

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    builder.build()

    sdist = fixtures_dir / "prerelease" / "dist" / "prerelease-0.1b1.tar.gz"

    assert sdist.exists()
Beispiel #5
0
def test_prelease():
    poetry = Poetry.create(project('prerelease'))

    builder = SdistBuilder(poetry, NullVenv(), NullIO())
    builder.build()

    sdist = fixtures_dir / 'prerelease' / 'dist' / 'prerelease-0.1b1.tar.gz'

    assert sdist.exists()
Beispiel #6
0
def test_package():
    poetry = Poetry.create(project('complete'))

    builder = SdistBuilder(poetry, NullVenv(), NullIO())
    builder.build()

    sdist = fixtures_dir / 'complete' / 'dist' / 'my-package-1.2.3.tar.gz'

    assert sdist.exists()
Beispiel #7
0
def test_default_with_excluded_data(mocker):
    # Patch git module to return specific excluded files
    p = mocker.patch("poetry.vcs.git.Git.get_ignored_files")
    p.return_value = [
        (
            (
                Path(__file__).parent
                / "fixtures"
                / "default_with_excluded_data"
                / "my_package"
                / "data"
                / "sub_data"
                / "data2.txt"
            )
            .relative_to(project("default_with_excluded_data"))
            .as_posix()
        )
    ]
    poetry = Factory().create_poetry(project("default_with_excluded_data"))

    builder = SdistBuilder(poetry, NullEnv(), NullIO())

    # Check setup.py
    setup = builder.build_setup()
    setup_ast = ast.parse(setup)

    setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
    ns = {}
    exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
    assert "package_dir" not in ns
    assert ns["packages"] == ["my_package"]
    assert ns["package_data"] == {
        "": ["*"],
        "my_package": ["data/*", "data/sub_data/data3.txt"],
    }

    builder.build()

    sdist = (
        fixtures_dir / "default_with_excluded_data" / "dist" / "my-package-1.2.3.tar.gz"
    )

    assert sdist.exists()

    with tarfile.open(str(sdist), "r") as tar:
        names = tar.getnames()
        assert len(names) == len(set(names))
        assert "my-package-1.2.3/LICENSE" in names
        assert "my-package-1.2.3/README.rst" in names
        assert "my-package-1.2.3/my_package/__init__.py" in names
        assert "my-package-1.2.3/my_package/data/data1.txt" in names
        assert "my-package-1.2.3/pyproject.toml" in names
        assert "my-package-1.2.3/setup.py" in names
        assert "my-package-1.2.3/PKG-INFO" in names
        # all last modified times should be set to a valid timestamp
        for tarinfo in tar.getmembers():
            assert 0 < tarinfo.mtime
Beispiel #8
0
def test_package_with_include(mocker):
    # Patch git module to return specific excluded files
    p = mocker.patch("poetry.vcs.git.Git.get_ignored_files")
    p.return_value = [
        str(
            Path(__file__).parent
            / "fixtures"
            / "with-include"
            / "extra_dir"
            / "vcs_excluded.txt"
        ),
        str(
            Path(__file__).parent
            / "fixtures"
            / "with-include"
            / "extra_dir"
            / "sub_pkg"
            / "vcs_excluded.txt"
        ),
    ]
    poetry = Poetry.create(project("with-include"))

    builder = SdistBuilder(poetry, NullEnv(), NullIO())

    # Check setup.py
    setup = builder.build_setup()
    setup_ast = ast.parse(setup)

    setup_ast.body = [n for n in setup_ast.body if isinstance(n, ast.Assign)]
    ns = {}
    exec(compile(setup_ast, filename="setup.py", mode="exec"), ns)
    assert "package_dir" not in ns
    assert ns["packages"] == ["extra_dir", "extra_dir.sub_pkg", "package_with_include"]
    assert ns["package_data"] == {"": ["*"]}
    assert ns["modules"] == ["my_module"]

    builder.build()

    sdist = fixtures_dir / "with-include" / "dist" / "with-include-1.2.3.tar.gz"

    assert sdist.exists()

    with tarfile.open(str(sdist), "r") as tar:
        names = tar.getnames()
        assert len(names) == len(set(names))
        assert "with-include-1.2.3/LICENSE" in names
        assert "with-include-1.2.3/README.rst" in names
        assert "with-include-1.2.3/extra_dir/__init__.py" in names
        assert "with-include-1.2.3/extra_dir/vcs_excluded.txt" in names
        assert "with-include-1.2.3/extra_dir/sub_pkg/__init__.py" in names
        assert "with-include-1.2.3/extra_dir/sub_pkg/vcs_excluded.txt" not in names
        assert "with-include-1.2.3/my_module.py" in names
        assert "with-include-1.2.3/notes.txt" in names
        assert "with-include-1.2.3/package_with_include/__init__.py" in names
        assert "with-include-1.2.3/pyproject.toml" in names
        assert "with-include-1.2.3/setup.py" in names
        assert "with-include-1.2.3/PKG-INFO" in names
Beispiel #9
0
def test_module():
    poetry = Poetry.create(project("module1"))

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    builder.build()

    sdist = fixtures_dir / "module1" / "dist" / "module1-0.1.tar.gz"

    assert sdist.exists()

    with tarfile.open(str(sdist), "r") as tar:
        assert "module1-0.1/module1.py" in tar.getnames()
Beispiel #10
0
def test_package():
    poetry = Poetry.create(project("complete"))

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    builder.build()

    sdist = fixtures_dir / "complete" / "dist" / "my-package-1.2.3.tar.gz"

    assert sdist.exists()

    with tarfile.open(str(sdist), "r") as tar:
        assert "my-package-1.2.3/LICENSE" in tar.getnames()
Beispiel #11
0
def test_with_c_extensions_src_layout():
    poetry = Poetry.create(project("src_extended"))

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    builder.build()

    sdist = fixtures_dir / "src_extended" / "dist" / "extended-0.1.tar.gz"

    assert sdist.exists()

    with tarfile.open(str(sdist), "r") as tar:
        assert "extended-0.1/build.py" in tar.getnames()
        assert "extended-0.1/src/extended/extended.c" in tar.getnames()
Beispiel #12
0
def test_module():
    poetry = Poetry.create(project('module1'))

    builder = SdistBuilder(poetry, NullVenv(), NullIO())
    builder.build()

    sdist = fixtures_dir / 'module1' / 'dist' / 'module1-0.1.tar.gz'

    assert sdist.exists()

    tar = tarfile.open(str(sdist), 'r')

    assert 'module1-0.1/module1.py' in tar.getnames()
Beispiel #13
0
def test_package():
    poetry = Poetry.create(project('complete'))

    builder = SdistBuilder(poetry, NullVenv(), NullIO())
    builder.build()

    sdist = fixtures_dir / 'complete' / 'dist' / 'my-package-1.2.3.tar.gz'

    assert sdist.exists()

    tar = tarfile.open(str(sdist), 'r')

    assert 'my-package-1.2.3/LICENSE' in tar.getnames()
Beispiel #14
0
def test_with_c_extensions():
    poetry = Poetry.create(project('extended'))

    builder = SdistBuilder(poetry, NullVenv(), NullIO())
    builder.build()

    sdist = fixtures_dir / 'extended' / 'dist' / 'extended-0.1.tar.gz'

    assert sdist.exists()

    tar = tarfile.open(str(sdist), 'r')

    assert 'extended-0.1/build.py' in tar.getnames()
    assert 'extended-0.1/extended/extended.c' in tar.getnames()
Beispiel #15
0
def test_sdist_package_pep_561_stub_only():
    root = fixtures_dir / "pep_561_stub_only"
    poetry = Factory().create_poetry(root)

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    builder.build()

    sdist = root / "dist" / "pep-561-stubs-0.1.tar.gz"

    assert sdist.exists()

    with tarfile.open(str(sdist), "r") as tar:
        names = tar.getnames()
        assert "pep-561-stubs-0.1/pkg-stubs/__init__.pyi" in names
        assert "pep-561-stubs-0.1/pkg-stubs/module.pyi" in names
        assert "pep-561-stubs-0.1/pkg-stubs/subpkg/__init__.pyi" in names