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

fix type errors in the spdx module #231

Merged
merged 1 commit into from
Nov 16, 2021
Merged
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
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
7 changes: 1 addition & 6 deletions poetry/core/spdx/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
from typing import Any
from typing import Dict
from typing import Optional


try:
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
from urllib.request import urlopen


class Updater:
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ module = [
'poetry.core.packages.*',
'poetry.core.pyproject.*',
'poetry.core.semver.*',
'poetry.core.spdx.*',
'poetry.core.version.*',
]
ignore_errors = true
Expand Down