Skip to content

Commit 152801d

Browse files
Merge pull request #2175 from camptocamp/ghci/audit/renovate/prod-2-10
Audit Update Renovate configuration
2 parents c931c6c + d3744e0 commit 152801d

8 files changed

Lines changed: 141 additions & 46 deletions

File tree

CONST_create_template/build

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ from typing import TYPE_CHECKING, Any, List, Optional
1515

1616
import yaml
1717

18-
CompletedProcess = subprocess.CompletedProcess[str] if TYPE_CHECKING else subprocess.CompletedProcess
18+
CompletedProcess = (
19+
subprocess.CompletedProcess[str] if TYPE_CHECKING else subprocess.CompletedProcess
20+
)
1921

2022

2123
def run(
22-
args: argparse.Namespace, command: List[str], exit_on_error: bool = True, **kwargs: Any
24+
args: argparse.Namespace,
25+
command: List[str],
26+
exit_on_error: bool = True,
27+
**kwargs: Any,
2328
) -> Optional[CompletedProcess]:
2429
if args.verbose or args.dry_run:
2530
print(shlex.join(command))
@@ -36,15 +41,25 @@ def run(
3641

3742
def main() -> None:
3843
parser = argparse.ArgumentParser(description="Build the project")
39-
parser.add_argument("--verbose", action="store_true", help="Display the Docker build commands")
40-
parser.add_argument("--no-cache", action="store_true", help="Disable docker cache on build")
4144
parser.add_argument(
42-
"--dry-run", action="store_true", help="Display the docker build commands without executing them"
45+
"--verbose", action="store_true", help="Display the Docker build commands"
46+
)
47+
parser.add_argument(
48+
"--no-cache", action="store_true", help="Disable docker cache on build"
49+
)
50+
parser.add_argument(
51+
"--dry-run",
52+
action="store_true",
53+
help="Display the docker build commands without executing them",
4354
)
4455
parser.add_argument("--service", help="Build only the specified service")
4556
parser.add_argument("--env", action="store_true", help="Build only the .env file")
46-
parser.add_argument("--simple", action="store_true", help="Force simple application mode")
47-
parser.add_argument("--not-simple", action="store_true", help="Force not simple application mode")
57+
parser.add_argument(
58+
"--simple", action="store_true", help="Force simple application mode"
59+
)
60+
parser.add_argument(
61+
"--not-simple", action="store_true", help="Force not simple application mode"
62+
)
4863
parser.add_argument("--upgrade", help="Start upgrading the project to version")
4964
parser.add_argument(
5065
"--reload",
@@ -60,9 +75,12 @@ def main() -> None:
6075
help="Do not pull external or base images for faster rebuild during development.",
6176
)
6277
parser.add_argument(
63-
"--debug", help="Path to c2cgeoportal source folder to be able to debug the upgrade procedure"
78+
"--debug",
79+
help="Path to c2cgeoportal source folder to be able to debug the upgrade procedure",
80+
)
81+
parser.add_argument(
82+
"--stack-trace", action="store_true", help="Display the stack trace on error"
6483
)
65-
parser.add_argument("--stack-trace", action="store_true", help="Display the stack trace on error")
6684
parser.add_argument("env_files", nargs="*", help="The environment config")
6785
args = parser.parse_args()
6886

@@ -124,7 +142,11 @@ def main() -> None:
124142
if args.not_simple:
125143
simple = False
126144

127-
git_hash = run(args, ["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE).stdout.decode().strip()
145+
git_hash = (
146+
run(args, ["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE)
147+
.stdout.decode()
148+
.strip()
149+
)
128150

129151
dest.write(f"SIMPLE={str(simple).upper()}\n")
130152
dest.write(f"GIT_HASH={git_hash}\n")
@@ -143,7 +165,9 @@ def main() -> None:
143165
if not args.no_pull:
144166
# Pull all the images
145167
if not args.service:
146-
run(args, [*docker_compose_command, "pull", "--ignore-buildable"]) # nosec
168+
run(
169+
args, [*docker_compose_command, "pull", "--ignore-buildable"]
170+
) # nosec
147171
docker_compose_build_cmd.append("--pull")
148172

149173
if args.service:
@@ -181,7 +205,16 @@ def main() -> None:
181205
if args.reload is not None:
182206
run(args, [*docker_compose_command, "rm", "--force", "-v", "config"])
183207
for service in services:
184-
run(args, [*docker_compose_command, "up", "--detach", "--force-recreate", service])
208+
run(
209+
args,
210+
[
211+
*docker_compose_command,
212+
"up",
213+
"--detach",
214+
"--force-recreate",
215+
service,
216+
],
217+
)
185218

186219

187220
if __name__ == "__main__":

CONST_create_template/ci/docker-compose-check

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ def _main() -> None:
1111

1212
services = [
1313
s.strip()
14-
for s in subprocess.run(["docker", "compose", "ps"], check=True, stdout=subprocess.PIPE)
14+
for s in subprocess.run(
15+
["docker", "compose", "ps"], check=True, stdout=subprocess.PIPE
16+
)
1517
.stdout.decode("utf-8")
1618
.splitlines()
1719
]
18-
errors_statuses = [s for s in services if " Exit " in s and not s.endswith(" Exit 0")]
20+
errors_statuses = [
21+
s for s in services if " Exit " in s and not s.endswith(" Exit 0")
22+
]
1923
if errors_statuses:
2024
print("\n".join(errors_statuses))
2125
sys.exit(1)

CONST_create_template/scripts/db-backup

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,13 @@ import sys
3737
def main() -> None:
3838
"""Backup the database."""
3939
parser = argparse.ArgumentParser(description="Backup the database.")
40-
parser.add_argument("--verbose", action="store_true", help="Print the command that is executed.")
4140
parser.add_argument(
42-
"--dry-run", action="store_true", help="Only print the command that would be executed."
41+
"--verbose", action="store_true", help="Print the command that is executed."
42+
)
43+
parser.add_argument(
44+
"--dry-run",
45+
action="store_true",
46+
help="Only print the command that would be executed.",
4347
)
4448
parser.add_argument(
4549
"--env",
@@ -79,8 +83,16 @@ def main() -> None:
7983
command2 = ["--env=PGPASSWORD={}".format(env["PGPASSWORD"])]
8084
command2_annon = ["--env=PGPASSWORD=***"]
8185
command3 = [
82-
*(["--env=PGSSLMODE={}".format(env["PGSSLMODE"])] if "PGSSLMODE" in env else []),
83-
*(["--env=PGOPTIONS={}".format(env["PGOPTIONS"])] if "PGOPTIONS" in env else []),
86+
*(
87+
["--env=PGSSLMODE={}".format(env["PGSSLMODE"])]
88+
if "PGSSLMODE" in env
89+
else []
90+
),
91+
*(
92+
["--env=PGOPTIONS={}".format(env["PGOPTIONS"])]
93+
if "PGOPTIONS" in env
94+
else []
95+
),
8496
"camptocamp/postgres:{}".format(env["POSTGRES_TAG"]),
8597
"pg_dump",
8698
"--format=c",
@@ -101,7 +113,11 @@ def main() -> None:
101113
print(shlex.join([*command1, *command2_annon, *command3]))
102114
if args.dry_run:
103115
sys.exit(0)
104-
sys.exit(subprocess.run([*command1, *command2, *command3], stdout=file_out).returncode)
116+
sys.exit(
117+
subprocess.run(
118+
[*command1, *command2, *command3], stdout=file_out
119+
).returncode
120+
)
105121
else:
106122
command = [
107123
"docker",
@@ -115,7 +131,9 @@ def main() -> None:
115131
*args.arg,
116132
]
117133
if args.dry_run or args.verbose:
118-
subprocess.run(["docker", "compose", "exec", "tools", "pg_dump", "--version"])
134+
subprocess.run(
135+
["docker", "compose", "exec", "tools", "pg_dump", "--version"]
136+
)
119137
print(shlex.join(command))
120138
if args.dry_run:
121139
sys.exit(0)

CONST_create_template/scripts/db-restore

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ import sys
3636
def main() -> None:
3737
"""Restore the database backup."""
3838
parser = argparse.ArgumentParser(description="Restore the database backup.")
39-
parser.add_argument("--verbose", action="store_true", help="Print the command that is executed.")
4039
parser.add_argument(
41-
"--dry-run", action="store_true", help="Only print the command that would be executed."
40+
"--verbose", action="store_true", help="Print the command that is executed."
41+
)
42+
parser.add_argument(
43+
"--dry-run",
44+
action="store_true",
45+
help="Only print the command that would be executed.",
4246
)
4347
parser.add_argument(
4448
"--env",
@@ -86,8 +90,16 @@ def main() -> None:
8690
]
8791
command2_annon = ["--env=PGPASSWORD=***"]
8892
command3 = [
89-
*(["--env=PGSSLMODE={}".format(env["PGSSLMODE"])] if "PGSSLMODE" in env else []),
90-
*(["--env=PGOPTIONS={}".format(env["PGOPTIONS"])] if "PGOPTIONS" in env else []),
93+
*(
94+
["--env=PGSSLMODE={}".format(env["PGSSLMODE"])]
95+
if "PGSSLMODE" in env
96+
else []
97+
),
98+
*(
99+
["--env=PGOPTIONS={}".format(env["PGOPTIONS"])]
100+
if "PGOPTIONS" in env
101+
else []
102+
),
91103
"camptocamp/postgres:{}".format(env["POSTGRES_TAG"]),
92104
"pg_restore",
93105
"--dbname={}".format(env["PGDATABASE"]),
@@ -107,7 +119,11 @@ def main() -> None:
107119
print(shlex.join([*command1, *command2_annon, *command3]))
108120
if args.dry_run:
109121
sys.exit(0)
110-
sys.exit(subprocess.run([*command1, *command2, *command3], stdin=file_in).returncode)
122+
sys.exit(
123+
subprocess.run(
124+
[*command1, *command2, *command3], stdin=file_in
125+
).returncode
126+
)
111127
else:
112128
command = [
113129
"docker",
@@ -121,7 +137,9 @@ def main() -> None:
121137
'pg_restore --dbname="$PGDATABASE" ' + " ".join(args.arg),
122138
]
123139
if args.verbose or args.dry_run:
124-
subprocess.run(["docker", "compose", "exec", "tools", "pg_restore", "--version"])
140+
subprocess.run(
141+
["docker", "compose", "exec", "tools", "pg_restore", "--version"]
142+
)
125143
print(shlex.join(command))
126144
if args.dry_run:
127145
sys.exit(0)

CONST_create_template/scripts/qgis-project-download

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,22 @@ Example usage:
2424
formatter_class=argparse.RawTextHelpFormatter,
2525
)
2626
parser.add_argument("schema", default="qgis", help="Source PostgreSQL schema name")
27-
parser.add_argument("project", default="project.qgz", help="Source QGIS project name")
28-
parser.add_argument("filename", default="qgisserver/project.qgz", help="Destination file name")
27+
parser.add_argument(
28+
"project", default="project.qgz", help="Source QGIS project name"
29+
)
30+
parser.add_argument(
31+
"filename", default="qgisserver/project.qgz", help="Destination file name"
32+
)
2933
args = parser.parse_args()
3034

3135
# Connect to a DB, e.g., the test DB on your localhost, and get a cursor
3236
with psycopg2.connect(f"dbname={os.environ['PGDATABASE']}") as connection:
3337
with connection.cursor() as cursor:
34-
query = sql.SQL(
35-
"""
38+
query = sql.SQL("""
3639
SELECT content
3740
FROM {}.qgis_projects
3841
WHERE name = %(name)s;
39-
"""
40-
).format(sql.Identifier(args.schema))
42+
""").format(sql.Identifier(args.schema))
4143

4244
cursor.execute(query, {"name": args.project})
4345
rows = cursor.fetchall()
@@ -47,7 +49,9 @@ Example usage:
4749
with path.open("wb") as f:
4850
f.write(data)
4951

50-
print(f"Project {args.project} from schema {args.schema} downloaded as {args.filename}")
52+
print(
53+
f"Project {args.project} from schema {args.schema} downloaded as {args.filename}"
54+
)
5155

5256

5357
if __name__ == "__main__":

CONST_create_template/scripts/qgis-project-upload

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@ Example usage:
2323
""",
2424
formatter_class=argparse.RawTextHelpFormatter,
2525
)
26-
parser.add_argument("filename", default="qgisserver/project.qgz", help="Source file name")
27-
parser.add_argument("schema", default="qgis", help="Destination PostgreSQL schema name")
28-
parser.add_argument("project", default="project.qgz", help="Destination QGIS project name")
26+
parser.add_argument(
27+
"filename", default="qgisserver/project.qgz", help="Source file name"
28+
)
29+
parser.add_argument(
30+
"schema", default="qgis", help="Destination PostgreSQL schema name"
31+
)
32+
parser.add_argument(
33+
"project", default="project.qgz", help="Destination QGIS project name"
34+
)
2935
args = parser.parse_args()
3036

3137
# Connect to a DB, e.g., the test DB on your localhost, and get a cursor
@@ -35,13 +41,11 @@ Example usage:
3541
with path.open("rb") as f:
3642
data = f.read()
3743

38-
query = sql.SQL(
39-
"""
44+
query = sql.SQL("""
4045
UPDATE {}.qgis_projects
4146
SET content = %(content)s
4247
WHERE name = %(name)s;
43-
"""
44-
).format(sql.Identifier(args.schema))
48+
""").format(sql.Identifier(args.schema))
4549

4650
cursor.execute(
4751
query,
@@ -51,7 +55,9 @@ Example usage:
5155
},
5256
)
5357

54-
print(f"Project {args.filename} uploaded in schema {args.schema} with name {args.project}")
58+
print(
59+
f"Project {args.filename} uploaded in schema {args.schema} with name {args.project}"
60+
)
5561

5662

5763
if __name__ == "__main__":

CONST_create_template/tests/test_app.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
("https://front/themes", {}, 120),
1212
("https://front/static-geomapfish/0/locales/fr.json", {}, 2),
1313
("https://front/dynamic.json", {"interface": "desktop"}, 10),
14-
("https://front/dynamic.json", {"interface": "desktop", "query": "", "path": "/"}, 10),
14+
(
15+
"https://front/dynamic.json",
16+
{"interface": "desktop", "query": "", "path": "/"},
17+
10,
18+
),
1519
("https://front/c2c/health_check", {}, 2),
1620
("https://front/c2c/health_check", {"max_level": "1"}, 2),
1721
("https://front/c2c/health_check", {"checker": "check_collector"}, 2),
@@ -63,7 +67,9 @@
6367
def test_url(url: str, params: dict[str, str], timeout: int) -> None:
6468
"""Tests that some URL didn't return an error."""
6569
for _ in range(6):
66-
response = requests.get(url, params=params, verify=False, timeout=timeout) # nosec
70+
response = requests.get(
71+
url, params=params, verify=False, timeout=timeout
72+
) # nosec
6773
if response.status_code == 503:
6874
time.sleep(1)
6975
continue

CONST_create_template/tests/test_testapp.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ def test_po(test_number: int) -> None:
1212
"""Tests that the generated pot files are identical between the command line and the view."""
1313
del test_number
1414

15-
response = requests.get("https://front/locale.pot", verify=False, timeout=30) # nosec
15+
response = requests.get(
16+
"https://front/locale.pot", verify=False, timeout=30
17+
) # nosec
1618
assert response.status_code == 200, response.text
1719
response_keys = {e.msgid for e in polib.pofile(response.text)}
1820

@@ -42,7 +44,11 @@ def test_desktop_alt(url: str) -> None:
4244

4345
def test_enum() -> None:
4446
"""Test the enumerations view."""
45-
response = requests.get("https://front/layers/test/values/type", verify=False, timeout=30) # nosec
47+
response = requests.get(
48+
"https://front/layers/test/values/type", verify=False, timeout=30
49+
) # nosec
4650
assert response.status_code == 200, response.text
4751

48-
assert response.json() == {"items": [{"value": "car"}, {"value": "train"}]}, response.text
52+
assert response.json() == {
53+
"items": [{"value": "car"}, {"value": "train"}]
54+
}, response.text

0 commit comments

Comments
 (0)