tools: add "tools" dir to LINTABLES and fix issues

The `./tools` dir was not part of the LINTABLES in the `tox.ini`
which meant that pep8/pylint etc checks were not run on the tools
there.

This commit adds it and fixes the issues that `make lint` found.
This commit is contained in:
Michael Vogt 2023-11-10 17:52:20 +01:00 committed by Simon de Vlieger
parent 9f4bd1fc31
commit d52738d70c
4 changed files with 17 additions and 14 deletions

View file

@ -5,6 +5,7 @@ and a list of Schutzfile entries not used by runners."""
import json import json
import sys import sys
import yaml import yaml

View file

@ -5,24 +5,25 @@ against the current snapshot list"""
import argparse import argparse
import json import json
import os import os
import sys
import subprocess import subprocess
import sys
import time import time
from urllib.parse import urlparse from urllib.parse import urlparse
import requests import requests
SNAPSHOTS_URL="https://rpmrepo.osbuild.org/v2/enumerate" SNAPSHOTS_URL = "https://rpmrepo.osbuild.org/v2/enumerate"
SNAPSHOTS_TIMEOUT = 2 * 60 SNAPSHOTS_TIMEOUT = 2 * 60
SNAPSHOT_GREP = ["grep", "--color=never", "-or", r"http.*rpmrepo.osbuild.org.*-20[0-9]\+"] SNAPSHOT_GREP = ["grep", "--color=never", "-or", r"http.*rpmrepo.osbuild.org.*-20[0-9]\+"]
def fetch_snapshots_api(url, timeout=SNAPSHOTS_TIMEOUT): def fetch_snapshots_api(url, timeout=SNAPSHOTS_TIMEOUT):
"""Get the list of snapshots from the rpmrepo API""" """Get the list of snapshots from the rpmrepo API"""
print(f"Fetching list of snapshots from {url}") print(f"Fetching list of snapshots from {url}")
start = time.time() start = time.time()
try: try:
r = requests.get(url, timeout=timeout) r = requests.get(url, timeout=timeout)
except: except BaseException:
return None return None
elapsed = time.time() - start elapsed = time.time() - start
if r.status_code != 200: if r.status_code != 200:
@ -143,7 +144,7 @@ def check_snapshot_urls(urls, snapshots, skip=["test/data/manifests", "test/data
# parse cmdline args # parse cmdline args
def parse_args(): def parse_args():
parser =argparse.ArgumentParser(description="Check snapshot urls") parser = argparse.ArgumentParser(description="Check snapshot urls")
parser.add_argument("--verbose") parser.add_argument("--verbose")
parser.add_argument("--timeout", type=int, default=SNAPSHOTS_TIMEOUT, parser.add_argument("--timeout", type=int, default=SNAPSHOTS_TIMEOUT,
help="How long to wait for rpmrepo snapshot list") help="How long to wait for rpmrepo snapshot list")
@ -155,6 +156,7 @@ def parse_args():
parser.add_argument("directory") parser.add_argument("directory")
return parser.parse_args() return parser.parse_args()
def main(): def main():
args = parse_args() args = parse_args()
urls = find_snapshot_urls(args.directory) urls = find_snapshot_urls(args.directory)
@ -164,7 +166,7 @@ def main():
try: try:
with open(args.cache, encoding="utf8") as f: with open(args.cache, encoding="utf8") as f:
snapshots = json.load(f) snapshots = json.load(f)
except: except BaseException:
print(f"No snapshots cache found at {args.cache}") print(f"No snapshots cache found at {args.cache}")
sys.exit(1) sys.exit(1)
else: else:
@ -176,5 +178,5 @@ def main():
return check_snapshot_urls(urls, snapshots, errors_only=args.errors_only) return check_snapshot_urls(urls, snapshots, errors_only=args.errors_only)
if __name__=='__main__': if __name__ == '__main__':
sys.exit(main()) sys.exit(main())

View file

@ -364,8 +364,7 @@ import hawkey
import rpm import rpm
import yaml import yaml
from osbuild.util import containers from osbuild.util import containers, ostree
from osbuild.util import ostree
from osbuild.util.rhsm import Subscriptions from osbuild.util.rhsm import Subscriptions
# We need to resolve an image name to a resolved image manifest digest # We need to resolve an image name to a resolved image manifest digest
@ -1314,6 +1313,7 @@ class ManifestFile:
def _process_ostree(self, _stage): def _process_ostree(self, _stage):
raise NotImplementedError() raise NotImplementedError()
class ManifestFileV1(ManifestFile): class ManifestFileV1(ManifestFile):
def __init__(self, path, overrides, default_vars, data, searchdirs): def __init__(self, path, overrides, default_vars, data, searchdirs):
super().__init__(path, overrides, default_vars, data, searchdirs, 1) super().__init__(path, overrides, default_vars, data, searchdirs, 1)
@ -1547,11 +1547,11 @@ class ManifestFileV2(ManifestFile):
def _process_container(self, stage): def _process_container(self, stage):
if stage.get("type", "") not in \ if stage.get("type", "") not in \
["org.osbuild.skopeo", "org.osbuild.ostree.deploy.container"]: ["org.osbuild.skopeo", "org.osbuild.ostree.deploy.container"]:
return return
inputs = element_enter(stage, "inputs", {}) inputs = element_enter(stage, "inputs", {})
inputs_images = element_enter(inputs, "images", {}) inputs_images = element_enter(inputs, "images", {})
if inputs_images.get("type", "") != "org.osbuild.containers": if inputs_images.get("type", "") != "org.osbuild.containers":
@ -1622,7 +1622,7 @@ class ManifestFileV2(ManifestFile):
def _process_ostree_commits(self, stage): def _process_ostree_commits(self, stage):
if stage.get("type", "") not in \ if stage.get("type", "") not in \
["org.osbuild.ostree.pull", "org.osbuild.ostree.deploy"]: ["org.osbuild.ostree.pull", "org.osbuild.ostree.deploy"]:
return return
# The ostree.deploy stage accepts both containers or # The ostree.deploy stage accepts both containers or
@ -1665,8 +1665,8 @@ class ManifestFileV2(ManifestFile):
# This is a temporary repo so we'll just use a random name # This is a temporary repo so we'll just use a random name
remote_name = "tmpremote" remote_name = "tmpremote"
ostree.setup_remote(tmprepo, remote_name, remote) ostree.setup_remote(tmprepo, remote_name, remote)
ostree.cli( "pull", "--commit-metadata-only", ostree.cli("pull", "--commit-metadata-only",
"--mirror", remote_name, ref, repo=tmprepo) "--mirror", remote_name, ref, repo=tmprepo)
checksum = ostree.rev_parse(tmprepo, ref) checksum = ostree.rev_parse(tmprepo, ref)
items[checksum] = { items[checksum] = {
"remote": remote "remote": remote

View file

@ -23,7 +23,7 @@ deps =
requests requests
setenv = setenv =
LINTABLES = osbuild/ assemblers/* devices/* inputs/* mounts/* runners/* sources/* stages/*.* stages/test/*.py LINTABLES = osbuild/ assemblers/* devices/* inputs/* mounts/* runners/* sources/* stages/*.* stages/test/*.py tools/
TYPEABLES = osbuild TYPEABLES = osbuild
passenv = passenv =