Add basic lint setup with ruff by ulgens · Pull Request #143 · processing/processing-contributions · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/git-hooks.yml
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.16.2
hooks:
- id: ruff-check
args: ["--fix", "--show-fixes"]
- id: ruff-format
2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
line-length = 120
target-version = "py311"
31 changes: 16 additions & 15 deletions scripts/add_new_contribution_to_yaml.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
"""
given properties, add a new contribution to the contributions.yaml database file.
"""
from datetime import datetime, UTC

import json
import pathlib
from datetime import UTC, datetime
from sys import argv

from ruamel.yaml import YAML


def split_categories(categories):
categories = sorted(categories.replace('"', '').split(','))
categories = sorted(categories.replace('"', "").split(","))
categories = [category.strip() for category in categories]
return categories


def postprocess_properties(properties_dict):
if 'categories' in properties_dict and properties_dict['categories']:
properties_dict['categories'] = split_categories(properties_dict['categories'])
if properties_dict.get("categories"):
properties_dict["categories"] = split_categories(properties_dict["categories"])
else:
properties_dict['categories'] = None
properties_dict["categories"] = None

# add download
if 'download' not in properties_dict:
properties_dict['download'] = properties_dict['source'][:properties_dict['source'].rfind('.')] + '.zip'
if "download" not in properties_dict:
properties_dict["download"] = properties_dict["source"][: properties_dict["source"].rfind(".")] + ".zip"


if __name__ == "__main__":
Expand All @@ -35,29 +36,29 @@ def postprocess_properties(properties_dict):
postprocess_properties(props)

# open database
database_file = pathlib.Path(__file__).parent.parent / 'contributions.yaml'
database_file = pathlib.Path(__file__).parent.parent / "contributions.yaml"

yaml = YAML()
with open(database_file, 'r') as db:
with open(database_file, "r") as db:
data = yaml.load(db)

contributions_list = list(data['contributions'])
contributions_list = list(data["contributions"])

# find max index
max_index = max([int(contribution["id"]) for contribution in contributions_list])

# append new contribution with next index
# add status, at top
datetime_today = datetime.now(UTC).strftime('%Y-%m-%dT%H:%M:%S%z')
datetime_today = datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%S%z")
contribution = {
'id': max_index + 1,
'status': 'VALID',
'dateAdded': datetime_today,
"id": max_index + 1,
"status": "VALID",
"dateAdded": datetime_today,
}
contribution.update(props)

contributions_list.append(contribution)

# write all contributions to database file
with open(database_file, 'w') as db:
with open(database_file, "w") as db:
yaml.dump({"contributions": contributions_list}, db)
202 changes: 103 additions & 99 deletions scripts/fetch_updates.py
Loading