Skip to main content

RPM Macro Expansion in Python

Project description

RPM Macro Expansion in Python

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).

How to Use It

$ norpm-expand-specfile --specfile SPEC --expand-string '%version %{!?epoch:(none)}'
1.1.1 (none)

Directly from Python, you can use:

from norpm.macrofile import system_macro_registry
from norpm.specfile import specfile_expand
registry = system_macro_registry()
registry["dist"] = ""
with open("my.spec", "r", encoding="utf8") as fd:
    expanded_specfile = specfile_expand(fd.read(), registry)
    print("Name:", registry["name"].value)
    print("Version:", registry["version"].value)

TODOs

There are many features still to be implemented. Your contributions are welcome and greatly encouraged!

  • %undefine
  • Parametric macro definitions + calls
  • %if, %else parsing (generic)
  • expression parsing (e.g., for %if)
  • %[expressions]
  • %{expand}
  • %bcond* support
  • %dnl
  • %{defined:}
  • version comparisons, like v"1" < v"1.2"
  • functions in expressions
  • %if[n]arch
  • rpmrc files (these e.g. define %optflags)
  • %include
  • %SOURCEN
  • Requires/BuildRequires parsing
  • %{gsub:}
  • %{lua:} (not safe, must be an opt-in)
  • %(shell) (not safe, must be an opt-in)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

norpm-1.0.tar.gz (41.3 kB view details)

Uploaded Source

File details

Details for the file norpm-1.0.tar.gz.

File metadata

  • Download URL: norpm-1.0.tar.gz
  • Upload date:
  • Size: 41.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for norpm-1.0.tar.gz
Algorithm Hash digest
SHA256 2997dc93809dbad58b6bd61c815beec5e16a68bc75b8b43117a2569ecd648df8
MD5 abba20f4c901942a156f124ded17e2f6
BLAKE2b-256 6b3f00d69d78af917cb2f43ac1c2ea9278596ab0e83b59c9430b5107886fa79a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page