mirror of
https://github.com/ARUP-CAS/aiscr-qgis-amcr-viewer.git
synced 2026-10-08 20:07:36 +02:00
* chore: odstranit resources.py a konfiguraci flake8 z balíčku Scanner na plugins.qgis.org označil plugin jako „Validated (configured)“ kvůli amcr_viewer/.flake8. Ten potlačoval jen stylové nálezy (E302, E305, E501) ve vygenerovaném resources.py, který se nikde neimportuje – ikony se načítají přímo z PNG. resources.py repozitář pluginů nevyžaduje (validator.py v QGIS-Django, PyQGIS cookbook: „optional“). - Smazán amcr_viewer/resources.py a amcr_viewer/.flake8. - CI: flake8 běží s --isolated (výchozí pravidla jako scanner); kontrola ZIPu místo .flake8 hlídá povinný LICENSE. - check_sources.py: žádné skryté soubory v balíčku, ani config soubory scanneru. - pyproject.toml, README.md, AGENTS.md: odstraněny odkazy na oba soubory, popsán postup bez konfigurace. Ověřeno: check_sources, flake8 7.3.0, ruff 0.16.5, bandit 1.9.4, detect-secrets bez nálezů; pyqgis4-checker čistý; smoke test v QGIS 3.44.15 (Qt 5) i 4.2.3 (Qt 6); ZIP bez skrytých souborů. Připraveno s pomocí AI (Claude). * Verze 2.1.4 Povýšena verze v metadata.txt (+ changelog) a CITATION.cff po odstranění resources.py a konfigurace flake8. Připraveno s pomocí AI (Claude).
84 lines
2.6 KiB
Python
84 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
Repository hygiene rules that need no QGIS and therefore run first.
|
||
|
||
Each rule guards a mistake that has already happened here at least once,
|
||
or one the plugins.qgis.org file analysis reports:
|
||
|
||
* a UTF-8 BOM makes the official pyqgis4-checker skip the file entirely,
|
||
so a broken file looks clean – it is silent, which is what makes it bad
|
||
* a direct PyQt5/PyQt6 import breaks the other Qt version
|
||
* an executable or hidden file in the package is reported on upload
|
||
|
||
Run it from the repository root:
|
||
|
||
python3 tests/check_sources.py
|
||
"""
|
||
|
||
import os
|
||
import re
|
||
import stat
|
||
import sys
|
||
|
||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||
BALICEK = os.path.join(ROOT, "amcr_viewer")
|
||
|
||
# Extensions that have no business inside a plugin package
|
||
PODEZRELE = {".exe", ".dll", ".so", ".dylib", ".sh", ".bat", ".cmd",
|
||
".pyc", ".pyd", ".jar", ".bin"}
|
||
|
||
PRIMY_IMPORT = re.compile(r"^\s*(?:from|import)\s+PyQt[56]\b", re.MULTILINE)
|
||
|
||
nalezy = []
|
||
|
||
|
||
def zdrojaky():
|
||
for adresar, _, soubory in os.walk(BALICEK):
|
||
for soubor in sorted(soubory):
|
||
if soubor.endswith(".py"):
|
||
yield os.path.join(adresar, soubor)
|
||
|
||
|
||
def vsechny_soubory():
|
||
for adresar, _, soubory in os.walk(BALICEK):
|
||
for soubor in sorted(soubory):
|
||
yield os.path.join(adresar, soubor)
|
||
|
||
|
||
def zkratka(cesta):
|
||
return os.path.relpath(cesta, ROOT)
|
||
|
||
|
||
for cesta in zdrojaky():
|
||
with open(cesta, "rb") as f:
|
||
zacatek = f.read(3)
|
||
if zacatek == b"\xef\xbb\xbf":
|
||
nalezy.append(f"{zkratka(cesta)}: UTF-8 BOM na začátku souboru")
|
||
|
||
with open(cesta, encoding="utf-8-sig") as f:
|
||
text = f.read()
|
||
for shoda in PRIMY_IMPORT.finditer(text):
|
||
radek = text[:shoda.start()].count("\n") + 1
|
||
nalezy.append(f"{zkratka(cesta)}:{radek}: přímý import z PyQt5/PyQt6, "
|
||
f"použij shim qgis.PyQt")
|
||
|
||
for cesta in vsechny_soubory():
|
||
jmeno = os.path.basename(cesta)
|
||
rezim = os.stat(cesta).st_mode
|
||
if rezim & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH):
|
||
nalezy.append(f"{zkratka(cesta)}: spustitelná práva "
|
||
f"({stat.filemode(rezim)})")
|
||
# No exceptions: scanner config files (.flake8, .bandit,
|
||
# .secrets.baseline) would mark the upload "Validated (configured)"
|
||
if jmeno.startswith("."):
|
||
nalezy.append(f"{zkratka(cesta)}: skrytý soubor v balíčku pluginu")
|
||
if os.path.splitext(jmeno)[1].lower() in PODEZRELE:
|
||
nalezy.append(f"{zkratka(cesta)}: podezřelý typ souboru")
|
||
|
||
if nalezy:
|
||
print("Nálezy:")
|
||
for nalez in nalezy:
|
||
print(f" {nalez}")
|
||
sys.exit(1)
|
||
print("Kontrola zdrojáků: bez nálezů")
|