From 567e872589e272f1bcf7dec093d7ab7b83af6273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Fri, 27 Oct 2023 11:46:24 +0200 Subject: [PATCH 1/2] Remove WIP note and caveats section MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 9dbbdaf..d6cca65 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ Python library for parsing and manipulating RPM spec files. Main focus is on modifying existing spec files, any change should result in a minimal diff. -This project is still a work in progress. - ## Motivation Originally, [rebase-helper](https://github.com/rebase-helper/rebase-helper/) provided an API for spec file modifications that was also used by [packit](https://github.com/packit/packit). The goal of this project is to make the interface more general and convenient to use by not only packit but also by other Python projects that need to interact with RPM spec files. @@ -252,12 +250,6 @@ print(tags.release.expanded_value) print(len(specfile.sources().content)) ``` -## Caveats - -### RPM macros - -specfile uses RPM for parsing spec files and macro expansion. Unfortunately, macros are always stored in a global context, which poses a problem for multiple instances of Specfile. - ## Videos Here is a demo showcasing the `Specfile.update_tag()` method and its use cases: From c54a12f5e6d5a6701f6f8cd2dca68eb267dd673b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Fri, 27 Oct 2023 11:50:40 +0200 Subject: [PATCH 2/2] Document validity of entities MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nikola Forró --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index d6cca65..daf5774 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,44 @@ print(tags.release.expanded_value) print(len(specfile.sources().content)) ``` +### Validity + +Macro definitions, tags, `%sourcelist`/`%patchlist` entries and sources/patches have a `valid` attribute. An entity is considered valid if it isn't present in a false branch of any condition. + +Consider the following in a spec file: + +```specfile +%if 0%{?fedora} >= 36 +Recommends: %{name}-selinux +%endif +``` + +Provided there are no other `Recommends` tags, the following would print `True` or `False` depending on the value of the `%fedora` macro: + +```python +with specfile.tags() as tags: + print(tags.recommends.valid) +``` + +You can define macros or redefine/undefine system macros using the `macros` argument of the constructor or by modifying the `macros` attribute of a `Specfile` instance. + +The same applies to `%ifarch`/`%ifos` statements: + +```specfile +%ifarch %{java_arches} +BuildRequires: java-devel +%endif +``` + +Provided there are no other `BuildRequires` tags, the following would print `True` in case the current platform was part of `%java_arches`: + +```python +with specfile.tags() as tags: + print(tags.buildrequires.valid) +``` + +To override this, you would have to redefine the `%_target_cpu` system macro (or `%_target_os` in case of `%ifos`). + ## Videos Here is a demo showcasing the `Specfile.update_tag()` method and its use cases: