-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #486 from LedgerHQ/fix/importlib
[fix] 'importlib' does not exist on Python<=3.8
- Loading branch information
Showing
11 changed files
with
59 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import json | ||
from pathlib import Path | ||
from platform import python_version_tuple | ||
from typing import Dict | ||
|
||
major, minor, _ = python_version_tuple() | ||
assert major == "3" | ||
|
||
if int(minor) <= 8: | ||
import importlib_resources as resources | ||
else: | ||
import importlib.resources as resources | ||
|
||
|
||
def get_resources_path(module: str, filename: str) -> Path: | ||
return resources.files(__package__) / module / "resources" / filename | ||
|
||
|
||
def get_resource_schema_as_json(module: str, filename: str) -> Dict: | ||
with get_resources_path(module, filename).open("rb") as fp: | ||
schema = json.load(fp) | ||
return schema |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import speculos.resources_importer as r | ||
|
||
|
||
def test_api_resource_exists(): | ||
assert r.get_resources_path("api", "").exists() | ||
|
||
|
||
def test_mcu_resource_exists(): | ||
assert r.get_resources_path("mcu", "").exists() | ||
|
||
|
||
def test_load_json(): | ||
schema = r.get_resource_schema_as_json("api", "finger.schema") | ||
assert isinstance(schema, dict) |