Skip to content
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

GHA CI: check python scripts #20590

Merged
merged 3 commits into from
Mar 25, 2024
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
79 changes: 79 additions & 0 deletions .github/workflows/ci_python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: CI - Python

on: [pull_request, push]

permissions: {}

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: ${{ github.head_ref != '' }}

jobs:
ci:
name: Check
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup python (auxiliary scripts)
uses: actions/setup-python@v5
with:
python-version: '3' # use default version

- name: Install tools (auxiliary scripts)
run: pip install bandit pycodestyle pyflakes

- name: Gather files (auxiliary scripts)
run: |
export "PY_FILES=$(find . -type f -name '*.py' ! -path '*searchengine*' -printf '%p ')"
echo $PY_FILES
echo "PY_FILES=$PY_FILES" >> "$GITHUB_ENV"

- name: Lint code (auxiliary scripts)
run: |
pyflakes $PY_FILES
bandit --skip B314,B405 $PY_FILES

- name: Format code (auxiliary scripts)
run: |
pycodestyle \
--max-line-length=1000 \
--statistics \
$PY_FILES

- name: Build code (auxiliary scripts)
run: |
python -m compileall $PY_FILES

- name: Setup python (search engine)
uses: actions/setup-python@v5
with:
python-version: '3.7'

- name: Install tools (search engine)
run: pip install bandit pycodestyle pyflakes

- name: Gather files (search engine)
run: |
export "PY_FILES=$(find . -type f -name '*.py' -path '*searchengine*' ! -name 'socks.py' -printf '%p ')"
echo $PY_FILES
echo "PY_FILES=$PY_FILES" >> "$GITHUB_ENV"

- name: Lint code (search engine)
run: |
pyflakes $PY_FILES
bandit --skip B110,B310,B314,B405 $PY_FILES

- name: Format code (search engine)
run: |
pycodestyle \
--ignore=E265,E402 \
--max-line-length=1000 \
--statistics \
$PY_FILES

- name: Build code (search engine)
run: |
python -m compileall $PY_FILES
2 changes: 1 addition & 1 deletion .github/workflows/ci_webui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
config-file: ./.github/workflows/helper/codeql/js.yaml
config-file: .github/workflows/helper/codeql/js.yaml
languages: javascript

- name: Run CodeQL analysis
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/helper/pre-commit/check_translation_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import argparse
import re


def main(argv: Optional[Sequence[str]] = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*', help='Filenames to check')
Expand All @@ -47,12 +48,12 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
for line in file:
if (match := regex.match(line)) is not None:
error_buffer += str(f"Defect file: \"{filename}\"\n"
f"Line: {line_counter}\n"
f"Column span: {match.span()}\n"
f"Part: \"{match.group()}\"\n\n")
f"Line: {line_counter}\n"
f"Column span: {match.span()}\n"
f"Part: \"{match.group()}\"\n\n")
line_counter += 1

except UnicodeDecodeError as error:
except UnicodeDecodeError:
# not a text file, skip
continue

Expand All @@ -64,5 +65,6 @@ def main(argv: Optional[Sequence[str]] = None) -> int:

return 0


if __name__ == '__main__':
exit(main())
3 changes: 3 additions & 0 deletions dist/windows/gather_qt_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import sys
from typing import List


def isNotStub(path: str) -> bool:
return (os.path.getsize(path) >= (10 * 1024))


def main() -> int:
parser = argparse.ArgumentParser(description='Gather valid Qt translations for NSIS packaging.')
parser.add_argument("qt_translations_folder", help="Qt's translations folder")
Expand All @@ -27,5 +29,6 @@ def main() -> int:

return 0


if __name__ == '__main__':
sys.exit(main())
6 changes: 3 additions & 3 deletions src/searchengine/nova3/novaprinter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#VERSION: 1.46
#VERSION: 1.47

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -45,13 +45,13 @@ def anySizeToBytes(size_string):
# separate integer from unit
try:
size, unit = size_string.split()
except:
except Exception:
try:
size = size_string.strip()
unit = ''.join([c for c in size if c.isalpha()])
if len(unit) > 0:
size = size[:-len(unit)]
except:
except Exception:
return -1
if len(size) == 0:
return -1
Expand Down
90 changes: 0 additions & 90 deletions src/update_qrc_files.py

This file was deleted.

5 changes: 5 additions & 0 deletions src/webui/www/split_merge_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pathlib import PurePath
import sys


def updateJson(json_file: str, source: dict[str, str]) -> None:
trimmed_path: str = json_file
path_parts = PurePath(json_file).parts
Expand All @@ -42,6 +43,7 @@ def updateJson(json_file: str, source: dict[str, str]) -> None:
file.write("\n")
file.truncate()


def splitJson(transifex_dir: str, json_public_dir: str, json_private_dir: str) -> None:
locales: list[str] = glob.glob("*.json", root_dir=transifex_dir)
locales = [x for x in locales if x != "en.json"]
Expand All @@ -65,6 +67,7 @@ def splitJson(transifex_dir: str, json_public_dir: str, json_private_dir: str) -
updateJson(public_file, transifex_json)
updateJson(private_file, transifex_json)


def mergeJson(transifex_dir: str, json_public_dir: str, json_private_dir: str) -> None:
transifex_en_file: str = f"{transifex_dir}/en.json"
public_en_file: str = f"{json_public_dir}/en.json"
Expand Down Expand Up @@ -92,6 +95,7 @@ def mergeJson(transifex_dir: str, json_public_dir: str, json_private_dir: str) -
json.dump(transifex_en_json, file, ensure_ascii=False, indent=2, sort_keys=True)
file.write("\n")


def main() -> int:
script_path: str = os.path.dirname(os.path.realpath(__file__))
transifex_dir: str = f"{script_path}/transifex"
Expand Down Expand Up @@ -124,5 +128,6 @@ def main() -> int:

return 0


if __name__ == '__main__':
sys.exit(main())
4 changes: 4 additions & 0 deletions src/webui/www/translations_qt2i18next.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import sys
import xml.etree.ElementTree as ET


def getTsStrings(ts_file: str, key: str) -> list[str]:
tr_strings: list[str] = []
tree = ET.parse(ts_file)
Expand All @@ -33,6 +34,7 @@ def getTsStrings(ts_file: str, key: str) -> list[str]:

return tr_strings


def migrate2Json(ts_dir: str, json_dir: str, locale: str) -> None:
ts_file: str = f"{ts_dir}/webui_{locale}.ts"
js_file: str = f"{json_dir}/{locale}.json"
Expand Down Expand Up @@ -71,6 +73,7 @@ def migrate2Json(ts_dir: str, json_dir: str, locale: str) -> None:

print("\tFinished.")


def main() -> int:
script_path: str = os.path.dirname(os.path.realpath(__file__))
ts_dir: str = f"{script_path}/translations"
Expand All @@ -97,5 +100,6 @@ def main() -> int:

return 0


if __name__ == '__main__':
sys.exit(main())
Loading