-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of the opensuse-distro-aliases package
- Loading branch information
0 parents
commit 09aee41
Showing
8 changed files
with
1,087 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
- package-ecosystem: "pip" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--- | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
pull_request: | ||
|
||
jobs: | ||
format: | ||
name: Ensure code is properly formatted | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.x' | ||
- uses: actions/cache@v4 | ||
with: | ||
path: ~/.cache/pypoetry/virtualenvs | ||
key: poetry-${{ hashFiles('poetry.lock') }} | ||
|
||
- run: pipx install poetry | ||
env: | ||
PIPX_BIN_DIR: /usr/bin | ||
|
||
- run: | | ||
poetry install | ||
poetry run ruff format --check --diff . | ||
poetry run ruff check | ||
build: | ||
name: Build the package | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.x" | ||
- uses: actions/cache@v4 | ||
with: | ||
path: ~/.cache/pypoetry/virtualenvs | ||
key: poetry-${{ hashFiles('poetry.lock') }} | ||
|
||
- run: pipx install poetry | ||
env: | ||
PIPX_BIN_DIR: /usr/bin | ||
|
||
- name: Run the build | ||
run: | | ||
poetry install | ||
poetry build | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: wheel | ||
path: dist/opensuse_distro_aliases*whl | ||
if-no-files-found: error | ||
|
||
install: | ||
name: Install the package | ||
runs-on: "ubuntu-latest" | ||
needs: build | ||
|
||
steps: | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: wheel | ||
path: dist | ||
|
||
- name: install the wheel | ||
run: pip install --break-system-packages dist/opensuse_distro_aliases*whl | ||
|
||
- name: run a smoke test that the package has been installed | ||
run: | | ||
python3 -c "from opensuse_distro_aliases import get_distro_aliases; print(get_distro_aliases())" | ||
lint: | ||
name: Lint the source code | ||
runs-on: ubuntu-latest | ||
needs: build | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.x' | ||
|
||
- uses: actions/cache@v4 | ||
with: | ||
path: ~/.cache/pypoetry/virtualenvs | ||
key: poetry-${{ hashFiles('poetry.lock') }} | ||
|
||
- run: pipx install poetry | ||
env: | ||
PIPX_BIN_DIR: /usr/bin | ||
|
||
- run: poetry install | ||
|
||
# grab the previously built wheel for checking with twine | ||
- uses: actions/download-artifact@v4 | ||
with: | ||
name: wheel | ||
path: dist | ||
|
||
- run: poetry run mypy --strict src/ | ||
- run: poetry run twine check dist/*whl | ||
- run: poetry run ruff check | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
openSUSE Distribution Aliases | ||
----------------------------- | ||
|
||
|
||
This project provides a list of the currently maintained openSUSE | ||
distributions. It is the openSUSE equivalent of `fedora-distro-aliases | ||
<https://github.com/rpm-software-management/fedora-distro-aliases>`_. | ||
|
||
|
||
Usage | ||
===== | ||
|
||
.. code-block:: python-console | ||
>>> from opensuse_distro_aliases import get_distro_aliases | ||
>>> aliases = get_distro_aliases() | ||
Obtain the name and version of all currently active releases: | ||
|
||
.. code-block:: python-console | ||
>>> [f"{d.name} {d.version}" for d in aliases["opensuse-all"]] | ||
['openSUSE Leap 15.6', 'openSUSE Leap 15.5', 'openSUSE Leap Micro 6.0', 'openSUSE Leap Micro 5.5', 'openSUSE Tumbleweed 20240714'] | ||
Get the corresponding main development project in the `Open Build Service | ||
<https://build.opensuse.org/>`_: | ||
|
||
.. code-block:: python-console | ||
>>> [f"{d.name}: {d.obs_project_name}" for d in aliases["opensuse-all"] if d.obs_project_name] | ||
['openSUSE Leap: openSUSE:Leap:15.6', 'openSUSE Leap: openSUSE:Leap:15.5', 'openSUSE Tumbleweed: openSUSE:Factory'] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[tool.poetry] | ||
name = "opensuse-distro-aliases" | ||
version = "0.1.0" | ||
description = "Aliases for active openSUSE releases" | ||
authors = ["Dan Čermák <[email protected]>"] | ||
license = "MIT" | ||
readme = "README.rst" | ||
packages = [{include = "opensuse_distro_aliases", from = "src"}] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.9" | ||
requests = ">=2.32" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
mypy = ">=1.10" | ||
ruff = ">=0.5" | ||
twine = ">=5.1" | ||
types-requests = ">=2.32" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[tool.ruff.lint] | ||
select = [ | ||
# Pyflakes | ||
"F", | ||
# Pycodestyle | ||
"E", | ||
"W", | ||
# isort | ||
"I" | ||
] | ||
|
||
[tool.ruff] | ||
src = ["src"] | ||
target-version = "py39" | ||
|
||
[tool.ruff.lint.isort] | ||
force-single-line = true | ||
case-sensitive = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import xml.etree.ElementTree as ET | ||
from dataclasses import dataclass | ||
from typing import Dict | ||
from typing import List | ||
from typing import Literal | ||
from typing import TypedDict | ||
from typing import Union | ||
|
||
import requests | ||
|
||
__all__ = ["Distro", "get_distro_aliases"] | ||
|
||
|
||
@dataclass | ||
class Distro: | ||
"""An openSUSE distribution""" | ||
|
||
#: full name of the distribution | ||
name: str | ||
|
||
#: version number of this distribution | ||
version: str | ||
|
||
#: name-version of the distribution corresponding to the mock chroot | ||
namever: str | ||
|
||
#: main project on build.opensuse.org from which this distribution is built | ||
obs_project_name: str | None | ||
|
||
|
||
class _Release(TypedDict): | ||
name: str | ||
version: str | ||
|
||
|
||
class _StableRelease(_Release): | ||
state: Literal["Stable", "EOL"] | ||
|
||
|
||
def get_distro_aliases(include_eol: bool = False) -> Dict[str, List[Distro]]: | ||
"""Fetches the currently maintained openSUSE distributions from | ||
get.opensuse.org and returns a dictionary of alias groups | ||
(e.g. `opensuse-leap-all`) as keys and the list of distros as values. | ||
""" | ||
|
||
releases: Dict[str, List[Union[_Release, _StableRelease]]] = requests.get( | ||
"https://get.opensuse.org/api/v0/distributions.json" | ||
).json() | ||
|
||
productlist = ET.fromstring( | ||
requests.get( | ||
"https://api.opensuse.org/public/source/openSUSE?view=productlist&expand=1&format=xml" | ||
).text | ||
) | ||
|
||
res: Dict[str, List[Distro]] = {} | ||
|
||
for distro_name, distro_list in releases.items(): | ||
aliases = [] | ||
|
||
if distro_name == "LeapMicro": | ||
distro_name = "Leap-Micro" | ||
|
||
if distro_name == "Tumbleweed": | ||
d = distro_list[0] | ||
aliases.append( | ||
Distro( | ||
name=d["name"], | ||
version=d["version"], | ||
namever="opensuse-tumbleweed", | ||
obs_project_name="openSUSE:Factory", | ||
) | ||
) | ||
|
||
else: | ||
matching_products = productlist.findall(f"product[@name='{distro_name}']") | ||
|
||
for distri in distro_list: | ||
if include_eol or distri.get("state", "") != "EOL": | ||
version = distri["version"] | ||
obs_project = [ | ||
op | ||
for op in ( | ||
p.attrib.get("originproject", "") for p in matching_products | ||
) | ||
if op.endswith(version) | ||
] | ||
|
||
aliases.append( | ||
Distro( | ||
name=(n := distri["name"]), | ||
version=version, | ||
# stay compatible with mock chroot names | ||
namever=f"{n.lower().replace(' ', '-')}-{version}", | ||
obs_project_name=obs_project[0] if obs_project else None, | ||
) | ||
) | ||
|
||
if aliases: | ||
res[f"opensuse-{distro_name.lower()}-all"] = aliases | ||
|
||
opensuse_all = [] | ||
for distros in res.values(): | ||
opensuse_all.extend(distros) | ||
res["opensuse-all"] = opensuse_all | ||
|
||
return res |
Empty file.