Skip to content

Commit

Permalink
Fix extras with dependency markers (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
anaoum authored Sep 3, 2022
1 parent e3ea1b1 commit 67de37c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ def configure_package(
dep.in_extras.append(extra_name)
package.extras[extra_name].append(dep)

break

if "build" in config:
build = config["build"]
if not isinstance(build, dict):
Expand Down
Empty file.
20 changes: 20 additions & 0 deletions tests/fixtures/project_with_markers_and_extras/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[tool.poetry]
name = "project-with-markers-and-extras"
version = "1.2.3"
description = "This is a description"
authors = ["Your Name <[email protected]>"]
license = "MIT"

packages = [
{include = "project"}
]

[tool.poetry.dependencies]
python = "*"
orjson = [
{ url = "https://example/location/orjson-3.8.0-cp310-cp310-manylinux_2_28_x86_64.whl", platform = "linux", optional = true },
{ url = "https://example/location/orjson-3.8.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl", platform = "darwin", optional = true }
]

[tool.poetry.extras]
all = ["orjson"]
22 changes: 22 additions & 0 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import pytest

from poetry.core.factory import Factory
from poetry.core.packages.url_dependency import URLDependency
from poetry.core.packages.vcs_dependency import VCSDependency
from poetry.core.semver.helpers import parse_constraint
from poetry.core.toml import TOMLFile
from poetry.core.version.markers import SingleMarker


if TYPE_CHECKING:
Expand Down Expand Up @@ -323,6 +325,26 @@ def test_create_poetry_with_groups_and_explicit_main() -> None:
}


def test_create_poetry_with_markers_and_extras() -> None:
poetry = Factory().create_poetry(fixtures_dir / "project_with_markers_and_extras")

package = poetry.package
dependencies = package.requires
extras = package.extras

assert len(dependencies) == 2
assert {dependency.name for dependency in dependencies} == {"orjson"}
assert set(extras["all"]) == set(dependencies)
for dependency in dependencies:
assert dependency.in_extras == ["all"]
assert isinstance(dependency, URLDependency)
assert isinstance(dependency.marker, SingleMarker)
assert dependency.marker.name == "sys_platform"
assert dependency.marker.value == (
"darwin" if "macosx" in dependency.url else "linux"
)


@pytest.mark.parametrize(
"constraint, exp_python, exp_marker",
[
Expand Down

0 comments on commit 67de37c

Please sign in to comment.