-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use importlib to retrieve library version
This is meant to replace the deprecated `pkg_resources.get_distribution` APIs.
- Loading branch information
1 parent
fc0ab1d
commit e71890f
Showing
2 changed files
with
12 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
import pkg_resources | ||
from importlib import metadata | ||
|
||
|
||
__version__ = pkg_resources.get_distribution("language_formatters_pre_commit_hooks").version | ||
__version__ = metadata.version("language_formatters_pre_commit_hooks") | ||
|
||
|
||
def _get_default_version(tool_name: str) -> str: # pragma: no cover | ||
""" | ||
Read tool_name default version. | ||
The method is intended to be used only from language_formatters_pre_commit_hooks modules | ||
""" | ||
version_file = "{tool_name}.version".format(tool_name=tool_name) | ||
try: | ||
with open( | ||
pkg_resources.resource_filename( | ||
"language_formatters_pre_commit_hooks", | ||
"{tool_name}.version".format(tool_name=tool_name), | ||
) | ||
) as f: | ||
return f.readline().split()[0] | ||
for file in metadata.files("language_formatters_pre_commit_hooks") or (): | ||
if file.name == version_file: | ||
return file.read_text().strip() | ||
|
||
raise RuntimeError("Default version for {tool_name} is not found".format(tool_name=tool_name)) | ||
except: # noqa: E722 (allow usage of bare 'except') # pragma: no cover | ||
raise RuntimeError("No default version found for {tool_name}".format(tool_name=tool_name)) |
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