Skip to content

Commit

Permalink
fix: ignore the expressions in dependency list when parsing setup.py
Browse files Browse the repository at this point in the history
Fix #1720
  • Loading branch information
frostming committed Feb 18, 2023
1 parent f6cc4eb commit 2c2bf3b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions news/1720.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the setup.py parser to ignore the expressions unable to parse as a string. This is safe for initializing a requirement.
10 changes: 4 additions & 6 deletions src/pdm/models/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,12 @@ def _find_install_requires(cls, call: ast.Call, body: Iterable[Any]) -> list[str
return install_requires

if isinstance(value, ast.List):
for el in value.elts:
install_requires.append(el.s)
install_requires.extend([el.s for el in value.elts if isinstance(el, ast.Str)])
elif isinstance(value, ast.Name):
variable = cls._find_variable_in_body(body, value.id)

if variable is not None and isinstance(variable, ast.List):
for el in variable.elts:
install_requires.append(el.s)
install_requires.extend([el.s for el in variable.elts if isinstance(el, ast.Str)])

return install_requires

Expand Down Expand Up @@ -295,7 +293,7 @@ def _find_extras_require(cls, call: ast.Call, body: Iterable[Any]) -> dict[str,
val = cls._find_variable_in_body(body, val.id)

if isinstance(val, ast.List):
extras_require[key.s] = [e.s for e in val.elts]
extras_require[key.s] = [e.s for e in val.elts if isinstance(e, ast.Str)]
elif isinstance(value, ast.Name):
variable = cls._find_variable_in_body(body, value.id)

Expand All @@ -307,7 +305,7 @@ def _find_extras_require(cls, call: ast.Call, body: Iterable[Any]) -> dict[str,
val = cls._find_variable_in_body(body, val.id)

if isinstance(val, ast.List):
extras_require[key.s] = [e.s for e in val.elts]
extras_require[key.s] = [e.s for e in val.elts if isinstance(e, ast.Str)]

return extras_require

Expand Down

0 comments on commit 2c2bf3b

Please sign in to comment.