Skip to content

Commit a2cf5fd

Browse files
Update README (#296)
Update README Reviewed-by: František Lachman <[email protected]>
2 parents 39bcedf + c54a12f commit a2cf5fd

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

README.md

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
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.
44

5-
This project is still a work in progress.
6-
75
## Motivation
86

97
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,11 +250,43 @@ print(tags.release.expanded_value)
252250
print(len(specfile.sources().content))
253251
```
254252

255-
## Caveats
253+
### Validity
254+
255+
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.
256+
257+
Consider the following in a spec file:
258+
259+
```specfile
260+
%if 0%{?fedora} >= 36
261+
Recommends: %{name}-selinux
262+
%endif
263+
```
264+
265+
Provided there are no other `Recommends` tags, the following would print `True` or `False` depending on the value of the `%fedora` macro:
266+
267+
```python
268+
with specfile.tags() as tags:
269+
print(tags.recommends.valid)
270+
```
271+
272+
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.
273+
274+
The same applies to `%ifarch`/`%ifos` statements:
275+
276+
```specfile
277+
%ifarch %{java_arches}
278+
BuildRequires: java-devel
279+
%endif
280+
```
256281

257-
### RPM macros
282+
Provided there are no other `BuildRequires` tags, the following would print `True` in case the current platform was part of `%java_arches`:
283+
284+
```python
285+
with specfile.tags() as tags:
286+
print(tags.buildrequires.valid)
287+
```
258288

259-
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.
289+
To override this, you would have to redefine the `%_target_cpu` system macro (or `%_target_os` in case of `%ifos`).
260290

261291
## Videos
262292

0 commit comments

Comments
 (0)