Skip to content

Commit

Permalink
address mypy errors in core.spdx
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Nov 13, 2021
1 parent d33de51 commit 9beba39
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
3 changes: 0 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ ignore_errors = True
[mypy-poetry.core.semver.*]
ignore_errors = True

[mypy-poetry.core.spdx.*]
ignore_errors = True

[mypy-poetry.core.vcs.*]
ignore_errors = True

Expand Down
43 changes: 24 additions & 19 deletions poetry/core/spdx/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,66 @@
import os

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

from .license import License

if TYPE_CHECKING:
from .license import License # noqa

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

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

def license_by_id(identifier: str) -> License:

def license_by_id(identifier: str) -> "License":
from .license import License # noqa

if _licenses is None:
load_licenses()
licenses = _lazy_load_licenses()

id = identifier.lower()

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

return License(identifier, identifier, False, False)

return _licenses[id]
return licenses[id]


def load_licenses() -> None:
from .license import License # noqa
def _lazy_load_licenses() -> Dict[str, License]:

global _licenses

_licenses = {}
if _licenses is None:
licenses = _load_licenses()
_licenses = licenses
return licenses
else:
return _licenses


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

licenses = {}
licenses_file = os.path.join(os.path.dirname(__file__), "data", "licenses.json")

with open(licenses_file, encoding="utf-8") as f:
data = json.loads(f.read())

for name, license_info in data.items():
license = License(name, license_info[0], license_info[1], license_info[2])
_licenses[name.lower()] = license
licenses[name.lower()] = license

full_name = license_info[0].lower()
if full_name in _licenses:
existing_license = _licenses[full_name]
if full_name in licenses:
existing_license = licenses[full_name]
if not existing_license.is_deprecated:
continue

_licenses[full_name] = license
licenses[full_name] = license

# Add a Proprietary license for non-standard licenses
_licenses["proprietary"] = License("Proprietary", "Proprietary", False, False)
licenses["proprietary"] = License("Proprietary", "Proprietary", False, False)

return licenses


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion poetry/core/spdx/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
from urllib2 import urlopen # type: ignore


class Updater:
Expand Down

0 comments on commit 9beba39

Please sign in to comment.