Skip to content

Commit

Permalink
consolidate: Use json5 over json
Browse files Browse the repository at this point in the history
Use json5 over json to support more advanced json syntax, as.. trailing commas

Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Aug 30, 2023
1 parent 92448d8 commit bb7531f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions blueos_repository/consolidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any, AsyncIterable, Dict, List, Optional, Union

import aiohttp
import json5
import semver
from registry import Registry

Expand Down Expand Up @@ -124,7 +125,7 @@ async def all_repositories(self) -> AsyncIterable[RepositoryEntry]:
company, extension_name = repo.as_posix().split("/")[-3:-1]
identifier = ".".join([company, extension_name])
try:
data = json.load(individual_file)
data = json5.load(individual_file)
except Exception as exc:
raise Exception(f"Unable to parse file {repo}") from exc
company_logo = (repo / "../../company_logo.png").resolve().relative_to(repos.resolve())
Expand Down Expand Up @@ -169,9 +170,9 @@ async def run(self) -> None:
continue
raw_labels = await self.registry.fetch_labels(f"{repository.docker}:{tag}")
permissions = raw_labels.get("permissions", None)
links = json.loads(raw_labels.get("links", "{}"))
links = json5.loads(raw_labels.get("links", "{}"))
website = links.pop("website", raw_labels.get("website", None))
authors = json.loads(raw_labels.get("authors", "[]"))
authors = json5.loads(raw_labels.get("authors", "[]"))
# documentation is just a URL for a link, but the old format had it as its own label
docs = links.pop("docs", links.pop("documentation", raw_labels.get("docs", None)))
readme = raw_labels.get("readme", None)
Expand All @@ -182,16 +183,16 @@ async def run(self) -> None:
except Exception as error: # pylint: disable=broad-except
readme = str(error)
company_raw = raw_labels.get("company", None)
company = Company.from_json(json.loads(company_raw)) if company_raw is not None else None
company = Company.from_json(json5.loads(company_raw)) if company_raw is not None else None
support = links.pop("support", raw_labels.get("support", None))
type_ = raw_labels.get("type", ExtensionType.OTHER)
filter_tags = json.loads(raw_labels.get("tags", "[]"))
filter_tags = json5.loads(raw_labels.get("tags", "[]"))

new_version = Version(
permissions=json.loads(permissions) if permissions else None,
permissions=json5.loads(permissions) if permissions else None,
website=website,
authors=authors,
docs=json.loads(docs) if docs else None,
docs=json5.loads(docs) if docs else None,
readme=readme,
company=company,
support=support,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ packages = [{include = "blueos_repository"}]

[tool.poetry.dependencies]
aiohttp = "3.7.4"
json-five = "1.1.1"
python = "^3.10"
semver = "^2.13.0"

Expand Down

0 comments on commit bb7531f

Please sign in to comment.