Skip to content

Commit

Permalink
Document validity of entities
Browse files Browse the repository at this point in the history
Signed-off-by: Nikola Forró <nforro@redhat.com>
  • Loading branch information
nforro committed Oct 27, 2023
1 parent 567e872 commit c54a12f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c54a12f

Please sign in to comment.