Skip to content

Commit

Permalink
fix (setup_reader): parse arguments when setuptools.setup() is used (#…
Browse files Browse the repository at this point in the history
…1761) (#1764)

* fix (setup_reader): in `setup.py` the `setup()` method can also be called by `setuptools.setup()`

* fix (setup_reader): make black happy

* fix (setup_reader): skip test for python <3.4
  • Loading branch information
finswimmer authored and sdispater committed Dec 20, 2019
1 parent 9537309 commit 945ca1d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
9 changes: 5 additions & 4 deletions poetry/utils/setup_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ def _find_setup_call(
continue

func = value.func
if not isinstance(func, ast.Name):
continue

if func.id != "setup":
if not (isinstance(func, ast.Name) and func.id == "setup") and not (
isinstance(func, ast.Attribute)
and func.value.id == "setuptools"
and func.attr == "setup"
):
continue

return value, elements
Expand Down
11 changes: 11 additions & 0 deletions tests/utils/fixtures/setups/setuptools_setup/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import setuptools

setuptools.setup(
name="my_package",
version="0.1.2",
author="John Doe",
author_email="john@example.orh",
description="Just a description",
url="https://example.org",
packages=setuptools.find_packages(),
)
11 changes: 11 additions & 0 deletions tests/utils/test_setup_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,14 @@ def test_setup_reader_read_extras_require_with_variables(setup):
assert expected_install_requires == result["install_requires"]
assert expected_extras_require == result["extras_require"]
assert expected_python_requires == result["python_requires"]


@pytest.mark.skipif(not PY35, reason="AST parsing does not work for Python <3.4")
def test_setup_reader_setuptools(setup):
result = SetupReader.read_from_directory(setup("setuptools_setup"))

expected_name = "my_package"
expected_version = "0.1.2"

assert expected_name == result["name"]
assert expected_version == result["version"]

0 comments on commit 945ca1d

Please sign in to comment.