Skip to content

Commit 460a7ab

Browse files
committed
use get_distribution from pkg_resources instead of mucking about in src dir
1 parent cddabb5 commit 460a7ab

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ dist/
1818
.tox/
1919
venv/
2020
env/
21-
src/aws_secretsmanager_caching/version.py
21+

setup.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
'Programming Language :: Python :: 3.7'
2222
],
2323
keywords='secretsmanager secrets manager development cache caching client',
24-
use_scm_version={
25-
'write_to': 'src/aws_secretsmanager_caching/version.py'
26-
},
24+
use_scm_version=True,
2725
python_requires='>3.5',
2826
install_requires=['botocore'],
2927
setup_requires=['pytest-runner', 'setuptools-scm'],

src/aws_secretsmanager_caching/secret_cache.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from copy import deepcopy
1515

1616
import botocore.session
17+
from pkg_resources import DistributionNotFound, get_distribution
1718

1819
from .cache import LRUCache, SecretCacheItem
1920
from .config import SecretCacheConfig
@@ -22,6 +23,11 @@
2223
class SecretCache:
2324
"""Secret Cache client for AWS Secrets Manager secrets"""
2425

26+
try:
27+
__version__ = get_distribution(__name__).version
28+
except DistributionNotFound:
29+
__version__ = '0.0.0'
30+
2531
def __init__(self, config=SecretCacheConfig(), client=None):
2632
"""Construct a secret cache using the given configuration and
2733
AWS Secrets Manager boto client.
@@ -38,13 +44,7 @@ def __init__(self, config=SecretCacheConfig(), client=None):
3844
if self._client is None:
3945
self._client = botocore.session.get_session().create_client("secretsmanager")
4046

41-
try:
42-
from .version import version
43-
except ModuleNotFoundError:
44-
version = '0.0.0'
45-
46-
self._version = version
47-
self._client.meta.config.user_agent_extra = "AwsSecretCache/{}".format(self._version)
47+
self._client.meta.config.user_agent_extra = "AwsSecretCache/{}".format(SecretCache.__version__)
4848

4949
def _get_cached_secret(self, secret_id):
5050
"""Get a cached secret for the given secret identifier.

0 commit comments

Comments
 (0)