Skip to content

Commit

Permalink
feat: fallback to gather metadata via pep517 if reading as Poetry pro…
Browse files Browse the repository at this point in the history
…ject raises RuntimeError
  • Loading branch information
finswimmer committed Jun 11, 2022
1 parent 374cff5 commit 331bff3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 71 deletions.
5 changes: 4 additions & 1 deletion src/poetry/inspection/info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import contextlib
import functools
import glob
import logging
Expand Down Expand Up @@ -452,7 +453,9 @@ def _get_poetry_package(path: Path) -> ProjectPackage | None:
# Note: we ignore any setup.py file at this step
# TODO: add support for handling non-poetry PEP-517 builds
if PyProjectTOML(path.joinpath("pyproject.toml")).is_poetry_project():
return Factory().create_poetry(path).package
with contextlib.suppress(RuntimeError):
return Factory().create_poetry(path).package

return None

@classmethod
Expand Down
66 changes: 32 additions & 34 deletions src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import contextlib
import csv
import itertools
import json
Expand Down Expand Up @@ -540,40 +541,37 @@ def _install_directory(self, operation: Install | Update) -> int:
pyproject = PyProjectTOML(os.path.join(req, "pyproject.toml"))

if pyproject.is_poetry_project():
# Even if there is a build system specified
# some versions of pip (< 19.0.0) don't understand it
# so we need to check the version of pip to know
# if we can rely on the build system
legacy_pip = (
self._env.pip_version
< self._env.pip_version.__class__.from_parts(19, 0, 0)
)
package_poetry = Factory().create_poetry(pyproject.file.path.parent)

builder: Builder
if package.develop and not package_poetry.package.build_script:
from poetry.masonry.builders.editable import EditableBuilder

# This is a Poetry package in editable mode
# we can use the EditableBuilder without going through pip
# to install it, unless it has a build script.
builder = EditableBuilder(package_poetry, self._env, NullIO())
builder.build()

return 0
elif legacy_pip or package_poetry.package.build_script:
from poetry.core.masonry.builders.sdist import SdistBuilder

# We need to rely on creating a temporary setup.py
# file since the version of pip does not support
# build-systems
# We also need it for non-PEP-517 packages
builder = SdistBuilder(package_poetry)

with builder.setup_py():
if package.develop:
return self.pip_install(req, upgrade=True, editable=True)
return self.pip_install(req, upgrade=True)
with contextlib.suppress(RuntimeError):
legacy_pip = (
self._env.pip_version
< self._env.pip_version.__class__.from_parts(19, 0, 0)
)
package_poetry = Factory().create_poetry(pyproject.file.path.parent)

builder: Builder
if package.develop and not package_poetry.package.build_script:
from poetry.masonry.builders.editable import EditableBuilder

# This is a Poetry package in editable mode
# we can use the EditableBuilder without going through pip
# to install it, unless it has a build script.
builder = EditableBuilder(package_poetry, self._env, NullIO())
builder.build()

return 0
elif legacy_pip or package_poetry.package.build_script:
from poetry.core.masonry.builders.sdist import SdistBuilder

# We need to rely on creating a temporary setup.py
# file since the version of pip does not support
# build-systems
# We also need it for non-PEP-517 packages
builder = SdistBuilder(package_poetry)

with builder.setup_py():
if package.develop:
return self.pip_install(req, upgrade=True, editable=True)
return self.pip_install(req, upgrade=True)

if package.develop:
return self.pip_install(req, upgrade=True, editable=True)
Expand Down
74 changes: 38 additions & 36 deletions src/poetry/installation/pip_installer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import contextlib
import os
import tempfile
import urllib.parse
Expand Down Expand Up @@ -220,44 +221,45 @@ def install_directory(self, package: Package) -> str | int:
pyproject = PyProjectTOML(os.path.join(req, "pyproject.toml"))

if pyproject.is_poetry_project():
# Even if there is a build system specified
# some versions of pip (< 19.0.0) don't understand it
# so we need to check the version of pip to know
# if we can rely on the build system
legacy_pip = self._env.pip_version < Version.from_parts(19, 0, 0)
package_poetry = Factory().create_poetry(pyproject.file.path.parent)

builder: Builder
if package.develop and not package_poetry.package.build_script:
from poetry.masonry.builders.editable import EditableBuilder

# This is a Poetry package in editable mode
# we can use the EditableBuilder without going through pip
# to install it, unless it has a build script.
builder = EditableBuilder(package_poetry, self._env, NullIO())
builder.build()

return 0
elif legacy_pip or package_poetry.package.build_script:
from poetry.core.masonry.builders.sdist import SdistBuilder

# We need to rely on creating a temporary setup.py
# file since the version of pip does not support
# build-systems
# We also need it for non-PEP-517 packages
builder = SdistBuilder(package_poetry)

with builder.setup_py():
if package.develop:
with contextlib.suppress(RuntimeError):
# Even if there is a build system specified
# some versions of pip (< 19.0.0) don't understand it
# so we need to check the version of pip to know
# if we can rely on the build system
legacy_pip = self._env.pip_version < Version.from_parts(19, 0, 0)
package_poetry = Factory().create_poetry(pyproject.file.path.parent)

builder: Builder
if package.develop and not package_poetry.package.build_script:
from poetry.masonry.builders.editable import EditableBuilder

# This is a Poetry package in editable mode
# we can use the EditableBuilder without going through pip
# to install it, unless it has a build script.
builder = EditableBuilder(package_poetry, self._env, NullIO())
builder.build()

return 0
elif legacy_pip or package_poetry.package.build_script:
from poetry.core.masonry.builders.sdist import SdistBuilder

# We need to rely on creating a temporary setup.py
# file since the version of pip does not support
# build-systems
# We also need it for non-PEP-517 packages
builder = SdistBuilder(package_poetry)

with builder.setup_py():
if package.develop:
return pip_install(
path=req,
environment=self._env,
upgrade=True,
editable=True,
)
return pip_install(
path=req,
environment=self._env,
upgrade=True,
editable=True,
path=req, environment=self._env, deps=False, upgrade=True
)
return pip_install(
path=req, environment=self._env, deps=False, upgrade=True
)

if package.develop:
return pip_install(
Expand Down

0 comments on commit 331bff3

Please sign in to comment.