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.3.tar.gz (41.9 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for norpm-1.3.tar.gz
Algorithm Hash digest
SHA256 a1c0d06714d3e4d817d5e3f202b35a0a7a794921ee4262748db00565356cf9f2
MD5 72f99cc316b9407288752c153e57e045
BLAKE2b-256 815a0d9d1b385307f5027c9e731eedca39a66d70b408cf7a168d36d08f779206

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