Skip to content
This repository was archived by the owner on May 20, 2022. It is now read-only.

Commit 01fd3c1

Browse files
committed
config: set version in package module
Instead of 'setup.py'. It is a common practice and very convenient.
1 parent 6d7627a commit 01fd3c1

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

fd_gcp/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@
2828
``kms_crypto_key_resource_name`` (unlike ``kms_crypto_key_id``).
2929
3030
"""
31+
32+
33+
__version__ = '0.1.0'

setup.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
#!/usr/bin/env python
2+
import os
3+
import re
4+
from typing import Sequence
5+
26
from setuptools import find_packages, setup
37

48

9+
def get_version(*file_paths: Sequence[str]) -> str:
10+
filename = os.path.join(os.path.dirname(__file__), *file_paths)
11+
version_file = open(filename).read()
12+
version_match = re.search(
13+
r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M)
14+
if version_match:
15+
return version_match.group(1)
16+
raise RuntimeError('Unable to find version string.')
17+
18+
19+
version = get_version('fd_gcp', '__init__.py')
20+
21+
522
with open('README.md') as readme_file:
623
readme = readme_file.read()
724

@@ -24,9 +41,6 @@
2441
# like 'coverage' or 'tox'.
2542
]
2643

27-
# TODO: extract from '__version__' in 'fd_gcp/__init__.py'.
28-
packages_version = '0.1.0'
29-
3044
# note: the "typing information" of this project's packages is not made available to its users
3145
# automatically; it needs to be packaged and distributed. The way to do so is fairly new and
3246
# it is specified in PEP 561 - "Distributing and Packaging Type Information".
@@ -63,6 +77,6 @@
6377
test_suite='tests',
6478
tests_require=test_requirements,
6579
url='https://github.com/fyndata/gcp-utils-python',
66-
version=packages_version,
80+
version=version,
6781
zip_safe=False,
6882
)

0 commit comments

Comments
 (0)