Skip to content

Commit 928aa2c

Browse files
jirivranyCopilot
andauthored
Update setup.py to avoid exec()
exec is generally considered insecure and may trigger more security warnings in the future Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 2c772c3 commit 928aa2c

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

setup.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,22 @@ def read_requirements(filename="requirements.txt"):
2121

2222

2323
# Import the __version__ variable
24-
with open("flowapp/__about__.py") as f:
25-
exec(f.read())
24+
import ast
2625

26+
with open("flowapp/__about__.py", "r", encoding="utf-8") as f:
27+
module_ast = ast.parse(f.read(), filename="flowapp/__about__.py")
28+
29+
__version__ = None
30+
for node in module_ast.body:
31+
if isinstance(node, ast.Assign) and len(node.targets) == 1:
32+
target = node.targets[0]
33+
if isinstance(target, ast.Name) and target.id == "__version__":
34+
if isinstance(node.value, ast.Constant) and isinstance(node.value.value, str):
35+
__version__ = node.value.value
36+
break
37+
38+
if __version__ is None:
39+
raise ValueError("Unable to find __version__ in flowapp/__about__.py")
2740
setuptools.setup(
2841
name="exafs",
2942
version=__version__, # noqa: F821

0 commit comments

Comments
 (0)