Parse RPM macro files and spec files, and expand macros safely—without the potential Turing-Complete side effects.
This is a standalone library that depends only on the standard Python library and PLY (for expression parsing).
$ norpm-expand-specfile --specfile SPEC --expand-string '%{?epoch}%{!?epoch:(none)}:%version'
(none):1.1.1Directly from Python, you can use:
from norpm.macrofile import system_macro_registry
from norpm.specfile import specfile_expand
registry = system_macro_registry()
with open("SPEC", "r", encoding="utf8") as fd:
expanded_specfile = specfile_expand(fd.read(), registry)
print("Name:", registry["name"].value)
print("Version:", registry["version"].value)There still are a few features to be implemented. Your contributions are welcome and greatly encouraged!