Skip to content

Commit 4b95272

Browse files
Update from base branch
From the artifact of the previous workflow run
1 parent 4c3c425 commit 4b95272

9 files changed

Lines changed: 53 additions & 156 deletions

File tree

build

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

1616
import yaml
1717

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

2220

2321
def run(
24-
args: argparse.Namespace,
25-
command: List[str],
26-
exit_on_error: bool = True,
27-
**kwargs: Any,
22+
args: argparse.Namespace, command: List[str], exit_on_error: bool = True, **kwargs: Any
2823
) -> Optional[CompletedProcess]:
2924
if args.verbose or args.dry_run:
3025
print(shlex.join(command))
@@ -41,22 +36,14 @@ def run(
4136

4237
def main() -> None:
4338
parser = argparse.ArgumentParser(description="Build the project")
39+
parser.add_argument("--verbose", action="store_true", help="Display the Docker build commands")
4440
parser.add_argument(
45-
"--verbose", action="store_true", help="Display the Docker build commands"
46-
)
47-
parser.add_argument(
48-
"--dry-run",
49-
action="store_true",
50-
help="Display the docker build commands without executing them",
41+
"--dry-run", action="store_true", help="Display the docker build commands without executing them"
5142
)
5243
parser.add_argument("--service", help="Build only the specified service")
5344
parser.add_argument("--env", action="store_true", help="Build only the .env file")
54-
parser.add_argument(
55-
"--simple", action="store_true", help="Force simple application mode"
56-
)
57-
parser.add_argument(
58-
"--not-simple", action="store_true", help="Force not simple application mode"
59-
)
45+
parser.add_argument("--simple", action="store_true", help="Force simple application mode")
46+
parser.add_argument("--not-simple", action="store_true", help="Force not simple application mode")
6047
parser.add_argument("--upgrade", help="Start upgrading the project to version")
6148
parser.add_argument(
6249
"--reload",
@@ -72,12 +59,9 @@ def main() -> None:
7259
help="Do not pull external or base images for faster rebuild during development.",
7360
)
7461
parser.add_argument(
75-
"--debug",
76-
help="Path to c2cgeoportal source folder to be able to debug the upgrade procedure",
77-
)
78-
parser.add_argument(
79-
"--stack-trace", action="store_true", help="Display the stack trace on error"
62+
"--debug", help="Path to c2cgeoportal source folder to be able to debug the upgrade procedure"
8063
)
64+
parser.add_argument("--stack-trace", action="store_true", help="Display the stack trace on error")
8165
parser.add_argument("env_files", nargs="*", help="The environment config")
8266
args = parser.parse_args()
8367

@@ -139,11 +123,7 @@ def main() -> None:
139123
if args.not_simple:
140124
simple = False
141125

142-
git_hash = (
143-
run(args, ["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE)
144-
.stdout.decode()
145-
.strip()
146-
)
126+
git_hash = run(args, ["git", "rev-parse", "HEAD"], stdout=subprocess.PIPE).stdout.decode().strip()
147127

148128
dest.write(f"SIMPLE={str(simple).upper()}\n")
149129
dest.write(f"GIT_HASH={git_hash}\n")
@@ -194,16 +174,7 @@ def main() -> None:
194174
if args.reload is not None:
195175
run(args, [*docker_compose_command, "rm", "--force", "-v", "config"])
196176
for service in services:
197-
run(
198-
args,
199-
[
200-
*docker_compose_command,
201-
"up",
202-
"--detach",
203-
"--force-recreate",
204-
service,
205-
],
206-
)
177+
run(args, [*docker_compose_command, "up", "--detach", "--force-recreate", service])
207178

208179

209180
if __name__ == "__main__":

ci/docker-compose-check

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

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

custom/custom/views/cog.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@
1414

1515
def _get_azure_container_client(container: str) -> ContainerClient:
1616
"""Get the Azure blog storage client."""
17-
if (
18-
"AZURE_STORAGE_CONNECTION_STRING" in os.environ
19-
and os.environ["AZURE_STORAGE_CONNECTION_STRING"]
20-
):
17+
if "AZURE_STORAGE_CONNECTION_STRING" in os.environ and os.environ["AZURE_STORAGE_CONNECTION_STRING"]:
2118
return BlobServiceClient.from_connection_string(
2219
os.environ["AZURE_STORAGE_CONNECTION_STRING"]
2320
).get_container_client(container=container)
2421
if "AZURE_STORAGE_BLOB_CONTAINER_URL" in os.environ:
25-
return ContainerClient.from_container_url(
26-
os.environ["AZURE_STORAGE_BLOB_CONTAINER_URL"]
27-
)
22+
return ContainerClient.from_container_url(os.environ["AZURE_STORAGE_BLOB_CONTAINER_URL"])
2823

2924
return BlobServiceClient(
3025
account_url=os.environ["AZURE_STORAGE_ACCOUNT_URL"],
@@ -59,13 +54,9 @@ def swissalti3d(request: pyramid.request.Request) -> pyramid.response.Response:
5954

6055
blob_properties = blob.get_blob_properties()
6156
_LOGGING.debug(blob_properties)
62-
request.response.headers["Content-Range"] = (
63-
f"bytes {start}-{end}/{blob_properties.size}"
64-
)
57+
request.response.headers["Content-Range"] = f"bytes {start}-{end}/{blob_properties.size}"
6558
request.response.headers["Accept-Ranges"] = "bytes"
66-
request.response.headers["Content-Type"] = (
67-
blob_properties.content_settings.content_type
68-
)
59+
request.response.headers["Content-Type"] = blob_properties.content_settings.content_type
6960

7061
blob_data = blob.download_blob(offset=start, length=end - start + 1)
7162
request.response.body = blob_data.readall()

custom/custom/views/feedback.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
description="The feedback service",
1818
path="/feedback",
1919
cors_origins=(
20-
(
21-
f"https://{os.environ['VISIBLE_WEB_HOST']}"
22-
if "VISIBLE_WEB_HOST" in os.environ
23-
else "*"
24-
),
20+
(f"https://{os.environ['VISIBLE_WEB_HOST']}" if "VISIBLE_WEB_HOST" in os.environ else "*"),
2521
*(
2622
["https://localhost:3002"]
2723
if os.environ.get("DEV", "false").lower() in ("1", "true", "yes")
@@ -66,9 +62,7 @@ def feedback_post(request: pyramid.request.Request) -> Any:
6662
request.dbsession.flush()
6763

6864
mail_list = (
69-
[request.registry.settings["admin_email"]]
70-
if "admin_email" in request.registry.settings
71-
else []
65+
[request.registry.settings["admin_email"]] if "admin_email" in request.registry.settings else []
7266
)
7367

7468
if email_optional is not None and email_optional != "":

custom/custom/views/swisscom_heatmap/entry.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
description="The swisscom-heatmap get config service",
2121
path="/swisscom-heatmap/get-config.json",
2222
cors_origins=(
23-
(
24-
f"https://{os.environ['VISIBLE_WEB_HOST']}"
25-
if "VISIBLE_WEB_HOST" in os.environ
26-
else "*"
27-
),
23+
(f"https://{os.environ['VISIBLE_WEB_HOST']}" if "VISIBLE_WEB_HOST" in os.environ else "*"),
2824
*(
2925
["https://localhost:3002"]
3026
if os.environ.get("DEV", "false").lower() in ("1", "true", "yes")
@@ -39,11 +35,7 @@
3935
description="The swisscom-heatmap dwell density service",
4036
path="/swisscom-heatmap/dwell-density.json",
4137
cors_origins=(
42-
(
43-
f"https://{os.environ['VISIBLE_WEB_HOST']}"
44-
if "VISIBLE_WEB_HOST" in os.environ
45-
else "*"
46-
),
38+
(f"https://{os.environ['VISIBLE_WEB_HOST']}" if "VISIBLE_WEB_HOST" in os.environ else "*"),
4739
*(
4840
["https://localhost:3002"]
4941
if os.environ.get("DEV", "false").lower() in ("1", "true", "yes")
@@ -58,11 +50,7 @@
5850
description="The swisscom-heatmap dwell demographics service",
5951
path="/swisscom-heatmap/dwell-demographics.json",
6052
cors_origins=(
61-
(
62-
f"https://{os.environ['VISIBLE_WEB_HOST']}"
63-
if "VISIBLE_WEB_HOST" in os.environ
64-
else "*"
65-
),
53+
(f"https://{os.environ['VISIBLE_WEB_HOST']}" if "VISIBLE_WEB_HOST" in os.environ else "*"),
6654
*(
6755
["https://localhost:3002"]
6856
if os.environ.get("DEV", "false").lower() in ("1", "true", "yes")

custom/custom/views/swisscom_heatmap/query_swisscom_heatmap_api.py

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@
1212

1313
LOG = logging.getLogger(__name__)
1414

15-
CLIENT_ID = os.getenv(
16-
"SWISSCOM_CLIENT_ID", ""
17-
) # customer key in the Swisscom digital marketplace
18-
CLIENT_SECRET = os.getenv(
19-
"SWISSCOM_CLIENT_SECRET", ""
20-
) # customer secret in the Swisscom digital marketplace
15+
CLIENT_ID = os.getenv("SWISSCOM_CLIENT_ID", "") # customer key in the Swisscom digital marketplace
16+
CLIENT_SECRET = os.getenv("SWISSCOM_CLIENT_SECRET", "") # customer secret in the Swisscom digital marketplace
2117
MIN_DATE = os.getenv("MIN_DATE", "03.10.2022")
2218
MAX_DATE = os.getenv("MAX_DATE", "16.10.2022")
2319
MAX_NB_TILES_REQUEST = int(os.getenv("MAX_NB_TILES_REQUEST", "100"))
@@ -51,24 +47,18 @@ def auth(self) -> OAuth2Session:
5147
# Fetch an access token
5248
client = BackendApplicationClient(client_id=CLIENT_ID)
5349
oauth = OAuth2Session(client=client)
54-
oauth.fetch_token(
55-
token_url=TKN_URL, client_id=CLIENT_ID, client_secret=CLIENT_SECRET
56-
)
50+
oauth.fetch_token(token_url=TKN_URL, client_id=CLIENT_ID, client_secret=CLIENT_SECRET)
5751
return oauth
5852

5953
def get_tiles_ids(self, oauth: OAuth2Session, postal_code: int) -> list[int]:
6054
# For muni/district id, see https://www.atlas.bfs.admin.ch/maps/13/fr/17804_229_228_227/27579.html
6155
# Municipalities and Districts doesn't work well probably because of the free plan
6256
# Get all the first MAX_NB_TILES_REQUEST tile ids associated with the postal code of interest
63-
muni_tiles_json = oauth.get(
64-
BASE_URL + f"/grids/postal-code-areas/{postal_code}", headers=HEADERS
65-
)
57+
muni_tiles_json = oauth.get(BASE_URL + f"/grids/postal-code-areas/{postal_code}", headers=HEADERS)
6658
self.check_api_error(muni_tiles_json)
6759
tiles = muni_tiles_json.json()["tiles"]
6860
LOG.info("Nb tiles received: %s", len(tiles))
69-
return [t["tileId"] for t in muni_tiles_json.json()["tiles"]][
70-
:MAX_NB_TILES_REQUEST
71-
]
61+
return [t["tileId"] for t in muni_tiles_json.json()["tiles"]][:MAX_NB_TILES_REQUEST]
7262

7363
def query_api_generic(
7464
self, oauth: OAuth2Session, path: str, postal_code: int, date_time: datetime
@@ -89,32 +79,24 @@ def response_to_geojson_result(self, data: dict[str, Any]) -> FeatureCollection:
8979
features.append(Feature(geometry=Point(coordinate), properties=element))
9080
return FeatureCollection(features)
9181

92-
def get_dwell_density(
93-
self, postal_code: int, date_time: datetime
94-
) -> FeatureCollection | Response:
82+
def get_dwell_density(self, postal_code: int, date_time: datetime) -> FeatureCollection | Response:
9583
self.error = None
9684
try:
9785
self.limit_query()
9886
oauth = self.auth()
99-
api_request = self.query_api_generic(
100-
oauth, "/dwell-density/hourly", postal_code, date_time
101-
)
87+
api_request = self.query_api_generic(oauth, "/dwell-density/hourly", postal_code, date_time)
10288
response = oauth.get(api_request, headers=HEADERS)
10389
self.check_api_error(response)
10490
except (ExternalAPIError, APIUsageExceededError):
10591
return self.error
10692
return self.response_to_geojson_result(response.json())
10793

108-
def get_dwell_demographics(
109-
self, postal_code: int, date_time: datetime
110-
) -> FeatureCollection | Response:
94+
def get_dwell_demographics(self, postal_code: int, date_time: datetime) -> FeatureCollection | Response:
11195
self.error = None
11296
try:
11397
self.limit_query()
11498
oauth = self.auth()
115-
api_request = self.query_api_generic(
116-
oauth, "/dwell-demographics/hourly", postal_code, date_time
117-
)
99+
api_request = self.query_api_generic(oauth, "/dwell-demographics/hourly", postal_code, date_time)
118100
response = oauth.get(api_request, headers=HEADERS)
119101
self.check_api_error(response)
120102
except (ExternalAPIError, APIUsageExceededError):

pyproject.toml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
[tool.black]
1+
2+
[project]
3+
classifiers = []
4+
dynamic = ["dependencies", "version"]
5+
6+
[tool.ruff]
7+
target-version = "py310"
28
line-length = 110
3-
target-version = ['py39']
49

5-
[tool.isort]
6-
profile = "black"
7-
line_length = 110
10+
[tool.ruff.lint.pydocstyle]
11+
convention = "numpy"

scripts/azure

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,10 @@ def main():
1414

1515
parser = argparse.ArgumentParser()
1616
parser.add_argument("--connection-string", help="Azure Storage connection string")
17-
parser.add_argument(
18-
"--list-containers", help="List the files in the container", action="store_true"
19-
)
17+
parser.add_argument("--list-containers", help="List the files in the container", action="store_true")
2018
parser.add_argument("--container", help="Container name")
21-
parser.add_argument(
22-
"--list", help="List the files in the container", action="store_true"
23-
)
24-
parser.add_argument(
25-
"--sync-upload", help="Sync the files in the container (local, azure)", nargs=2
26-
)
19+
parser.add_argument("--list", help="List the files in the container", action="store_true")
20+
parser.add_argument("--sync-upload", help="Sync the files in the container (local, azure)", nargs=2)
2721
parser.add_argument(
2822
"--sync-download",
2923
help="Sync the files in the container (local, azure)",
@@ -32,14 +26,10 @@ def main():
3226
parser.add_argument("--dry-run", action="store_true", help="Dry run")
3327
args = parser.parse_args()
3428

35-
blob_service_client = BlobServiceClient.from_connection_string(
36-
args.connection_string
37-
)
29+
blob_service_client = BlobServiceClient.from_connection_string(args.connection_string)
3830
print()
3931
print(f"Connected as {blob_service_client.account_name}, account information:")
40-
print(
41-
yaml.dump(blob_service_client.get_account_information(), Dumper=yaml.SafeDumper)
42-
)
32+
print(yaml.dump(blob_service_client.get_account_information(), Dumper=yaml.SafeDumper))
4333

4434
if args.list_containers:
4535
print()
@@ -48,9 +38,7 @@ def main():
4838
print(container["name"])
4939

5040
if args.container:
51-
container_client = blob_service_client.get_container_client(
52-
container=args.container
53-
)
41+
container_client = blob_service_client.get_container_client(container=args.container)
5442
if args.list:
5543
print()
5644
for c in container_client.list_blobs():
@@ -61,11 +49,7 @@ def main():
6149
for filename in glob.glob(f"{args.sync_upload[0]}/**", recursive=True):
6250
if os.path.isfile(filename):
6351
relative = filename[len(args.sync_upload[0]) + 1 :]
64-
dest = (
65-
os.path.join(args.sync_upload[1], relative)
66-
if args.sync_upload[1]
67-
else relative
68-
)
52+
dest = os.path.join(args.sync_upload[1], relative) if args.sync_upload[1] else relative
6953
print(f"{filename} -> {dest}")
7054
if not args.dry_run:
7155
blob_client = container_client.get_blob_client(blob=dest)
@@ -84,11 +68,7 @@ def main():
8468
os.makedirs(os.path.dirname(dest), exist_ok=True)
8569
if not args.dry_run:
8670
with open(dest, "wb") as data:
87-
content = (
88-
container_client.get_blob_client(blob=src)
89-
.download_blob()
90-
.readall()
91-
)
71+
content = container_client.get_blob_client(blob=src).download_blob().readall()
9272
data.write(content)
9373

9474

0 commit comments

Comments
 (0)