How to use the poetry.factory.Factory function in poetry

To help you get started, we’ve selected a few poetry examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-poetry / poetry / tests / masonry / publishing / test_publisher.py View on Github external
def test_publish_publishes_to_pypi_by_default(fixture_dir, mocker, config):
    uploader_auth = mocker.patch("poetry.masonry.publishing.uploader.Uploader.auth")
    uploader_upload = mocker.patch("poetry.masonry.publishing.uploader.Uploader.upload")
    poetry = Factory().create_poetry(fixture_dir("sample_project"))
    poetry._config = config
    poetry.config.merge(
        {"http-basic": {"pypi": {"username": "foo", "password": "bar"}}}
    )
    publisher = Publisher(poetry, NullIO())

    publisher.publish(None, None, None)

    assert [("foo", "bar")] == uploader_auth.call_args
    assert [
        ("https://upload.pypi.org/legacy/",),
        {"cert": None, "client_cert": None},
    ] == uploader_upload.call_args
github python-poetry / poetry / tests / masonry / builders / test_sdist.py View on Github external
def test_make_pkg_info(mocker):
    get_metadata_content = mocker.patch(
        "poetry.masonry.builders.builder.Builder.get_metadata_content"
    )
    poetry = Factory().create_poetry(project("complete"))

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

    assert get_metadata_content.called
github python-poetry / poetry / tests / masonry / builders / test_sdist.py View on Github external
def test_proper_python_requires_if_three_digits_precision_version_specified():
    poetry = Factory().create_poetry(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"
github python-poetry / poetry / tests / masonry / builders / test_sdist.py View on Github external
def test_module():
    poetry = Factory().create_poetry(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()
github python-poetry / poetry / tests / test_factory.py View on Github external
def test_create_poetry():
    poetry = Factory().create_poetry(fixtures_dir / "sample_project")

    package = poetry.package

    assert package.name == "my-package"
    assert package.version.text == "1.2.3"
    assert package.description == "Some description."
    assert package.authors == ["Sébastien Eustace "]
    assert package.license.id == "MIT"
    assert (
        package.readme.relative_to(fixtures_dir).as_posix()
        == "sample_project/README.rst"
    )
    assert package.homepage == "https://python-poetry.org"
    assert package.repository_url == "https://github.com/python-poetry/poetry"
    assert package.keywords == ["packaging", "dependency", "poetry"]
github python-poetry / poetry / tests / masonry / builders / test_sdist.py View on Github external
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"],
    }
github python-poetry / poetry / tests / masonry / publishing / test_publisher.py View on Github external
def test_publish_can_publish_to_given_repository(fixture_dir, mocker, config):
    uploader_auth = mocker.patch("poetry.masonry.publishing.uploader.Uploader.auth")
    uploader_upload = mocker.patch("poetry.masonry.publishing.uploader.Uploader.upload")
    poetry = Factory().create_poetry(fixture_dir("sample_project"))
    poetry._config = config
    poetry.config.merge(
        {
            "repositories": {"my-repo": {"url": "http://foo.bar"}},
            "http-basic": {"my-repo": {"username": "foo", "password": "bar"}},
        }
    )
    publisher = Publisher(poetry, NullIO())

    publisher.publish("my-repo", None, None)

    assert [("foo", "bar")] == uploader_auth.call_args
    assert [
        ("http://foo.bar",),
        {"cert": None, "client_cert": None},
    ] == uploader_upload.call_args
github python-poetry / poetry / poetry / utils / inspector.py View on Github external
tar.close()

        unpacked = file_path.parent / "unpacked"
        elements = list(unpacked.glob("*"))
        if len(elements) == 1 and elements[0].is_dir():
            sdist_dir = elements[0]
        else:
            sdist_dir = unpacked / file_path.name.rstrip(suffix)

        pyproject = TomlFile(sdist_dir / "pyproject.toml")
        if pyproject.exists():
            from poetry.factory import Factory

            pyproject_content = pyproject.read()
            if "tool" in pyproject_content and "poetry" in pyproject_content["tool"]:
                package = Factory().create_poetry(sdist_dir).package
                return {
                    "name": package.name,
                    "version": package.version.text,
                    "summary": package.description,
                    "requires_dist": [dep.to_pep_508() for dep in package.requires],
                    "requires_python": package.python_versions,
                }

        # Checking for .egg-info at root
        eggs = list(sdist_dir.glob("*.egg-info"))
        if eggs:
            egg_info = eggs[0]

            requires = egg_info / "requires.txt"
            if requires.exists():
                with requires.open(encoding="utf-8") as f: