Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #340 from dephell/fix-pyproject-detection
Browse files Browse the repository at this point in the history
Add detection for pyproject format
  • Loading branch information
orsinium committed Dec 18, 2019
2 parents 878b1ad + 408ac71 commit 3a9aac7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 2 additions & 3 deletions dephell/converters/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ def can_parse(self, path: Path, content: Optional[str] = None) -> bool:
if isinstance(path, str):
path = Path(path)
if content:
return ('[tool.poetry]' in content)
else:
return (path.name == 'pyproject.toml')
return '[tool.poetry]' in content
return path.name == 'pyproject.toml'

def loads(self, content) -> RootDependency:
doc = tomlkit.parse(content)
Expand Down
10 changes: 9 additions & 1 deletion dephell/converters/pyproject.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# built-in
from pathlib import Path
from typing import Optional

# external
from dephell_discover import Root as PackageRoot
Expand All @@ -15,13 +16,20 @@
class PyProjectConverter(BaseConverter):
lock = False

def can_parse(self, path: Path, content: Optional[str] = None) -> bool:
if isinstance(path, str):
path = Path(path)
if content:
return '[build-system]' in content
return path.name == 'pyproject.toml'

def loads(self, content: str) -> RootDependency:
doc = parse(content)
deps = []
root = RootDependency(
package=PackageRoot(path=self.project_path or Path()),
)
for req in doc['build-system']['requires']:
for req in doc['build-system'].get('requires', []):
req = Requirement(req)
deps.extend(DependencyMaker.from_requirement(source=root, req=req))
root.attach_dependencies(deps)
Expand Down

0 comments on commit 3a9aac7

Please sign in to comment.