Skip to content

Commit

Permalink
Tools: Improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
cal0pteryx committed Jan 30, 2024
1 parent 018ae3e commit 41fce8e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 61 deletions.
48 changes: 14 additions & 34 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,23 @@ skip_gitignore = true

[tool.ruff]

select = [
"A", # flake8-builtins
"ANN", # flake8-annotations
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"C90", # mccabe
"DTZ", # flake8-datetimez
"E", # pycodestyle
"EM", # flake8-errmsg
"ERA", # eradicate
"F", # pyflakes
# "FBT", # flake8-boolean-trap
"ICN", # flake8-import-conventions
"ISC", # flake8-implicit-str-concat
"N", # pep8-naming
"PIE", # flake8-pie
"PGH", # pygrep-hooks
"PLC", # pylint
"PLE", # pylint
"PLR", # pylint
"PLW", # pylint
"Q", # flake8-quotes
"RUF", # Ruff-specific rules
"RET", # flake8-return
"S", # flake8-bandit
"SIM", # flake8-simplify
"T", # flake8-debugger, flake8-print
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
]
select = ["ALL"]

ignore = [
"ANN101", # missing-type-self
"COM812", # missing-trailing-comma
"D100", # undocumented-public-module
"D104", # undocumented-public-package
"D203", # one-blank-line-before-class
"D205", # blank-line-after-summary
"D212", # multi-line-summary-first-line
"D213", # multi-line-summary-second-line
"D400", # ends-in-period
"D401", # non-imperative-mood
"D404", # docstring-starts-with-this
"D415", # ends-in-punctuation
"I001", # unsorted-imports
"PTH123", # builtin-open
]

target-version = "py311"
Expand Down
11 changes: 4 additions & 7 deletions tools/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import json
import logging
import os
import shutil
from http import HTTPStatus
from pathlib import Path
Expand Down Expand Up @@ -37,8 +36,8 @@ def download_file(url: str, path: Path) -> bool:
"""
try:
file_response = requests.get(url, timeout=5)
except (ConnectTimeout, ReadTimeout) as err:
log.error("Error while trying to download from %s, %s", url, err)
except (ConnectTimeout, ReadTimeout):
log.exception("Error while trying to download from %s", url)
return False

if not HTTPStatus.OK >= file_response.status_code < HTTPStatus.BAD_REQUEST:
Expand All @@ -61,10 +60,8 @@ def download_file(url: str, path: Path) -> bool:


def initialize_directory(path: Path) -> None:
"""
Remove path (if it exists) and containing files, then recreate path
"""
"""Remove path (if it exists) and containing files, then recreate path"""
if path.exists() and path.is_dir():
shutil.rmtree(path)

os.mkdir(path)
path.mkdir()
20 changes: 4 additions & 16 deletions tools/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#
# SPDX-License-Identifier: AGPL-3.0-or-later

"""
Download / prepare / process XMPP Providers data
"""
import json
import logging
import os
Expand Down Expand Up @@ -55,9 +52,7 @@


def prepare_provider_data_files() -> None:
"""
Download and prepare provider data files
"""
"""Download and prepare provider data files"""
initialize_directory(DOWNLOAD_PATH)

# Temporarily move 'logo' folder and 'recommended_clients.json'
Expand Down Expand Up @@ -180,9 +175,7 @@ def _get_providers_file() -> None:


def create_provider_pages() -> None:
"""
Create a .md page per provider
"""
"""Create a .md page per provider"""
log.info("Creating provider pages")
initialize_directory(PROVIDERS_PAGES_PATH)

Expand Down Expand Up @@ -218,9 +211,7 @@ def _parse_doap_infos(doap_file: str) -> dict[str, list[str]] | None:


def prepare_client_data_file() -> None:
"""
Download and prepare clients data
"""
"""Download and prepare clients data"""
log.info("Downloading clients list file")
Path(DOWNLOAD_PATH / "clients_data/doap_files").mkdir(parents=True)

Expand Down Expand Up @@ -248,16 +239,13 @@ def prepare_client_data_file() -> None:
xsf_software_list = json.load(json_file)

log.info("Parsing clients list infos")
client_names: list[str] = []
for client in providers_clients_list:
client_names.append(client)

client_infos: list[dict[str, str | bool | list[str] | None]] = []
for package in xsf_software_list:
if "client" not in package["categories"]:
continue

if package["name"] in client_names:
if package["name"] in providers_clients_list:
provider_infos = providers_clients_list[package["name"]]
if package["doap"] is not None:
log.info("Downloading DOAP file for: %s", package["name"])
Expand Down
1 change: 1 addition & 0 deletions tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ToolsArgumentParser(ArgumentParser):
"""Parses arguments for XMPP Providers Website processor."""

def __init__(self) -> None:
"""Parses arguments for XMPP Providers Website processor."""
super().__init__()

self.description = """
Expand Down
9 changes: 5 additions & 4 deletions tools/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@


def prepare_statistics() -> None: # noqa: C901, PLR0912, PLR0915
"""Create statistics dict which can be consumed by echarts."""
try:
with open(DATA_PATH / "providers.json") as file:
providers_data = json.load(file)
except json.decoder.JSONDecodeError as e:
log.error("Could not open providers.json: %s", e)
except json.decoder.JSONDecodeError:
log.exception("Could not open providers.json")
return

try:
with open(DATA_PATH / "filtered_providers.json") as file:
filtered_providers_data = json.load(file)
except json.decoder.JSONDecodeError as e:
log.error("Could not open filtered_providers.json: %s", e)
except json.decoder.JSONDecodeError:
log.exception("Could not open filtered_providers.json")
return

statistics_data = {
Expand Down

0 comments on commit 41fce8e

Please sign in to comment.