Skip to content

[CI] Fix warnings instead of hiding them #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 72 additions & 46 deletions .github/validate-rapps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pathlib import Path
import sys
from enum import Enum, unique
import struct;
import struct


# TODO: make this even nicer by using https://github.com/pytorch/add-annotations-github-action
Expand Down Expand Up @@ -64,14 +64,16 @@
]

LICENSE_TYPES = [
1, # Open source
2, # Freeware
3, # Trial/Demo
1, # Open source
2, # Freeware
3, # Trial/Demo
]


def get_valid_keys(section_name):
return KEYS[section_name]


all_names = {}
all_urls = {}
g_current_section = None
Expand All @@ -93,7 +95,7 @@ def __init__(self):

def add(self, line, column, problem):
self._problems += 1
print('{col}: {msg}'.format(col = line.location(column), msg = problem))
print("{col}: {msg}".format(col=line.location(column), msg=problem))
print(line.text())
idx = column - 1 + len("b'") # Offset the b' prefix
print(' ' * idx + '^')
Expand Down Expand Up @@ -158,15 +160,25 @@ def _parse_section(self, reporter, stripped):

if section_name not in KEYS:
help = 'should always be "Section"'
reporter.add(self, self._text.index(section_name) + 1,
'Invalid section name: "{sec}", {msg}'.format(sec = section_name, msg = help))
reporter.add(
self,
self._text.index(section_name) + 1,
'Invalid section name: "{sec}", {msg}'.format(
sec=section_name, msg=help
),
)
elif not locale:
self.main_section = True

if locale:
if len(locale) not in (2, 4) or not all(c in HEXDIGITS for c in locale):
reporter.add(self, self._text.index(locale) + 1,
'Invalid locale{extra}: "{loc}"'.format(extra = extra_locale, loc = locale))
reporter.add(
self,
self._text.index(locale) + 1,
'Invalid locale{extra}: "{loc}"'.format(
extra=extra_locale, loc=locale
),
)

if arch:
if arch not in ALL_ARCH:
Expand Down Expand Up @@ -205,43 +217,71 @@ def _parse_key_value(self, reporter, parts):
textval = self.val.decode()

if self.key not in get_valid_keys(g_current_section):
reporter.add(self, 0, 'Unknown key: "{key}"'.format(key = textkey))
reporter.add(self, 0, 'Unknown key: "{key}"'.format(key=textkey))

if self.key in [b'LicenseType']:
v = int(textval, base=10)
if v not in LICENSE_TYPES:
reporter.add(self, 0, 'Invalid value: "{val}" in {key}'.format(val = v, key = textkey))
reporter.add(self, 0, 'Invalid value: "{val}" in {key}'.format(val=v, key=textkey))

if self.key in [b'License']:
v = textval
if v.casefold() == 'Unknown'.casefold():
# TODO: Reporter should be enabled when the existing DB entries are fixed:
# reporter.add(self, 0, 'Invalid value: "{val}" in {key}'.format(val = v, key = textkey))
print('Warning: {key} is "{val}" ({file})'.format(val = v, key = textkey, file = self._file.filename))
print(
'Warning: {key} is "{val}" ({file})'.format(
val=v, key=textkey, file=self._file.filename
)
)

if self.key in [b'Scope']:
v = textval
if v.casefold() not in ['user', 'machine']:
print('Warning: {key} is "{val}" ({file})'.format(val = v, key = textkey, file = self._file.filename))
print(
'Warning: {key} is "{val}" ({file})'.format(
val=v, key=textkey, file=self._file.filename
)
)

def location(self, column):
return '{file}({line}:{col})'.format(file = self._file.filename, line = self._lineno, col = column)
return "{file}({line}:{col})".format(
file=self._file.filename, line=self._lineno, col=column
)

def text(self):
return self._text


def verify_unique(reporter, lines, line, name):
first = lines.get(name, None)
if first:
reporter.add(line, 0, "Duplicate value found: {name}".format(name=name))
reporter.add(first, 0, 'First occurence:')
else:
lines[name] = line


def verify_uniqueness(name, ver, url, reporter):
# Verify that the application name and version is unique
if name:
if ver:
verify_unique(reporter, all_names, name, name.val + b', version ' + ver.val)
else:
verify_unique(reporter, all_names, name, name.val)

# Verify that the download URL is unique
if url:
verify_unique(reporter, all_urls, url, url.val)


class RappsFile:
def __init__(self, fullname):
self.path = fullname
self.filename = fullname.name
self._sections = []

def parse(self, reporter):
with open(str(self.path), 'rb') as f:
lines = [RappsLine(self, idx + 1, line) for idx, line in enumerate(f.readlines())]

# Create sections from all lines, and add keyvalue entries in their own section
def _parse_lines(self, lines, reporter):
section = None
for line in lines:
linetype = line.parse(reporter)
Expand All @@ -254,6 +294,13 @@ def parse(self, reporter):
assert section, "Got no section yet?"
section.add(line)

def parse(self, reporter):
with open(str(self.path), 'rb') as f:
lines = [RappsLine(self, idx + 1, line) for idx, line in enumerate(f.readlines())]

# Create sections from all lines, and add keyvalue entries in their own section
self._parse_lines(lines, reporter)

all_sections = []
main_section = None
name = None
Expand All @@ -270,41 +317,19 @@ def parse(self, reporter):
main_section = section
for key in REQUIRED_SECTION_KEYS:
if not section[key]:
reporter.add(section, 0, 'Main section has no {key} key!'.format(key = key))
reporter.add(section, 0, 'Main section has no {key} key!'.format(key=key))
if section[b'URLDownload'] and not section[b'SizeBytes']:
# We allow this, if the main section has a SizeBytes (alternate mirror without duplicating the info)
if section == main_section or main_section and not main_section[b'SizeBytes']:
reporter.add(section, 0, 'Section has URLDownload but no SizeBytes!')

if section[b'Name'] and not name:
name = section[b'Name']
if section[b'Version'] and not ver:
ver = section[b'Version']
if section[b'URLDownload'] and not url:
url = section[b'URLDownload']

# Verify that the application name and version is unique
if name:
global all_names
if ver:
verify_unique(reporter, all_names, name, name.val + b', version ' + ver.val)
else:
verify_unique(reporter, all_names, name, name.val)
name = name if name else section[b'Name']
ver = ver if ver else section[b'Version']
url = url if url else section[b'URLDownload']

# Verify that the download URL is unique
if url:
global all_urls
verify_unique(reporter, all_urls, url, url.val)
verify_uniqueness(name, ver, url, reporter)


def verify_unique(reporter, lines, line, name):
first = lines.get(name, None)
if first:
reporter.add(line, 0, 'Duplicate value found: {name}'.format(name = name))
reporter.add(first, 0, 'First occurence:')
else:
lines[name] = line

def validate_single_icon(icon, reporter):
try:
with open(str(icon), 'rb') as f:
Expand All @@ -323,6 +348,7 @@ def validate_single_icon(icon, reporter):
except Exception as e:
reporter.add_file('icons/' + icon.name, 'Exception while reading icon: ' + str(e))


def validate_icons(ico_dir, reporter):
for icon in ico_dir.glob('*.ico'):
validate_single_icon(icon, reporter)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-rapps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --ignore=F824 --show-source --statistics
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Validate RAPPS entries
Expand Down