Skip to content

Commit 8202da7

Browse files
authored
Merge pull request #172 from YunoHost/actions/black
2 parents 26c67a8 + cbe51ee commit 8202da7

File tree

5 files changed

+104
-40
lines changed

5 files changed

+104
-40
lines changed

tests/test_app.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@
99
import tomllib
1010
from typing import Generator
1111

12-
from lib.lib_package_linter import (Error, Info, Success, TestResult,
13-
TestSuite, Warning, config_panel_v1_schema,
14-
not_empty, test, tests_reports,
15-
validate_schema)
12+
from lib.lib_package_linter import (
13+
Error,
14+
Info,
15+
Success,
16+
TestResult,
17+
TestSuite,
18+
Warning,
19+
config_panel_v1_schema,
20+
not_empty,
21+
test,
22+
tests_reports,
23+
validate_schema,
24+
)
1625
from lib.print import _print, is_json_output
1726
from tests.test_catalog import AppCatalog
1827
from tests.test_configurations import Configurations
@@ -412,7 +421,9 @@ def doc_dir(app) -> TestResult:
412421
@test()
413422
def doc_dir_v2(app) -> TestResult:
414423

415-
if (app.path / "doc").exists() and not (app.path / "doc" / "DESCRIPTION.md").exists():
424+
if (app.path / "doc").exists() and not (
425+
app.path / "doc" / "DESCRIPTION.md"
426+
).exists():
416427
yield Error(
417428
"A DESCRIPTION.md is now mandatory in packaging v2 and is meant to contains an extensive description of what the app is and does. Consider also adding a '/doc/screenshots/' folder with a few screenshots of what the app looks like."
418429
)
@@ -523,28 +534,25 @@ def config_panel(app) -> TestResult:
523534
"Please do not commit config_panel.toml.example ... This is just a 'documentation' for the config panel syntax meant to be kept in example_ynh"
524535
)
525536

526-
if not not_empty(app.path / "config_panel.toml") and not_empty(app.path / "scripts" / "config"):
537+
if not not_empty(app.path / "config_panel.toml") and not_empty(
538+
app.path / "scripts" / "config"
539+
):
527540
yield Warning(
528541
"The script 'config' exists but there is no config_panel.toml ... Please remove the 'config' script if this is just the example from example_ynh, or add a proper config_panel.toml if the point is really to have a config panel"
529542
)
530543

531544
if not_empty(app.path / "config_panel.toml"):
532545
check_old_panel = os.system(
533-
"grep -q 'version = \"0.1\"' '%s'"
534-
% (app.path / "config_panel.toml")
546+
"grep -q 'version = \"0.1\"' '%s'" % (app.path / "config_panel.toml")
535547
)
536548
if check_old_panel == 0:
537549
yield Error(
538550
"Config panels version 0.1 are not supported anymore, should be adapted for version 1.0"
539551
)
540-
elif (
541-
(app.path / "scripts" / "config").exists()
542-
and os.system(
543-
"grep -q 'YNH_CONFIG_\\|yunohost app action' '%s'"
544-
% (app.path / "scripts" / "config")
545-
)
546-
== 0
547-
):
552+
elif (app.path / "scripts" / "config").exists() and os.system(
553+
"grep -q 'YNH_CONFIG_\\|yunohost app action' '%s'"
554+
% (app.path / "scripts" / "config")
555+
) == 0:
548556
yield Error(
549557
"The config panel is set to version 1.x, but the config script is apparently still using some old code from 0.1 such as '$YNH_CONFIG_STUFF' or 'yunohost app action'"
550558
)

tests/test_catalog.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@
1111
from types import ModuleType
1212
from typing import Any, Generator
1313

14-
from lib.lib_package_linter import (Critical, Error, Info, Success, TestResult,
15-
TestSuite, Warning, test, urlopen)
14+
from lib.lib_package_linter import (
15+
Critical,
16+
Error,
17+
Info,
18+
Success,
19+
TestResult,
20+
TestSuite,
21+
Warning,
22+
test,
23+
urlopen,
24+
)
1625
from lib.print import _print
1726

