Skip to content

Commit

Permalink
wip: poc pep 735
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed Jan 13, 2025
1 parent ed4bb56 commit c912bde
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/poetry/core/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,14 @@ def configure_package(
) -> None:
project = pyproject.data.get("project", {})
tool_poetry = pyproject.poetry_config
dependency_groups = pyproject.data.get("dependency-groups", {})

package.root_dir = root

cls._configure_package_metadata(package, project, tool_poetry, root)
cls._configure_entry_points(package, project, tool_poetry)
cls._configure_package_dependencies(
package, project, tool_poetry, with_groups=with_groups
package, project, tool_poetry, dependency_groups=dependency_groups, with_groups=with_groups
)
cls._configure_package_poetry_specifics(package, tool_poetry)

Expand Down Expand Up @@ -282,6 +283,7 @@ def _configure_package_dependencies(
package: ProjectPackage,
project: dict[str, Any],
tool_poetry: dict[str, Any],
dependency_groups: dict[str, list[str]],
with_groups: bool = True,
) -> None:
from poetry.core.packages.dependency import Dependency
Expand Down Expand Up @@ -332,16 +334,29 @@ def _configure_package_dependencies(
dependencies=tool_poetry["dependencies"],
)

if with_groups and "group" in tool_poetry:
for group_name, group_config in tool_poetry["group"].items():
group = DependencyGroup(
group_name, optional=group_config.get("optional", False)
)
cls._add_package_group_dependencies(
package=package,
group=group,
dependencies=group_config["dependencies"],
)
if with_groups:
if dependency_groups:
for group_name, dependencies in dependency_groups.items():
group = DependencyGroup(group_name)
package.add_dependency_group(group)

for constraint in dependencies:
dep = Dependency.create_from_pep_508(
constraint, relative_to=package.root_dir
)
dep._groups = frozenset([group_name])
group.add_dependency(dep)

if "group" in tool_poetry:
for group_name, group_config in tool_poetry["group"].items():
group = DependencyGroup(
group_name, optional=group_config.get("optional", False)
)
cls._add_package_group_dependencies(
package=package,
group=group,
dependencies=group_config["dependencies"],
)

if with_groups and "dev-dependencies" in tool_poetry:
cls._add_package_group_dependencies(
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/sample_project_with_groups_new/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
My Package
==========
62 changes: 62 additions & 0 deletions tests/fixtures/sample_project_with_groups_new/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[project]
name = "my-package"
version = "1.2.3"
description = "Some description."
readme = "README.rst"
requires-python = ">=3.6"
license = { text = "MIT" }
keywords = ["packaging", "dependency", "poetry"]
authors = [
{ name = "Sébastien Eustace", email = "sebastien@eustace.io" }
]
maintainers = [
{ name = "Sébastien Eustace", email = "sebastien@eustace.io" }
]

classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules"
]

# Requirements
dependencies = [
"cleo ~=0.6",
"pendulum @ git+https://github.com/sdispater/pendulum.git@2.0",
"tomlkit @ git+https://github.com/sdispater/tomlkit.git@3bff550",
"pathlib2 ~=2.2 ; python_version == '2.7'",
# File dependency
"demo @ ../distributions/demo-0.1.0-py2.py3-none-any.whl",
# Dir dependency with setup.py
"my-package @ ../project_with_setup/",
# Dir dependency with pyproject.toml
"simple-project @ ../simple_project/",
# Dependency with markers
"functools32 ~=3.2.3 ; python_version ~= '2.7' and sys_platform == 'win32' or python_version in '3.4 3.5'",
# Dependency with python constraint
"dataclasses ~=0.7 ; python_full_version >= '3.6.1' and python_version < '3.7'"
]

[project.optional-dependencies]
db = [
"orator ~=0.9"
]
network = [
"requests[security] ~=2.18"
]

[project.urls]
homepage = "https://python-poetry.org"
repository = "https://github.com/python-poetry/poetry"
documentation = "https://python-poetry.org/docs"

[project.scripts]
my-script = "my_package:main"

[project.entry-points."blogtool.parsers"]
".rst" = "some_module::SomeClass"

[tool.poetry.dependencies]
tomlkit = { develop = true }

[dependency-groups]
test = ["pytest>7", "coverage"]
6 changes: 6 additions & 0 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ def test_create_poetry(project: str) -> None:
"Topic :: Software Development :: Libraries :: Python Modules",
]

def test_create_poetry_with_groups() -> None:
poetry = Factory().create_poetry(
fixtures_dir / "sample_project_with_groups_new"
)
package = poetry.package
pass

def test_create_poetry_with_dependencies_with_subdirectory() -> None:
poetry = Factory().create_poetry(
Expand Down

0 comments on commit c912bde

Please # to comment.