Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor spdx.helpers #243

Merged
merged 1 commit into from
Nov 16, 2021
Merged
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
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()
neersighted marked this conversation as resolved.
Show resolved Hide resolved
def _load_licenses() -> Dict[str, License]:

licenses = {}
Expand Down