1827
PACKAGE_LINTER_DIR = Path(__file__).resolve().parent.parent
@@ -48,8 +57,11 @@ def __init__(self, app_id: str) -> None:
4857

4958
def _fetch_app_repo(self) -> None:
5059
flagfile = PACKAGE_LINTER_DIR / ".apps_git_clone_cache"
51-
if APPS_CACHE.exists() and flagfile.exists() \
52-
and time.time() - flagfile.stat().st_mtime < 3600:
60+
if (
61+
APPS_CACHE.exists()
62+
and flagfile.exists()
63+
and time.time() - flagfile.stat().st_mtime < 3600
64+
):
5365
return
5466

5567
if not APPS_CACHE.exists():
@@ -169,7 +181,9 @@ def _time_points_until_today() -> Generator[datetime, None, None]:
169181

170182
date = datetime(year, month, day)
171183

172-
def get_history(N: int) -> Generator[tuple[datetime, dict[str, Any]], None, None]:
184+
def get_history(
185+
N: int,
186+
) -> Generator[tuple[datetime, dict[str, Any]], None, None]:
173187

174188
for t in list(_time_points_until_today())[(-1 * N) :]:
175189
loader: ModuleType
@@ -192,7 +206,10 @@ def get_history(N: int) -> Generator[tuple[datetime, dict[str, Any]], None, None
192206
raw_catalog_at_this_date = git(["show", f"{commit}:apps.json"])
193207
loader = json
194208

195-
elif os.system(f"git -C {APPS_CACHE} cat-file -e {commit}:apps.toml") == 0:
209+
elif (
210+
os.system(f"git -C {APPS_CACHE} cat-file -e {commit}:apps.toml")
211+
== 0
212+
):
196213
raw_catalog_at_this_date = git(["show", f"{commit}:apps.toml"])
197214
loader = tomllib
198215
else:

tests/test_configurations.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,18 @@
88
import tomllib
99
from typing import Any, Generator
1010

11-
from lib.lib_package_linter import (Error, Info, TestReport, TestResult,
12-
TestSuite, Warning, not_empty, test,
13-
tests_v1_schema, validate_schema)
11+
from lib.lib_package_linter import (
12+
Error,
13+
Info,
14+
TestReport,
15+
TestResult,
16+
TestSuite,
17+
Warning,
18+
not_empty,
19+
test,
20+
tests_v1_schema,
21+
validate_schema,
22+
)
1423
from lib.print import _print
1524

1625

@@ -62,7 +71,10 @@ def encourage_extra_php_conf(self) -> TestResult:
6271
def misc_source_management(self) -> TestResult:
6372
source_dir = self.app.path / "sources"
6473

65-
if source_dir.exists() and len(list(elt for elt in source_dir.iterdir() if elt.is_file())) > 5:
74+
if (
75+
source_dir.exists()
76+
and len(list(elt for elt in source_dir.iterdir() if elt.is_file())) > 5
77+
):
6678
yield Error(
6779
"Upstream app sources shouldn't be stored in this 'sources' folder of this git repository as a copy/paste\n"
6880
"During installation, the package should download sources from upstream via 'ynh_setup_source'.\n"
@@ -300,7 +312,9 @@ def misc_nginx_path_traversal(self) -> TestResult:
300312
#
301313
# Path traversal issues
302314
#
303-
def find_location_with_alias(locationblock: Any) -> Generator[tuple[str, str], None, None]:
315+
def find_location_with_alias(
316+
locationblock: Any,
317+
) -> Generator[tuple[str, str], None, None]:
304318

305319
if locationblock[0][0] != "location":
306320
return
@@ -319,7 +333,9 @@ def find_location_with_alias(locationblock: Any) -> Generator[tuple[str, str], N
319333
else:
320334
continue
321335

322-
def find_path_traversal_issue(nginxconf: list[Any]) -> Generator[str, None, None]:
336+
def find_path_traversal_issue(
337+
nginxconf: list[Any],
338+
) -> Generator[str, None, None]:
323339

324340
for block in nginxconf:
325341
for location, alias in find_location_with_alias(block):
@@ -414,9 +430,9 @@ def bind_public_ip(self) -> TestResult:
414430

415431
for number, line in enumerate(content.split("\n"), 1):
416432
comment = ("#", "//", ";", "/*", "*")
417-
if (
418-
"0.0.0.0" in line or "::" in line
419-
) and not line.strip().startswith(comment):
433+
if ("0.0.0.0" in line or "::" in line) and not line.strip().startswith(
434+
comment
435+
):
420436
for ip in re.split(r"[ \t,='\"(){}\[\]]", line):
421437
if ip == "::" or ip.startswith("0.0.0.0"):
422438
yield Info(

tests/test_manifest.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@
88
import tomllib
99
from typing import Any, Callable
1010

11-
from lib.lib_package_linter import (Critical, Error, Info, TestResult,
12-
TestSuite, Warning, c, manifest_v2_schema,
13-
spdx_licenses, test, validate_schema)
11+
from lib.lib_package_linter import (
12+
Critical,
13+
Error,
14+
Info,
15+
TestResult,
16+
TestSuite,
17+
Warning,
18+
c,
19+
manifest_v2_schema,
20+
spdx_licenses,
21+
test,
22+
validate_schema,
23+
)
1424

1525
# Only packaging v2 is supported on the linter now ... But someday™ according The Prophecy™, packaging v3 will be a thing
1626
app_packaging_format = 2
@@ -70,7 +80,9 @@ def __init__(self, path: Path) -> None:
7080
manifest_path = path / "manifest.toml"
7181

7282
# Taken from https://stackoverflow.com/a/49518779
73-
def check_for_duplicate_keys(ordered_pairs: list[tuple[str, Any]]) -> dict[str, Any]:
83+
def check_for_duplicate_keys(
84+
ordered_pairs: list[tuple[str, Any]]
85+
) -> dict[str, Any]:
7486
dict_out = {}
7587
for key, val in ordered_pairs:
7688
if key in dict_out:
@@ -83,7 +95,9 @@ def check_for_duplicate_keys(ordered_pairs: list[tuple[str, Any]]) -> dict[str,
8395
try:
8496
self.manifest = tomllib.loads(self.raw_manifest)
8597
except Exception as e:
86-
print(f"{c.FAIL}✘ Looks like there's a syntax issue in your manifest?\n ---> {e}")
98+
print(
99+
f"{c.FAIL}✘ Looks like there's a syntax issue in your manifest?\n ---> {e}"
100+
)
87101
sys.exit(1)
88102

89103
@test()

tests/test_scripts.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,17 @@
88
import subprocess
99
from typing import Generator
1010

11-
from lib.lib_package_linter import (Critical, Error, Info, TestResult,
12-
TestSuite, Warning, not_empty,
13-
report_warning_not_reliable, test)
11+
from lib.lib_package_linter import (
12+
Critical,
13+
Error,
14+
Info,
15+
TestResult,
16+
TestSuite,
17+
Warning,
18+
not_empty,
19+
report_warning_not_reliable,
20+
test,
21+
)
1422
from lib.print import _print
1523

1624

@@ -371,7 +379,8 @@ def argument_fetching(self) -> TestResult:
371379
def sources_list_tweaking(self) -> TestResult:
372380
common_sh = self.app / "scripts" / "_common.sh"
373381
if self.contains("/etc/apt/sources.list") or (
374-
common_sh.exists() and "/etc/apt/sources.list" in common_sh.read_text()
382+
common_sh.exists()
383+
and "/etc/apt/sources.list" in common_sh.read_text()
375384
and "ynh_add_repo" not in common_sh.read_text()
376385
):
377386
yield Error(

0 commit comments

Comments
 (0)