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

Read description field from setup files #8545

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/poetry/utils/setup_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SetupReader:
DEFAULT: ClassVar[dict[str, Any]] = {
"name": None,
"version": None,
"description": None,
"install_requires": [],
"extras_require": {},
"python_requires": None,
Expand Down Expand Up @@ -62,6 +63,7 @@ def read_setup_py(self, filepath: Path) -> dict[str, Any]:
call, body = setup_call
result["name"] = self._find_single_string(call, body, "name")
result["version"] = self._find_single_string(call, body, "version")
result["description"] = self._find_single_string(call, body, "description")
result["install_requires"] = self._find_install_requires(call, body)
result["extras_require"] = self._find_extras_require(call, body)
result["python_requires"] = self._find_single_string(
Expand All @@ -77,12 +79,16 @@ def read_setup_cfg(self, filepath: Path) -> dict[str, Any]:

name = None
version = None
description = None
if parser.has_option("metadata", "name"):
name = parser.get("metadata", "name")

if parser.has_option("metadata", "version"):
version = Version.parse(parser.get("metadata", "version")).text

if parser.has_option("metadata", "description"):
description = parser.get("metadata", "description")

install_requires = []
extras_require: dict[str, list[str]] = {}
python_requires = None
Expand Down Expand Up @@ -112,6 +118,7 @@ def read_setup_cfg(self, filepath: Path) -> dict[str, Any]:
return {
"name": name,
"version": version,
"description": description,
"install_requires": install_requires,
"extras_require": extras_require,
"python_requires": python_requires,
Expand Down
6 changes: 6 additions & 0 deletions tests/utils/fixtures/setups/minimal/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from __future__ import annotations

from setuptools import setup


setup()
Empty file.
6 changes: 6 additions & 0 deletions tests/utils/fixtures/setups/with-setup-cfg-minimal/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from __future__ import annotations

from setuptools import setup


setup()
1 change: 1 addition & 0 deletions tests/utils/fixtures/setups/with-setup-cfg/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[metadata]
name = with-setup-cfg
version = 1.2.3
description = Package with setup.cfg

[options]
zip_safe = true
Expand Down
52 changes: 52 additions & 0 deletions tests/utils/test_setup_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,32 @@ def _setup(name: str) -> Path:
return _setup


def test_setup_reader_read_minimal_setup_py(setup: Callable[[str], Path]) -> None:
result = SetupReader.read_from_directory(setup("minimal"))

expected_name = None
expected_version = None
expected_description = None
expected_install_requires: list[str] = []
expected_extras_require: dict[str, list[str]] = {}
expected_python_requires = None

assert result["name"] == expected_name
assert result["version"] == expected_version
assert result["description"] == expected_description
assert result["install_requires"] == expected_install_requires
assert result["extras_require"] == expected_extras_require
assert result["python_requires"] == expected_python_requires


def test_setup_reader_read_first_level_setup_call_with_direct_types(
setup: Callable[[str], Path]
) -> None:
result = SetupReader.read_from_directory(setup("flask"))

expected_name = "Flask"
expected_version = None
expected_description = "A simple framework for building complex web applications."
expected_install_requires = [
"Werkzeug>=0.14",
"Jinja2>=2.10",
Expand All @@ -51,6 +70,7 @@ def test_setup_reader_read_first_level_setup_call_with_direct_types(

assert result["name"] == expected_name
assert result["version"] == expected_version
assert result["description"] == expected_description
assert result["install_requires"] == expected_install_requires
assert result["extras_require"] == expected_extras_require
assert result["python_requires"] == expected_python_requires
Expand All @@ -63,6 +83,7 @@ def test_setup_reader_read_first_level_setup_call_with_variables(

expected_name = None
expected_version = None
expected_description = None
expected_install_requires = [
"chardet>=3.0.2,<3.1.0",
"idna>=2.5,<2.8",
Expand All @@ -78,6 +99,7 @@ def test_setup_reader_read_first_level_setup_call_with_variables(

assert result["name"] == expected_name
assert result["version"] == expected_version
assert result["description"] == expected_description
assert result["install_requires"] == expected_install_requires
assert result["extras_require"] == expected_extras_require
assert result["python_requires"] == expected_python_requires
Expand All @@ -90,6 +112,7 @@ def test_setup_reader_read_sub_level_setup_call_with_direct_types(

expected_name = "SQLAlchemy"
expected_version = None
expected_description = "Database Abstraction Library"
expected_install_requires: list[str] = []
expected_extras_require = {
"mysql": ["mysqlclient"],
Expand All @@ -104,6 +127,7 @@ def test_setup_reader_read_sub_level_setup_call_with_direct_types(

assert result["name"] == expected_name
assert result["version"] == expected_version
assert result["description"] == expected_description
assert result["install_requires"] == expected_install_requires
assert result["extras_require"] == expected_extras_require
assert result["python_requires"] is None
Expand All @@ -114,6 +138,7 @@ def test_setup_reader_read_setup_cfg(setup: Callable[[str], Path]) -> None:

expected_name = "with-setup-cfg"
expected_version = "1.2.3"
expected_description = "Package with setup.cfg"
expected_install_requires = ["six", "tomlkit"]
expected_extras_require = {
"validation": ["cerberus"],
Expand All @@ -123,6 +148,25 @@ def test_setup_reader_read_setup_cfg(setup: Callable[[str], Path]) -> None:

assert result["name"] == expected_name
assert result["version"] == expected_version
assert result["description"] == expected_description
assert result["install_requires"] == expected_install_requires
assert result["extras_require"] == expected_extras_require
assert result["python_requires"] == expected_python_requires


def test_setup_reader_read_minimal_setup_cfg(setup: Callable[[str], Path]) -> None:
result = SetupReader.read_from_directory(setup("with-setup-cfg-minimal"))

expected_name = None
expected_version = None
expected_description = None
expected_install_requires: list[str] = []
expected_extras_require: dict[str, list[str]] = {}
expected_python_requires = None

assert result["name"] == expected_name
assert result["version"] == expected_version
assert result["description"] == expected_description
assert result["install_requires"] == expected_install_requires
assert result["extras_require"] == expected_extras_require
assert result["python_requires"] == expected_python_requires
Expand All @@ -138,12 +182,14 @@ def test_setup_reader_read_setup_kwargs(setup: Callable[[str], Path]) -> None:

expected_name = "pendulum"
expected_version = "2.0.4"
expected_description = "Python datetimes made easy"
expected_install_requires = ["python-dateutil>=2.6,<3.0", "pytzdata>=2018.3"]
expected_extras_require = {':python_version < "3.5"': ["typing>=3.6,<4.0"]}
expected_python_requires = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"

assert result["name"] == expected_name
assert result["version"] == expected_version
assert result["description"] == expected_description
assert result["install_requires"] == expected_install_requires
assert result["extras_require"] == expected_extras_require
assert result["python_requires"] == expected_python_requires
Expand All @@ -154,12 +200,14 @@ def test_setup_reader_read_setup_call_in_main(setup: Callable[[str], Path]) -> N

expected_name = "PyYAML"
expected_version = "3.13"
expected_description = "YAML parser and emitter for Python"
expected_install_requires: list[str] = []
expected_extras_require: dict[str, list[str]] = {}
expected_python_requires = None

assert result["name"] == expected_name
assert result["version"] == expected_version
assert result["description"] == expected_description
assert result["install_requires"] == expected_install_requires
assert result["extras_require"] == expected_extras_require
assert result["python_requires"] == expected_python_requires
Expand All @@ -172,12 +220,14 @@ def test_setup_reader_read_extras_require_with_variables(

expected_name = "extras_require_with_vars"
expected_version = "0.0.1"
expected_description = "test setup_reader.py"
expected_install_requires: list[str] = []
expected_extras_require = {"test": ["pytest"]}
expected_python_requires = None

assert result["name"] == expected_name
assert result["version"] == expected_version
assert result["description"] == expected_description
assert result["install_requires"] == expected_install_requires
assert result["extras_require"] == expected_extras_require
assert result["python_requires"] == expected_python_requires
Expand All @@ -188,6 +238,8 @@ def test_setup_reader_setuptools(setup: Callable[[str], Path]) -> None:

expected_name = "my_package"
expected_version = "0.1.2"
expected_description = "Just a description"

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