Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

Commit

Permalink
build(deps): add ability to depend on official addons (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReenigneArcher authored Jan 13, 2024
1 parent 4545942 commit 00efe32
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Kodistubs==20.0.1 # docs: https://romanvm.github.io/Kodistubs
pytest==7.4.4
pytest-cov==4.1.0
PyYAML==6.0.1
requests==2.31.0
rstcheck==6.2.0
Sphinx==7.1.2
sphinx-copybutton==0.5.2
Expand Down
32 changes: 30 additions & 2 deletions scripts/addon_yaml_to_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
# lib imports
from kodi_addon_checker.check_dependencies import VERSION_ATTRB as xbmc_versions
from lxml import etree
import requests
import yaml

# global vars
kodi_branch = os.getenv('KODI_BRANCH', 'Nexus').lower()


def handle_asset_elements(
parent: etree.ElementBase,
Expand All @@ -21,6 +25,16 @@ def handle_asset_elements(
etree.SubElement(parent, key).text = value


def get_branch_plugins():
url = f'http://mirrors.kodi.tv/addons/{kodi_branch}/addons.xml'
response = requests.get(url)

if response.status_code != 200:
raise Exception(f'Failed to get {url}')

return etree.fromstring(response.content)


def yaml_to_xml_lxml(yaml_file: str) -> str:
# Load YAML file
with open(yaml_file, 'r') as file:
Expand All @@ -30,18 +44,32 @@ def yaml_to_xml_lxml(yaml_file: str) -> str:
build_version = os.getenv('BUILD_VERSION')
if build_version: # update version if building from CI
data['addon']['version'] = build_version

branch_addons_xml = None

for requirement in data['addon']['requires']['import']:
if requirement.get('version'):
# if the version is specified in yaml, don't look it up
# this allows pinning a requirement to a specific version
continue

requirement_xml = None

if requirement['addon'].startswith('xbmc.'):
requirement['version'] = xbmc_versions[requirement['addon']][os.getenv(
'KODI_BRANCH', 'Nexus').lower()]['advised']
requirement['version'] = xbmc_versions[requirement['addon']][kodi_branch]['advised']
elif requirement['addon'].startswith('script.module.'):
requirement_xml = os.path.join(
os.getcwd(), 'third-party', 'repo-scripts', requirement['addon'], 'addon.xml')
else:
if not branch_addons_xml:
branch_addons_xml = get_branch_plugins() # only get the branch addons.xml if we need it

# get the requirement version from the branch addons.xml
addon = branch_addons_xml.xpath(f'//addon[@id="{requirement["addon"]}"]')
version = addon[0].attrib['version']
requirement['version'] = version

if requirement_xml:
# get the version property out of the addon tag
with open(requirement_xml, 'r', encoding='utf-8') as file:
requirement_data = etree.parse(file)
Expand Down

0 comments on commit 00efe32

Please sign in to comment.