Exemplo n.º 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()
Exemplo n.º 2
0
def test_convert_dependencies():
    result = SdistBuilder.convert_dependencies([
        get_dependency('A', '^1.0'),
        get_dependency('B', '~1.0'),
        get_dependency('C', '1.2.3'),
    ])
    main = [
        'A (>=1.0.0.0,<2.0.0.0)',
        'B (>=1.0.0.0,<1.1.0.0)',
        'C (==1.2.3.0)',
    ]
    extras = []

    assert result == (main, extras)

    dependency_with_python = get_dependency('A', '^1.0')
    dependency_with_python.python_versions = '^3.4'

    result = SdistBuilder.convert_dependencies([
        dependency_with_python,
        get_dependency('B', '~1.0'),
        get_dependency('C', '1.2.3'),
    ])
    main = [
        'B (>=1.0.0.0,<1.1.0.0)',
        'C (==1.2.3.0)',
    ]
    extras = [
        'A (>=1.0.0.0,<2.0.0.0); python_version>="3.4.0.0" and python_version<"4.0.0.0"',
    ]

    assert result == (main, extras)
Exemplo n.º 3
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()
Exemplo n.º 4
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
Exemplo n.º 5
0
def test_make_setup():
    poetry = Poetry.create(project("complete"))

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    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["packages"] == [
        "my_package",
        "my_package.sub_pkg1",
        "my_package.sub_pkg2",
    ]
    assert ns["install_requires"] == [
        "cachy[msgpack]>=0.2.0,<0.3.0", "cleo>=0.6,<0.7"
    ]
    assert ns["entry_points"] == {
        "console_scripts": [
            "extra-script = my_package.extra:main[time]",
            "my-2nd-script = my_package:main2",
            "my-script = my_package:main",
        ]
    }
    assert ns["extras_require"] == {"time": ["pendulum>=1.4,<2.0"]}
Exemplo n.º 6
0
def test_convert_dependencies():
    package = Package('foo', '1.2.3')
    result = SdistBuilder.convert_dependencies(package, [
        get_dependency('A', '^1.0'),
        get_dependency('B', '~1.0'),
        get_dependency('C', '1.2.3'),
    ])
    main = [
        'A (>=1.0.0.0,<2.0.0.0)',
        'B (>=1.0.0.0,<1.1.0.0)',
        'C (==1.2.3.0)',
    ]
    extras = {}

    assert result == (main, extras)

    package = Package('foo', '1.2.3')
    package.extras = {'bar': [get_dependency('A')]}

    result = SdistBuilder.convert_dependencies(package, [
        get_dependency('A', '>=1.2', optional=True),
        get_dependency('B', '~1.0'),
        get_dependency('C', '1.2.3'),
    ])
    main = [
        'B (>=1.0.0.0,<1.1.0.0)',
        'C (==1.2.3.0)',
    ]
    extras = {'bar': ['A (>=1.2.0.0)']}

    assert result == (main, extras)
Exemplo n.º 7
0
def test_make_setup():
    poetry = Poetry.create(project('complete'))

    builder = SdistBuilder(poetry, NullVenv(), NullIO())
    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['packages'] == [
        'my_package',
        'my_package.sub_pkg1',
        'my_package.sub_pkg2'
    ]
    assert ns['install_requires'] == [
        'cleo (>=0.6.0.0,<0.7.0.0)'
    ]
    assert ns['entry_points'] == {
        'console_scripts': [
            'my-script = my_package:main',
            'my-2nd-script = my_package:main2',
        ]
    }
    assert ns['extras_require'] == {
        'time': [
            'pendulum (>=1.4.0.0,<2.0.0.0)'
        ]
    }
