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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for norpm-1.1.tar.gz
Algorithm Hash digest
SHA256 08b88393428e4af4f517cd4fd1b417e37025a98e5f00af17b6ee5d9a25274cf3
MD5 caecbdbc08cf18b1f4bc9acaa67c0dfc
BLAKE2b-256 e549b70c84897da7e46bed4e00f290cc99a49527f6def2079049987018ad67f6

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