-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: python <3.9 absent importlib.resources.files
- Loading branch information
Showing
5 changed files
with
50 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,29 @@ | ||
from os import path | ||
|
||
# import pkg_resources | ||
from importlib.resources import files as pkg_resources_files | ||
try: | ||
from importlib.resources import files as pkg_resources_files | ||
|
||
def get_resource_file_path(anchor, resource_name: str) -> str: | ||
return str(pkg_resources_files(anchor) / resource_name) | ||
|
||
def get_resource_file_content(file_name: str) -> str: | ||
with open( | ||
pkg_resources_files(__name__) / path.join(".", "res", file_name), | ||
mode="rt", | ||
) as source: | ||
return source.read() | ||
def get_resource_file_content(file_name: str) -> str: | ||
with open( | ||
get_resource_file_path(__name__, path.join(".", "res", file_name)), | ||
mode="rt", | ||
) as source: | ||
return source.read() | ||
|
||
except ImportError: | ||
# import pkg_resources | ||
from pkg_resources import resource_filename | ||
|
||
def get_resource_file_path(anchor, resource_name: str) -> str: | ||
return resource_filename(anchor, resource_name) | ||
|
||
def get_resource_file_content(file_name: str) -> str: | ||
with open( | ||
get_resource_file_path(__name__, path.join(".", "res", file_name)), | ||
mode="rt", | ||
) as source: | ||
return source.read() |
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