Exemplo n.º 8
0
def test_convert_dependencies():
    package = Package("foo", "1.2.3")
    result = SdistBuilder.convert_dependencies(
        package,
        [
            get_dependency("A", "^1.0"),
            get_dependency("B", "~1.0"),
            get_dependency("C", "1.2.3"),
        ],
    )
    main = ["A>=1.0,<2.0", "B>=1.0,<1.1", "C==1.2.3"]
    extras = {}

    assert result == (main, extras)

    package = Package("foo", "1.2.3")
    package.extras = {"bar": [get_dependency("A")]}

    result = SdistBuilder.convert_dependencies(
        package,
        [
            get_dependency("A", ">=1.2", optional=True),
            get_dependency("B", "~1.0"),
            get_dependency("C", "1.2.3"),
        ],
    )
    main = ["B>=1.0,<1.1", "C==1.2.3"]
    extras = {"bar": ["A>=1.2"]}

    assert result == (main, extras)

    c = get_dependency("C", "1.2.3")
    c.python_versions = "~2.7 || ^3.6"
    d = get_dependency("D", "3.4.5", optional=True)
    d.python_versions = "~2.7 || ^3.4"

    package.extras = {"baz": [get_dependency("D")]}

    result = SdistBuilder.convert_dependencies(
        package,
        [
            get_dependency("A", ">=1.2", optional=True),
            get_dependency("B", "~1.0"),
            c,
            d,
        ],
    )
    main = ["B>=1.0,<1.1"]

    extra_python = (
        ':python_version >= "2.7" and python_version < "2.8" '
        'or python_version >= "3.6" and python_version < "4.0"'
    )
    extra_d_dependency = (
        'baz:python_version >= "2.7" and python_version < "2.8" '
        'or python_version >= "3.4" and python_version < "4.0"'
    )
    extras = {extra_python: ["C==1.2.3"], extra_d_dependency: ["D==3.4.5"]}

    assert result == (main, extras)
Exemplo n.º 9
0
def test_convert_dependencies():
    package = Package('foo', '1.2.3')
    result = SdistBuilder.convert_dependencies(package, [
        get_dependency('A', '^1.0'),
        get_dependency('B', '~1.0'),
        get_dependency('C', '1.2.3'),
    ])
    main = [
        'A>=1.0.0.0,<2.0.0.0',
        'B>=1.0.0.0,<1.1.0.0',
        'C==1.2.3.0',
    ]
    extras = {}

    assert result == (main, extras)

    package = Package('foo', '1.2.3')
    package.extras = {'bar': [get_dependency('A')]}

    result = SdistBuilder.convert_dependencies(package, [
        get_dependency('A', '>=1.2', optional=True),
        get_dependency('B', '~1.0'),
        get_dependency('C', '1.2.3'),
    ])
    main = [
        'B>=1.0.0.0,<1.1.0.0',
        'C==1.2.3.0',
    ]
    extras = {'bar': ['A>=1.2.0.0']}

    assert result == (main, extras)

    c = get_dependency('C', '1.2.3')
    c.python_versions = '~2.7 || ^3.6'
    d = get_dependency('D', '3.4.5', optional=True)
    d.python_versions = '~2.7 || ^3.4'

    package.extras = {'baz': [get_dependency('D')]}

    result = SdistBuilder.convert_dependencies(package, [
        get_dependency('A', '>=1.2', optional=True),
        get_dependency('B', '~1.0'), c, d
    ])
    main = [
        'B>=1.0.0.0,<1.1.0.0',
    ]

    extra_python = (
        ':(python_version >= "2.7.0.0" and python_version < "2.8.0.0") '
        'or (python_version >= "3.6.0.0" and python_version < "4.0.0.0")')
    extra_d_dependency = (
        'baz:(python_version >= "2.7.0.0" and python_version < "2.8.0.0") '
        'or (python_version >= "3.4.0.0" and python_version < "4.0.0.0")')
    extras = {
        extra_python: ['C==1.2.3.0'],
        extra_d_dependency: ['D==3.4.5.0'],
    }

    assert result == (main, extras)
Exemplo n.º 10
0
def test_proper_python_requires_if_two_digits_precision_version_specified():
    poetry = Factory().create_poetry(project("simple_version"))

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    pkg_info = builder.build_pkg_info()
    p = Parser()
    parsed = p.parsestr(to_str(pkg_info))

    assert parsed["Requires-Python"] == ">=3.6,<3.7"
Exemplo n.º 11
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
Exemplo n.º 12
0
def test_make_pkg_info(mocker):
    get_metadata_content = mocker.patch(
        "poetry.masonry.builders.builder.Builder.get_metadata_content")
    poetry = Poetry.create(project("complete"))

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

    assert get_metadata_content.called
