Skip to content

Commit

Permalink
Add an attribute with always numeric version number
Browse files Browse the repository at this point in the history
Fix #9

For example for Fedora Rawhide that would mean that `distro.version`
will be `"rawhide"` and `distro.version_number` will be e.g. `"41"`.
  • Loading branch information
FrostyX committed Mar 10, 2024
1 parent 4136d98 commit c633a3c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ Branch names in DistGit:
Only version numbers:

```python
>>> [x.version for x in aliases["fedora-stable"]]
['38', '39']
>>> [x.version for x in aliases["fedora-all"]]
['38', '39', 'rawhide']
```

If you need a numeric version even for rawhide:

```python
>>> [x.version_number for x in aliases["fedora-all"]]
['38', '39', '40']
```


Expand Down
6 changes: 4 additions & 2 deletions fedora_distro_aliases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_distro_aliases():
epel = []

distros = [Distro.from_bodhi_release(x) for x in releases if x.name != "ELN"]
distros.sort(key=lambda x: int(x.version))
distros.sort(key=lambda x: int(x.version_number))

epel = [x for x in distros if x.product == "epel"]
fedora = [x for x in distros if x.product == "fedora"]
Expand Down Expand Up @@ -79,7 +79,9 @@ def from_bodhi_release(cls, release):
Create a `Distro` object from Bodhi `release`
"""
keys = ["name", "long_name", "version", "state", "branch", "id_prefix"]
return cls({k: getattr(release, k) for k in keys})
distro = cls({k: getattr(release, k) for k in keys})
distro.version_number = release.version
return distro

@property
def product(self):
Expand Down
7 changes: 7 additions & 0 deletions tests/test_fedora_distro_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def test_distro():
assert distro.namever == "foo-123"
assert distro.product == "fedora"
assert distro.product == "fedora"
assert distro.version_number == "123"
assert "nonsense" not in distro
assert "additional" not in distro

Expand All @@ -62,3 +63,9 @@ def test_f40_branch_to_final_release_window(requests_get):
namevers = [x.namever for x in aliases["fedora-all"]]
expected = ["fedora-38", "fedora-39", "fedora-40", "fedora-rawhide"]
assert namevers == expected

versions = [x.version for x in aliases["fedora-all"]]
assert versions == ["38", "39", "40", "rawhide"]

version_numbers = [x.version_number for x in aliases["fedora-all"]]
assert version_numbers == ["38", "39", "40", "41"]

0 comments on commit c633a3c

Please sign in to comment.