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

use prepare_metadata_for_build_wheel instead of parsing setup.py #2296

Closed
wants to merge 12 commits into from
31 changes: 27 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 18 additions & 83 deletions poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import glob
import logging
import os
import re
Expand All @@ -10,8 +9,6 @@
from typing import List
from typing import Optional

import pkginfo

from clikit.ui.components import ProgressIndicator

from poetry.core.packages import Dependency
Expand All @@ -32,13 +29,9 @@
from poetry.packages import DependencyPackage
from poetry.packages.package_collection import PackageCollection
from poetry.repositories import Pool
from poetry.utils._compat import PY35
from poetry.utils._compat import OrderedDict
from poetry.utils._compat import Path
from poetry.utils._compat import urlparse
from poetry.utils.env import EnvCommandError
from poetry.utils.env import EnvManager
from poetry.utils.env import VirtualEnv
from poetry.utils.helpers import parse_requires
from poetry.utils.helpers import safe_rmtree
from poetry.utils.helpers import temporary_directory
Expand All @@ -60,7 +53,6 @@ def _formatter_elapsed(self):


class Provider:

UNSAFE_PACKAGES = {"setuptools", "distribute", "pip"}

def __init__(self, package, pool, io): # type: (Package, Pool, Any) -> None
Expand Down Expand Up @@ -321,89 +313,32 @@ def get_package_from_directory(

package.python_versions = pkg.python_versions
else:
# Execute egg_info
current_dir = os.getcwd()
os.chdir(str(directory))

try:
with temporary_directory() as tmp_dir:
EnvManager.build_venv(tmp_dir)
venv = VirtualEnv(Path(tmp_dir), Path(tmp_dir))
venv.run("python", "setup.py", "egg_info")
except EnvCommandError:
result = SetupReader.read_from_directory(directory)
if not result["name"]:
# The name could not be determined
# We use the dependency name
result["name"] = name

if not result["version"]:
# The version could not be determined
# so we raise an error since it is mandatory
raise RuntimeError(
"Unable to retrieve the package version for {}".format(
directory
)
)
result = SetupReader.read_from_pep517_hook(directory)

package_name = result["name"]
package_version = result["version"]
python_requires = result["python_requires"]
if python_requires is None:
python_requires = "*"

package_summary = ""

requires = ""
for dep in result["install_requires"]:
requires += dep + "\n"
package_name = result["name"]
package_version = result["version"]
python_requires = result["python_requires"]
if python_requires is None:
python_requires = "*"

if result["extras_require"]:
requires += "\n"
package_summary = result["summary"]

for extra_name, deps in result["extras_require"].items():
requires += "[{}]\n".format(extra_name)
requires = ""
for dep in result["install_requires"]:
requires += dep + "\n"

for dep in deps:
requires += dep + "\n"
if result["extras_require"]:
requires += "\n"

requires += "\n"
for extra_name, deps in result["extras_require"].items():
requires += "[{}]\n".format(extra_name)

reqs = parse_requires(requires)
else:
os.chdir(current_dir)
# Sometimes pathlib will fail on recursive
# symbolic links, so we need to workaround it
# and use the glob module instead.
# Note that this does not happen with pathlib2
# so it's safe to use it for Python < 3.4.
if PY35:
egg_info = next(
Path(p)
for p in glob.glob(
os.path.join(str(directory), "**", "*.egg-info"),
recursive=True,
)
)
else:
egg_info = next(directory.glob("**/*.egg-info"))
for dep in deps:
requires += dep + "\n"

meta = pkginfo.UnpackedSDist(str(egg_info))
package_name = meta.name
package_version = meta.version
package_summary = meta.summary
python_requires = meta.requires_python
requires += "\n"

if meta.requires_dist:
reqs = list(meta.requires_dist)
else:
reqs = []
requires = egg_info / "requires.txt"
if requires.exists():
with requires.open(encoding="utf-8") as f:
reqs = parse_requires(f.read())
finally:
os.chdir(current_dir)
reqs = parse_requires(requires)

package = Package(package_name, package_version)
package.description = package_summary
Expand Down
2 changes: 1 addition & 1 deletion poetry/utils/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _inspect_sdist_with_setup(
"requires_dist": None,
}

result = SetupReader.read_from_directory(sdist_dir)
result = SetupReader.read_from_pep517_hook(sdist_dir)
requires = ""
for dep in result["install_requires"]:
requires += dep + "\n"
Expand Down
Loading