Exemplo n.º 13
0
def test_proper_python_requires_if_single_version_specified():
    poetry = Poetry.create(project("simple_version"))

    builder = SdistBuilder(poetry, NullVenv(), NullIO())
    pkg_info = builder.build_pkg_info()
    p = Parser()
    parsed = p.parsestr(to_str(pkg_info))

    assert parsed["Requires-Python"] == ">=3.6,<3.7"
Exemplo n.º 14
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()
Exemplo n.º 15
0
def test_proper_python_requires_if_three_digits_precision_version_specified():
    poetry = Poetry.create(project("single_python"))

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    pkg_info = builder.build_pkg_info()
    p = Parser()
    parsed = p.parsestr(to_str(pkg_info))

    assert parsed["Requires-Python"] == "==2.7.15"
Exemplo n.º 16
0
def test_make_pkg_info_any_python():
    poetry = Poetry.create(project("module1"))

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    pkg_info = builder.build_pkg_info()
    p = Parser()
    parsed = p.parsestr(to_str(pkg_info))

    assert "Requires-Python" not in parsed
Exemplo n.º 17
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
Exemplo n.º 18
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()
Exemplo n.º 19
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()
Exemplo n.º 20
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()
Exemplo n.º 21
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()
Exemplo n.º 22
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()
Exemplo n.º 23
0
def test_excluded_subpackage():
    poetry = Factory().create_poetry(project("excluded_subpackage"))

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    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["packages"] == ["example"]
Exemplo n.º 24
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()
Exemplo n.º 25
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()
Exemplo n.º 26
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()
Exemplo n.º 27
0
def test_make_pkg_info_multi_constraints_dependency():
    poetry = Poetry.create(
        Path(__file__).parent.parent.parent / "fixtures" /
        "project_with_multi_constraints_dependency")

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    pkg_info = builder.build_pkg_info()
    p = Parser()
    parsed = p.parsestr(to_str(pkg_info))

    requires = parsed.get_all("Requires-Dist")
    assert requires == [
        'pendulum (>=1.5,<2.0); python_version < "3.4"',
        'pendulum (>=2.0,<3.0); python_version >= "3.4" and python_version < "4.0"',
    ]
Exemplo n.º 28
0
def test_find_files_to_add():
    poetry = Poetry.create(project('complete'))

    builder = SdistBuilder(poetry, NullVenv(), NullIO())
    result = builder.find_files_to_add()

    assert result == [
        Path('README.rst'),
        Path('my_package/__init__.py'),
        Path('my_package/data1/test.json'),
        Path('my_package/sub_pkg1/__init__.py'),
        Path('my_package/sub_pkg2/__init__.py'),
        Path('my_package/sub_pkg2/data2/data.json'),
        Path('pyproject.toml'),
    ]
Exemplo n.º 29
0
def test_find_files_to_add():
    poetry = Poetry.create(project("complete"))

    builder = SdistBuilder(poetry, NullEnv(), NullIO())
    result = builder.find_files_to_add()

    assert sorted(result) == sorted([
        Path("LICENSE"),
        Path("README.rst"),
        Path("my_package/__init__.py"),
        Path("my_package/data1/test.json"),
        Path("my_package/sub_pkg1/__init__.py"),
        Path("my_package/sub_pkg2/__init__.py"),
        Path("my_package/sub_pkg2/data2/data.json"),
        Path("pyproject.toml"),
    ])
Exemplo n.º 30
0
def make_setup_if_not_exists():
    '''
    If python package without setup.py
    (for example Poetry)
    '''
    if not os.path.exists('setup.py') and os.path.exists('setup.cfg'):
        from poetry.masonry.builders.sdist import SdistBuilder
        from poetry.factory import Factory
        factory = Factory()
        poetry = factory.create_poetry('.')
        sdist_builder = SdistBuilder(poetry, None, None)
        setuppy_blob = sdist_builder.build_setup()
        with open('setup.py', 'wb') as unit:
            unit.write(setuppy_blob)
            unit.write(b'\n# This setup.py was autogenerated using poetry.\n')
    pass