From 37961b718722f0db484685e981f9490b58f41733 Mon Sep 17 00:00:00 2001 From: Arun Babu Neelicattu Date: Fri, 10 Jul 2020 15:22:33 +0200 Subject: [PATCH] inspection: use pep517.meta.build from shell With change we execute pep517 metadata build from within a new venv retaining old `python setup.py egg_info` behaviour. We fallback to the old behaviour if pep517 metadata build fails. --- poetry.lock | 93 +++++++++++++++++++---------------- poetry/inspection/info.py | 74 ++++++++++++++++++++++++---- pyproject.toml | 1 - tests/inspection/test_info.py | 39 ++++++++++++--- 4 files changed, 148 insertions(+), 59 deletions(-) diff --git a/poetry.lock b/poetry.lock index ed7f5b5024c..afa50c02199 100644 --- a/poetry.lock +++ b/poetry.lock @@ -194,7 +194,7 @@ description = "Code coverage measurement for Python" name = "coverage" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4" -version = "5.1" +version = "5.2" [package.extras] toml = ["toml"] @@ -868,7 +868,7 @@ description = "pytest-sugar is a plugin for pytest that changes the default look name = "pytest-sugar" optional = false python-versions = "*" -version = "0.9.3" +version = "0.9.4" [package.dependencies] packaging = ">=14.1" @@ -1070,8 +1070,8 @@ category = "main" description = "Type Hints for Python" name = "typing" optional = false -python-versions = "*" -version = "3.7.4.1" +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <3.5" +version = "3.7.4.2" [[package]] category = "main" @@ -1100,11 +1100,11 @@ description = "Virtual Python Environment builder" name = "virtualenv" optional = false python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7" -version = "20.0.25" +version = "20.0.26" [package.dependencies] appdirs = ">=1.4.3,<2" -distlib = ">=0.3.0,<1" +distlib = ">=0.3.1,<1" filelock = ">=3.0.0,<4" six = ">=1.9.0,<2" importlib-metadata = {version = ">=0.12,<2", markers = "python_version < \"3.8\""} @@ -1249,37 +1249,40 @@ contextlib2 = [ {file = "contextlib2-0.6.0.post1.tar.gz", hash = "sha256:01f490098c18b19d2bd5bb5dc445b2054d2fa97f09a4280ba2c5f3c394c8162e"}, ] coverage = [ - {file = "coverage-5.1-cp27-cp27m-macosx_10_12_x86_64.whl", hash = "sha256:0cb4be7e784dcdc050fc58ef05b71aa8e89b7e6636b99967fadbdba694cf2b65"}, - {file = "coverage-5.1-cp27-cp27m-macosx_10_13_intel.whl", hash = "sha256:c317eaf5ff46a34305b202e73404f55f7389ef834b8dbf4da09b9b9b37f76dd2"}, - {file = "coverage-5.1-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:b83835506dfc185a319031cf853fa4bb1b3974b1f913f5bb1a0f3d98bdcded04"}, - {file = "coverage-5.1-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:5f2294dbf7875b991c381e3d5af2bcc3494d836affa52b809c91697449d0eda6"}, - {file = "coverage-5.1-cp27-cp27m-win32.whl", hash = "sha256:de807ae933cfb7f0c7d9d981a053772452217df2bf38e7e6267c9cbf9545a796"}, - {file = "coverage-5.1-cp27-cp27m-win_amd64.whl", hash = "sha256:bf9cb9a9fd8891e7efd2d44deb24b86d647394b9705b744ff6f8261e6f29a730"}, - {file = "coverage-5.1-cp27-cp27mu-manylinux1_i686.whl", hash = "sha256:acf3763ed01af8410fc36afea23707d4ea58ba7e86a8ee915dfb9ceff9ef69d0"}, - {file = "coverage-5.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:dec5202bfe6f672d4511086e125db035a52b00f1648d6407cc8e526912c0353a"}, - {file = "coverage-5.1-cp35-cp35m-macosx_10_12_x86_64.whl", hash = "sha256:7a5bdad4edec57b5fb8dae7d3ee58622d626fd3a0be0dfceda162a7035885ecf"}, - {file = "coverage-5.1-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:1601e480b9b99697a570cea7ef749e88123c04b92d84cedaa01e117436b4a0a9"}, - {file = "coverage-5.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:dbe8c6ae7534b5b024296464f387d57c13caa942f6d8e6e0346f27e509f0f768"}, - {file = "coverage-5.1-cp35-cp35m-win32.whl", hash = "sha256:a027ef0492ede1e03a8054e3c37b8def89a1e3c471482e9f046906ba4f2aafd2"}, - {file = "coverage-5.1-cp35-cp35m-win_amd64.whl", hash = "sha256:0e61d9803d5851849c24f78227939c701ced6704f337cad0a91e0972c51c1ee7"}, - {file = "coverage-5.1-cp36-cp36m-macosx_10_13_x86_64.whl", hash = "sha256:2d27a3f742c98e5c6b461ee6ef7287400a1956c11421eb574d843d9ec1f772f0"}, - {file = "coverage-5.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:66460ab1599d3cf894bb6baee8c684788819b71a5dc1e8fa2ecc152e5d752019"}, - {file = "coverage-5.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:5c542d1e62eece33c306d66fe0a5c4f7f7b3c08fecc46ead86d7916684b36d6c"}, - {file = "coverage-5.1-cp36-cp36m-win32.whl", hash = "sha256:2742c7515b9eb368718cd091bad1a1b44135cc72468c731302b3d641895b83d1"}, - {file = "coverage-5.1-cp36-cp36m-win_amd64.whl", hash = "sha256:dead2ddede4c7ba6cb3a721870f5141c97dc7d85a079edb4bd8d88c3ad5b20c7"}, - {file = "coverage-5.1-cp37-cp37m-macosx_10_13_x86_64.whl", hash = "sha256:01333e1bd22c59713ba8a79f088b3955946e293114479bbfc2e37d522be03355"}, - {file = "coverage-5.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:e1ea316102ea1e1770724db01998d1603ed921c54a86a2efcb03428d5417e489"}, - {file = "coverage-5.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:adeb4c5b608574a3d647011af36f7586811a2c1197c861aedb548dd2453b41cd"}, - {file = "coverage-5.1-cp37-cp37m-win32.whl", hash = "sha256:782caea581a6e9ff75eccda79287daefd1d2631cc09d642b6ee2d6da21fc0a4e"}, - {file = "coverage-5.1-cp37-cp37m-win_amd64.whl", hash = "sha256:00f1d23f4336efc3b311ed0d807feb45098fc86dee1ca13b3d6768cdab187c8a"}, - {file = "coverage-5.1-cp38-cp38-macosx_10_13_x86_64.whl", hash = "sha256:402e1744733df483b93abbf209283898e9f0d67470707e3c7516d84f48524f55"}, - {file = "coverage-5.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:a3f3654d5734a3ece152636aad89f58afc9213c6520062db3978239db122f03c"}, - {file = "coverage-5.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:6402bd2fdedabbdb63a316308142597534ea8e1895f4e7d8bf7476c5e8751fef"}, - {file = "coverage-5.1-cp38-cp38-win32.whl", hash = "sha256:8fa0cbc7ecad630e5b0f4f35b0f6ad419246b02bc750de7ac66db92667996d24"}, - {file = "coverage-5.1-cp38-cp38-win_amd64.whl", hash = "sha256:79a3cfd6346ce6c13145731d39db47b7a7b859c0272f02cdb89a3bdcbae233a0"}, - {file = "coverage-5.1-cp39-cp39-win32.whl", hash = "sha256:a82b92b04a23d3c8a581fc049228bafde988abacba397d57ce95fe95e0338ab4"}, - {file = "coverage-5.1-cp39-cp39-win_amd64.whl", hash = "sha256:bb28a7245de68bf29f6fb199545d072d1036a1917dca17a1e75bbb919e14ee8e"}, - {file = "coverage-5.1.tar.gz", hash = "sha256:f90bfc4ad18450c80b024036eaf91e4a246ae287701aaa88eaebebf150868052"}, + {file = "coverage-5.2-cp27-cp27m-macosx_10_13_intel.whl", hash = "sha256:d9ad0a988ae20face62520785ec3595a5e64f35a21762a57d115dae0b8fb894a"}, + {file = "coverage-5.2-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:4bb385a747e6ae8a65290b3df60d6c8a692a5599dc66c9fa3520e667886f2e10"}, + {file = "coverage-5.2-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:9702e2cb1c6dec01fb8e1a64c015817c0800a6eca287552c47a5ee0ebddccf62"}, + {file = "coverage-5.2-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:42fa45a29f1059eda4d3c7b509589cc0343cd6bbf083d6118216830cd1a51613"}, + {file = "coverage-5.2-cp27-cp27m-win32.whl", hash = "sha256:41d88736c42f4a22c494c32cc48a05828236e37c991bd9760f8923415e3169e4"}, + {file = "coverage-5.2-cp27-cp27m-win_amd64.whl", hash = "sha256:bbb387811f7a18bdc61a2ea3d102be0c7e239b0db9c83be7bfa50f095db5b92a"}, + {file = "coverage-5.2-cp27-cp27mu-manylinux1_i686.whl", hash = "sha256:3740b796015b889e46c260ff18b84683fa2e30f0f75a171fb10d2bf9fb91fc70"}, + {file = "coverage-5.2-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:ebf2431b2d457ae5217f3a1179533c456f3272ded16f8ed0b32961a6d90e38ee"}, + {file = "coverage-5.2-cp35-cp35m-macosx_10_13_x86_64.whl", hash = "sha256:d54d7ea74cc00482a2410d63bf10aa34ebe1c49ac50779652106c867f9986d6b"}, + {file = "coverage-5.2-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:87bdc8135b8ee739840eee19b184804e5d57f518578ffc797f5afa2c3c297913"}, + {file = "coverage-5.2-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:ed9a21502e9223f563e071759f769c3d6a2e1ba5328c31e86830368e8d78bc9c"}, + {file = "coverage-5.2-cp35-cp35m-win32.whl", hash = "sha256:509294f3e76d3f26b35083973fbc952e01e1727656d979b11182f273f08aa80b"}, + {file = "coverage-5.2-cp35-cp35m-win_amd64.whl", hash = "sha256:ca63dae130a2e788f2b249200f01d7fa240f24da0596501d387a50e57aa7075e"}, + {file = "coverage-5.2-cp36-cp36m-macosx_10_13_x86_64.whl", hash = "sha256:5c74c5b6045969b07c9fb36b665c9cac84d6c174a809fc1b21bdc06c7836d9a0"}, + {file = "coverage-5.2-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:c32aa13cc3fe86b0f744dfe35a7f879ee33ac0a560684fef0f3e1580352b818f"}, + {file = "coverage-5.2-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:1e58fca3d9ec1a423f1b7f2aa34af4f733cbfa9020c8fe39ca451b6071237405"}, + {file = "coverage-5.2-cp36-cp36m-win32.whl", hash = "sha256:3b2c34690f613525672697910894b60d15800ac7e779fbd0fccf532486c1ba40"}, + {file = "coverage-5.2-cp36-cp36m-win_amd64.whl", hash = "sha256:a4d511012beb967a39580ba7d2549edf1e6865a33e5fe51e4dce550522b3ac0e"}, + {file = "coverage-5.2-cp37-cp37m-macosx_10_13_x86_64.whl", hash = "sha256:32ecee61a43be509b91a526819717d5e5650e009a8d5eda8631a59c721d5f3b6"}, + {file = "coverage-5.2-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:6f91b4492c5cde83bfe462f5b2b997cdf96a138f7c58b1140f05de5751623cf1"}, + {file = "coverage-5.2-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:bfcc811883699ed49afc58b1ed9f80428a18eb9166422bce3c31a53dba00fd1d"}, + {file = "coverage-5.2-cp37-cp37m-win32.whl", hash = "sha256:60a3d36297b65c7f78329b80120f72947140f45b5c7a017ea730f9112b40f2ec"}, + {file = "coverage-5.2-cp37-cp37m-win_amd64.whl", hash = "sha256:12eaccd86d9a373aea59869bc9cfa0ab6ba8b1477752110cb4c10d165474f703"}, + {file = "coverage-5.2-cp38-cp38-macosx_10_13_x86_64.whl", hash = "sha256:d82db1b9a92cb5c67661ca6616bdca6ff931deceebb98eecbd328812dab52032"}, + {file = "coverage-5.2-cp38-cp38-manylinux1_i686.whl", hash = "sha256:214eb2110217f2636a9329bc766507ab71a3a06a8ea30cdeebb47c24dce5972d"}, + {file = "coverage-5.2-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:8a3decd12e7934d0254939e2bf434bf04a5890c5bf91a982685021786a08087e"}, + {file = "coverage-5.2-cp38-cp38-win32.whl", hash = "sha256:1dcebae667b73fd4aa69237e6afb39abc2f27520f2358590c1b13dd90e32abe7"}, + {file = "coverage-5.2-cp38-cp38-win_amd64.whl", hash = "sha256:f50632ef2d749f541ca8e6c07c9928a37f87505ce3a9f20c8446ad310f1aa87b"}, + {file = "coverage-5.2-cp39-cp39-macosx_10_13_x86_64.whl", hash = "sha256:7403675df5e27745571aba1c957c7da2dacb537c21e14007ec3a417bf31f7f3d"}, + {file = "coverage-5.2-cp39-cp39-manylinux1_i686.whl", hash = "sha256:0fc4e0d91350d6f43ef6a61f64a48e917637e1dcfcba4b4b7d543c628ef82c2d"}, + {file = "coverage-5.2-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:25fe74b5b2f1b4abb11e103bb7984daca8f8292683957d0738cd692f6a7cc64c"}, + {file = "coverage-5.2-cp39-cp39-win32.whl", hash = "sha256:d67599521dff98ec8c34cd9652cbcfe16ed076a2209625fca9dc7419b6370e5c"}, + {file = "coverage-5.2-cp39-cp39-win_amd64.whl", hash = "sha256:10f2a618a6e75adf64329f828a6a5b40244c1c50f5ef4ce4109e904e69c71bd2"}, + {file = "coverage-5.2.tar.gz", hash = "sha256:1874bdc943654ba46d28f179c1846f5710eda3aeb265ff029e0ac2b52daae404"}, ] crashtest = [ {file = "crashtest-0.3.0-py3-none-any.whl", hash = "sha256:06069a9267c54be31c42b03574b72407bf780e13c82cb0238f24ea69cf25b6dd"}, @@ -1423,6 +1426,11 @@ markupsafe = [ {file = "MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6"}, {file = "MarkupSafe-1.1.1-cp37-cp37m-win32.whl", hash = "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2"}, {file = "MarkupSafe-1.1.1-cp37-cp37m-win_amd64.whl", hash = "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c"}, + {file = "MarkupSafe-1.1.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15"}, + {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2"}, + {file = "MarkupSafe-1.1.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42"}, + {file = "MarkupSafe-1.1.1-cp38-cp38-win32.whl", hash = "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b"}, + {file = "MarkupSafe-1.1.1-cp38-cp38-win_amd64.whl", hash = "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be"}, {file = "MarkupSafe-1.1.1.tar.gz", hash = "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b"}, ] mkdocs = [ @@ -1550,7 +1558,7 @@ pytest-mock = [ {file = "pytest_mock-1.13.0-py2.py3-none-any.whl", hash = "sha256:67e414b3caef7bff6fc6bd83b22b5bc39147e4493f483c2679bc9d4dc485a94d"}, ] pytest-sugar = [ - {file = "pytest-sugar-0.9.3.tar.gz", hash = "sha256:1630b5b7ea3624919b73fde37cffb87965c5087a4afab8a43074ff44e0d810c4"}, + {file = "pytest-sugar-0.9.4.tar.gz", hash = "sha256:b1b2186b0a72aada6859bea2a5764145e3aaa2c1cfbb23c3a19b5f7b697563d3"}, ] pywin32-ctypes = [ {file = "pywin32-ctypes-0.2.0.tar.gz", hash = "sha256:24ffc3b341d457d48e8922352130cf2644024a4ff09762a2261fd34c36ee5942"}, @@ -1682,9 +1690,8 @@ typed-ast = [ {file = "typed_ast-1.4.1.tar.gz", hash = "sha256:8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b"}, ] typing = [ - {file = "typing-3.7.4.1-py2-none-any.whl", hash = "sha256:c8cabb5ab8945cd2f54917be357d134db9cc1eb039e59d1606dc1e60cb1d9d36"}, - {file = "typing-3.7.4.1-py3-none-any.whl", hash = "sha256:f38d83c5a7a7086543a0f649564d661859c5146a85775ab90c0d2f93ffaa9714"}, - {file = "typing-3.7.4.1.tar.gz", hash = "sha256:91dfe6f3f706ee8cc32d38edbbf304e9b7583fb37108fef38229617f8b3eba23"}, + {file = "typing-3.7.4.2-py2-none-any.whl", hash = "sha256:e470592ab1725d6810cd91d687c857a853d136d9a9dc9289713fa887f39b931a"}, + {file = "typing-3.7.4.2.tar.gz", hash = "sha256:6f6f3553709d2234e412092e5daa93aaaaa42ea1854505442280b39f9311707f"}, ] typing-extensions = [ {file = "typing_extensions-3.7.4.2-py2-none-any.whl", hash = "sha256:f8d2bd89d25bc39dabe7d23df520442fa1d8969b82544370e03d88b5a591c392"}, @@ -1696,8 +1703,8 @@ urllib3 = [ {file = "urllib3-1.25.9.tar.gz", hash = "sha256:3018294ebefce6572a474f0604c2021e33b3fd8006ecd11d62107a5d2a963527"}, ] virtualenv = [ - {file = "virtualenv-20.0.25-py2.py3-none-any.whl", hash = "sha256:ffffcb3c78a671bb3d590ac3bc67c081ea2188befeeb058870cba13e7f82911b"}, - {file = "virtualenv-20.0.25.tar.gz", hash = "sha256:f332ba0b2dfbac9f6b1da9f11224f0036b05cdb4df23b228527c2a2d5504aeed"}, + {file = "virtualenv-20.0.26-py2.py3-none-any.whl", hash = "sha256:c11a475400e98450403c0364eb3a2d25d42f71cf1493da64390487b666de4324"}, + {file = "virtualenv-20.0.26.tar.gz", hash = "sha256:e10cc66f40cbda459720dfe1d334c4dc15add0d80f09108224f171006a97a172"}, ] wcwidth = [ {file = "wcwidth-0.2.5-py2.py3-none-any.whl", hash = "sha256:beb4802a9cebb9144e99086eff703a642a13d6a0052920003a230f3294bbe784"}, diff --git a/poetry/inspection/info.py b/poetry/inspection/info.py index 0380bca7720..8e56dec4e0c 100644 --- a/poetry/inspection/info.py +++ b/poetry/inspection/info.py @@ -1,5 +1,6 @@ import glob import logging +import os import subprocess import tarfile import zipfile @@ -12,8 +13,6 @@ import pkginfo -from pep517.build import compat_system as pep517_compat_system -from pep517.meta import build as pep517_metadata_build from poetry.core.factory import Factory from poetry.core.packages import Package from poetry.core.packages import ProjectPackage @@ -23,12 +22,26 @@ from poetry.core.utils.helpers import parse_requires from poetry.core.utils.helpers import temporary_directory from poetry.core.version.markers import InvalidMarker +from poetry.utils.env import EnvCommandError +from poetry.utils.env import EnvManager +from poetry.utils.env import VirtualEnv from poetry.utils.setup_reader import SetupReader from poetry.utils.toml_file import TomlFile logger = logging.getLogger(__name__) +PEP517_META_BUILD = """\ +import pep517.build +import pep517.meta + +path='{source}' +system=pep517.build.compat_system(path) +pep517.meta.build(source_dir=path, dest='{dest}', system=system) +""" + +PEP517_META_BUILD_DEPS = ["pep517===0.8.2", "toml==0.10.1"] + class PackageInfoError(ValueError): def __init__(self, path): # type: (Union[Path, str]) -> None @@ -255,6 +268,10 @@ def _from_sdist_file(cls, path): # type: (Path) -> PackageInfo return info.update(new_info) + @staticmethod + def has_setup_files(path): # type: (Path) -> bool + return any((path / f).exists() for f in SetupReader.FILES) + @classmethod def from_setup_files(cls, path): # type: (Path) -> PackageInfo """ @@ -264,7 +281,7 @@ def from_setup_files(cls, path): # type: (Path) -> PackageInfo :param path: Path to `setup.py` file """ - if not any((path / f).exists() for f in SetupReader.FILES): + if not cls.has_setup_files(path): raise PackageInfoError(path) try: @@ -416,14 +433,51 @@ def _pep517_metadata(cls, path): # type (Path) -> PackageInfo except PackageInfoError: pass + cwd = Path.cwd() + os.chdir(path.as_posix()) + try: with temporary_directory() as tmp_dir: - pep517_metadata_build( - source_dir=path.as_posix(), - dest=tmp_dir, - system=pep517_compat_system(source_dir=path.as_posix()), - ) - return cls.from_metadata(Path(tmp_dir)) + # TODO: cache PEP 517 build environment corresponding to each project venv + venv_dir = Path(tmp_dir) / ".venv" + EnvManager.build_venv(venv_dir.as_posix()) + venv = VirtualEnv(venv_dir, venv_dir) + + dest_dir = Path(tmp_dir) / "dist" + dest_dir.mkdir() + + try: + venv.run( + "python", + "-m", + "pip", + "install", + "--disable-pip-version-check", + "--ignore-installed", + *PEP517_META_BUILD_DEPS + ) + venv.run( + "python", + "-c", + PEP517_META_BUILD.format( + source=path.as_posix(), dest=dest_dir.as_posix() + ), + ) + return cls.from_metadata(dest_dir) + except EnvCommandError as e: + # something went wrong while attempting pep517 metadata build + # fallback to egg_info if setup.py available + cls._log("PEP517 build failed: {}".format(e), level="debug") + setup_py = path / "setup.py" + if not setup_py.exists(): + raise PackageInfoError(path) + + try: + venv.run("python", "setup.py", "egg_info") + return cls.from_metadata(path) + except EnvCommandError: + raise PackageInfoError(path) + except subprocess.CalledProcessError: cls._log("PEP 517 metadata build failed for {}".format(path), "debug") if info: @@ -431,6 +485,8 @@ def _pep517_metadata(cls, path): # type (Path) -> PackageInfo "Falling back to parsed setup.py file for {}".format(path), "debug" ) return info + finally: + os.chdir(cwd.as_posix()) # if we reach here, everything has failed and all hope is lost raise PackageInfoError(path) diff --git a/pyproject.toml b/pyproject.toml index 9810646874a..2be84d1b3da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,7 +60,6 @@ keyring = [ # Use subprocess32 for Python 2.7 subprocess32 = { version = "^3.5", python = "~2.7" } importlib-metadata = {version = "^1.6.0", python = "<3.8"} -pep517 = "^0.8.2" [tool.poetry.dev-dependencies] pytest = [ diff --git a/tests/inspection/test_info.py b/tests/inspection/test_info.py index 748334a4f3d..d82526943d9 100644 --- a/tests/inspection/test_info.py +++ b/tests/inspection/test_info.py @@ -3,9 +3,13 @@ import pytest from poetry.inspection.info import PackageInfo +from poetry.inspection.info import PackageInfoError from poetry.utils._compat import PY35 +from poetry.utils._compat import CalledProcessError from poetry.utils._compat import Path from poetry.utils._compat import decode +from poetry.utils.env import EnvCommandError +from poetry.utils.env import VirtualEnv FIXTURE_DIR_BASE = Path(__file__).parent.parent / "fixtures" @@ -149,18 +153,30 @@ def test_info_no_setup_pkg_info_no_deps(): assert info.requires_dist is None +@pytest.mark.skipif(not PY35, reason="Parsing of setup.py is skipped for Python < 3.5") def test_info_setup_simple(mocker, demo_setup): - pep517_metadata_build = mocker.patch("pep517.meta.build") + spy = mocker.spy(VirtualEnv, "run") + info = PackageInfo.from_directory(demo_setup, allow_build=True) + assert spy.call_count == 0 + demo_check_info(info, requires_dist={"package"}) + + +@pytest.mark.skipif( + PY35, + reason="For projects with setup.py using Python < 3.5 fallback to pep517 build", +) +def test_info_setup_simple_py2(mocker, demo_setup): + spy = mocker.spy(VirtualEnv, "run") info = PackageInfo.from_directory(demo_setup, allow_build=True) - pep517_metadata_build.assert_not_called() + assert spy.call_count == 2 demo_check_info(info, requires_dist={"package"}) @pytest.mark.skipif(not PY35, reason="Parsing of setup.cfg is skipped for Python < 3.5") def test_info_setup_cfg(mocker, demo_setup_cfg): - pep517_metadata_build = mocker.patch("pep517.meta.build") + spy = mocker.spy(VirtualEnv, "run") info = PackageInfo.from_directory(demo_setup_cfg, allow_build=True) - pep517_metadata_build.assert_not_called() + assert spy.call_count == 0 demo_check_info(info, requires_dist={"package"}) @@ -169,6 +185,17 @@ def test_info_setup_complex(demo_setup_complex): demo_check_info(info, requires_dist={"package"}) +def test_info_setup_complex_pep517_error(mocker, demo_setup_complex): + mocker.patch( + "poetry.utils.env.VirtualEnv.run", + auto_spec=True, + side_effect=EnvCommandError(CalledProcessError(1, "mock", output="mock")), + ) + + with pytest.raises(PackageInfoError): + PackageInfo.from_directory(demo_setup_complex, allow_build=True) + + def test_info_setup_complex_pep517_legacy(demo_setup_complex_pep517_legacy): info = PackageInfo.from_directory( demo_setup_complex_pep517_legacy, allow_build=True @@ -178,9 +205,9 @@ def test_info_setup_complex_pep517_legacy(demo_setup_complex_pep517_legacy): @pytest.mark.skipif(not PY35, reason="Parsing of setup.py is skipped for Python < 3.5") def test_info_setup_complex_disable_build(mocker, demo_setup_complex): - pep517_metadata_build = mocker.patch("pep517.meta.build") + spy = mocker.spy(VirtualEnv, "run") info = PackageInfo.from_directory(demo_setup_complex, allow_build=False) - pep517_metadata_build.assert_not_called() + assert spy.call_count == 0 assert info.name == "demo" assert info.version == "0.1.0" assert info.requires_dist is None