You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I like that you extract information like author, version, etc. from a single source file.
Lately I came across this approach used in sphinxcontrib.autoprogram:
withopen(os.path.join('..', 'setup.py')) as_f:
_setup_ast=ast.parse(_f.read(), _f.name)
del_f# The full version, including alpha/beta/rc tags.release=next(
node.value.sfornodeinast.walk(_setup_ast)
if (isinstance(node, ast.Assign) andlen(node.targets) ==1andisinstance(node.targets[0], ast.Name) andnode.targets[0].id=='version'andisinstance(node.value, ast.Str))
)
They use the ast (abstract syntax tree) package from Python to scan for a variable called version. I think this is a more elegant solution and more robust.
The text was updated successfully, but these errors were encountered:
I like that you extract information like author, version, etc. from a single source file.
Lately I came across this approach used in
sphinxcontrib.autoprogram
:They use the
ast
(abstract syntax tree) package from Python to scan for a variable calledversion
. I think this is a more elegant solution and more robust.The text was updated successfully, but these errors were encountered: