Skip to content

Commit

Permalink
remove 'spdx' module from whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Nov 16, 2021
1 parent 35ef528 commit 214af82
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module = [
'poetry.core.packages.*',
'poetry.core.pyproject.*',
'poetry.core.semver.*',
'poetry.core.spdx.*',
'poetry.core.vcs.*',
'poetry.core.version.*',
]
ignore_errors = true
Expand Down

0 comments on commit 214af82

Please sign in to comment.