Skip to content

Commit

Permalink
refactor spdx.helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Nov 16, 2021
1 parent 131b8cc commit 2360337
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions poetry/core/spdx/helpers.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,24 @@
import functools
import json
import os

from io import open
from typing import Dict
from typing import Optional

from .license import License


_licenses: Optional[Dict[str, License]] = None


def license_by_id(identifier: str) -> License:
if not identifier:
raise ValueError("A license identifier is required")

licenses = _lazy_load_licenses()

id = identifier.lower()

if id not in licenses:
if not identifier:
raise ValueError("A license identifier is required")

return License(identifier, identifier, False, False)

return licenses[id]


def _lazy_load_licenses() -> Dict[str, License]:

global _licenses

if _licenses is None:
licenses = _load_licenses()
_licenses = licenses
return licenses
else:
return _licenses
licenses = _load_licenses()
return licenses.get(
identifier.lower(), License(identifier, identifier, False, False)
)


@functools.lru_cache()
def _load_licenses() -> Dict[str, License]:

licenses = {}
Expand Down

0 comments on commit 2360337

Please sign in to comment.