Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #73 from webscopeio/fix/72-NpmKeyError
Browse files Browse the repository at this point in the history
Fix/72 npm key error
  • Loading branch information
jvorcak committed Jan 28, 2020
2 parents d525d61 + de0fe80 commit 4639a18
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ examples
.vscode
**/node_modules/**
**/target/**
**/dist/**
**/dist/**
**/build/**
**/license_sh.egg-info/**
6 changes: 5 additions & 1 deletion license_sh/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ def get_npm_license_from_licenses_array(licenses_array):

license_name = UNKNOWN
for license_item in licenses_array:
license_item_type = license_item.get("type", UNKNOWN)
license_item_type = (
license_item.get("type", UNKNOWN)
if type(license_item) is dict
else f"{license_item}"
)
if license_name != UNKNOWN:
license_name = f"{license_name} AND {license_item_type}"
else:
Expand Down
7 changes: 4 additions & 3 deletions license_sh/runners/runners_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ async def fetch_concurrent(urls):
try:
output, version = await result
page = json.loads(output)
license_map[f"{page['name']}@{version}"] = extract_npm_license(
page, version
)
if ("name") in page:
license_map[f"{page['name']}@{version}"] = extract_npm_license(
page, version
)

except json.JSONDecodeError:
pass
Expand Down
2 changes: 1 addition & 1 deletion license_sh/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.15"
__version__ = "1.0.16"
10 changes: 10 additions & 0 deletions tests/runners/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ def test_extract_npm_license_simple(self):
name = extract_npm_license(data, "Unknown")
self.assertEqual(name, "MIT")

def test_extract_npm_licenses_global_single_string(self):
data = json.loads(
"""{
"name": "name",
"licenses": ["MIT"]
}"""
)
name = extract_npm_license(data, "Unknown")
self.assertEqual(name, "MIT")

def test_extract_npm_licenses_global_single(self):
data = json.loads(
"""{
Expand Down

0 comments on commit 4639a18

Please sign in to comment.