Skip to content

Commit

Permalink
dependency: support PEP 517 projects as dir deps
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed May 24, 2022
1 parent 79333f7 commit 8620154
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/poetry/core/packages/directory_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def __init__(
raise ValueError(f"Directory {self._path} does not exist")

self._develop = develop
self._supports_poetry = False

if not self._full_path.exists():
raise ValueError(f"Directory {self._path} does not exist")
Expand All @@ -46,11 +45,12 @@ def __init__(

# Checking content to determine actions
setup = self._full_path / "setup.py"
self._supports_poetry = PyProjectTOML(
self._full_path / "pyproject.toml"
).is_poetry_project()
pyproject = PyProjectTOML(self._full_path / "pyproject.toml")

if not setup.exists() and not self._supports_poetry:
self._supports_pep517 = setup.exists() or pyproject.is_build_system_defined
self._supports_poetry = pyproject.is_poetry_project()

if not (setup.exists() or self._supports_pep517 or self._supports_poetry):
raise ValueError(
f"Directory {self._full_path} does not seem to be a Python package"
)
Expand Down
4 changes: 4 additions & 0 deletions src/poetry/core/pyproject/toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def data(self) -> TOMLDocument:

return self._data

@property
def is_build_system_defined(self) -> bool:
return self._file.exists() and "build-system" in self.data

@property
def build_system(self) -> BuildSystem:
from poetry.core.pyproject.tables import BuildSystem
Expand Down
13 changes: 13 additions & 0 deletions tests/fixtures/project_with_pep517_non_poetry/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build-system]
requires = ["flit_core >=3.7.1,<4"]
build-backend = "flit_core.buildapi"

[project]
name = "flit"
authors = []
dependencies = [
"flit_core >=3.7.1",
]
requires-python = ">=3.6"
readme = "README.rst"
dynamic = ['version', 'description']
11 changes: 11 additions & 0 deletions tests/packages/test_directory_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,14 @@ def test_directory_dependency_pep_508_extras() -> None:
requirement = f"demo[foo,bar] @ file://{path.as_posix()}"
requirement_expected = f"demo[bar,foo] @ file://{path.as_posix()}"
_test_directory_dependency_pep_508("demo", path, requirement, requirement_expected)


def test_directory_dependency_pep_517_non_poetry() -> None:
path = Path(__file__).parent.parent / "fixtures" / "project_with_pep517_non_poetry"

try:
DirectoryDependency("flit", path)
except ValueError as e:
if "does not seem to be a Python package" not in str(e):
raise e from e
pytest.fail("PEP 517 project not recognized as valid directory dependency")

0 comments on commit 8620154

Please sign in to comment.