Skip to content

Commit

Permalink
Merge pull request #236 from macisamuele/maci-deprecate-pkg_resources
Browse files Browse the repository at this point in the history
Use importlib to retrieve library version
  • Loading branch information
macisamuele committed Jul 14, 2024
2 parents fd08295 + 634b990 commit d2d51b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
17 changes: 8 additions & 9 deletions language_formatters_pre_commit_hooks/__init__.py
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))
7 changes: 4 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ classifiers =
License :: OSI Approved :: Apache Software License
Operating System :: OS Independent
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.12
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
description = List of pre-commit hooks meant to format your source code.
Expand All @@ -25,12 +24,14 @@ version = 2.13.0

[options]
install_requires =
setuptools
config_formatter
importlib-metadata; python_version<"3.10"
packaging
requests
ruamel.yaml
setuptools
toml-sort>=0.22.0 # 0.22.0 introduces specific prettification configs (ie. SortConfiguration)

packages = find:

[options.packages.find]
Expand Down

0 comments on commit d2d51b4

Please sign in to comment.