Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add poetry support #78

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,20 @@ This would be the same as running `unidep merge --name myenv --verbose`:
🔍 Scanning in `.` at depth 0
🔍 Scanning in `hatch_project` at depth 1
🔍 Found `requirements.yaml` at `hatch_project/requirements.yaml`
🔍 Scanning in `poetry_project` at depth 1
🔍 Found `requirements.yaml` at `poetry_project/requirements.yaml`
🔍 Scanning in `setuptools_project` at depth 1
🔍 Found `requirements.yaml` at `setuptools_project/requirements.yaml`
🔍 Scanning in `setup_py_project` at depth 1
🔍 Found `requirements.yaml` at `setup_py_project/requirements.yaml`
📄 Parsing `hatch_project/requirements.yaml`
📄 Parsing `poetry_project/requirements.yaml`
📄 Parsing `setup_py_project/requirements.yaml`
📄 Parsing include `../setuptools_project`
📄 Parsing `setuptools_project/requirements.yaml`
📝 Generating environment file at `environment.yaml`
📝 Environment file generated successfully.
✅ Generated environment file at `environment.yaml` from `hatch_project/requirements.yaml`, `setup_py_project/requirements.yaml`, `setuptools_project/requirements.yaml`
✅ Generated environment file at `environment.yaml` from `hatch_project/requirements.yaml`, `poetry_project/requirements.yaml`, `setup_py_project/requirements.yaml`, `setuptools_project/requirements.yaml`
```

<!-- OUTPUT:END -->
Expand Down
1 change: 1 addition & 0 deletions example/poetry_project/poetry_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = 1
13 changes: 13 additions & 0 deletions example/poetry_project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build-system]
requires = ["poetry-core>=1.0.0", "unidep @ file://localhost/Users/basnijholt/Code/unidep"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "poetry_project"
version = "0.1.0"
description = "Example poetry_project for `unidep`."
authors = ["Bas Nijholt <[email protected]>"]

# `dependencies` is not needed because it is automatically
# populated by `unidep` with the dependencies from the `requirements.yaml`
# [tool.poetry.dependencies]
9 changes: 9 additions & 0 deletions example/poetry_project/requirements.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: poetry_project
channels:
- conda-forge
dependencies:
- numpy
- pandas
- wexpect # [win]
- pexpect # [unix]
- pip: unidep
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ unidep = "unidep:_setuptools_integration._setuptools_finalizer"
[project.entry-points.hatch]
unidep = "unidep._hatch_integration"

[tool.poetry.plugins."poetry.plugin"]
poetry-dynamic-versioning = "unidep._poetry_integration:UniDepPlugin"

[project.entry-points.pytest11]
affected = "unidep._pytest_plugin"

Expand Down
39 changes: 39 additions & 0 deletions unidep/_poetry_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from __future__ import annotations

from pathlib import Path

from cleo.io.io import IO
from poetry.plugins.plugin import Plugin
from poetry.poetry import Poetry

from unidep._setuptools_integration import get_python_dependencies
from unidep.utils import identify_current_platform

__all__ = ["UniDepPlugin"]

# See example: https://github.com/mtkennerly/poetry-dynamic-versioning


class UniDepPlugin(Plugin):
def activate(self, poetry: Poetry, io: IO):
io.write_line("Setting dependencies with UniDep")
project_root = Path().resolve()
requirements_file = project_root / "requirements.yaml"
if "dependencies" not in metadata.get("dynamic", []):
return
if not requirements_file.exists():
return
if "dependencies" in metadata:
error_msg = (
"You have a requirements.yaml file in your project root,"
" but you are also using [project.dependencies]."
" Please choose either requirements.yaml or"
" [project.dependencies], but not both."
)
raise RuntimeError(error_msg)

poetry.package.dependencies = get_python_dependencies(
requirements_file,
platforms=[identify_current_platform()],
raises_if_missing=False,
)
Loading