-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aab5e3f
commit 398d5b1
Showing
7 changed files
with
97 additions
and
55 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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Compatibility functions | ||
""" | ||
try: | ||
from importlib.resources import as_file, files | ||
except ImportError: | ||
from pkg_resources import resource_string, resource_filename | ||
|
||
|
||
try: | ||
from importlib.metadata import version | ||
except ImportError: | ||
from pkg_resources import require | ||
|
||
|
||
def get_resource_file(resource: str, filename: str): | ||
"""Compatibility function until pkg_resources is fully removed""" | ||
# pylint: disable=missing-parentheses-for-call-in-test | ||
if as_file and files: | ||
with as_file(files(resource).joinpath(filename)) as fpath: | ||
return fpath | ||
|
||
# pylint: disable=used-before-assignment | ||
return resource_filename(resource, filename) | ||
|
||
|
||
def get_resource_string(resource: str, filename: str): | ||
"""Compatibility function until pkg_resources is fully removed""" | ||
# pylint: disable=missing-parentheses-for-call-in-test | ||
if as_file and files: | ||
return files(resource).joinpath(filename).read_text(encoding="UTF-8") | ||
|
||
# pylint: disable=used-before-assignment | ||
return resource_string(resource, filename).decode("UTF-8") | ||
|
||
|
||
def get_version(): | ||
"""Compatibility function until pkg_resources is fully removed""" | ||
# pylint: disable=missing-parentheses-for-call-in-test,using-constant-test | ||
if version: | ||
return version("gscreenshot") | ||
|
||
# pylint: disable=used-before-assignment | ||
return require("gscreenshot")[0].version |
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