setup.get_version()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 16
rs 10
c 0
b 0
f 0
cc 2
nop 1
1
import os
2
import re
3
from setuptools import setup, find_packages
4
5
6
def get_version(source):
7
    """
8
    Retrieve the version of a python distribution.
9
10
    version_file default is the <project_root>/_version.py
11
12
    :param source: Path to project root
13
    :return: Version string
14
    """
15
    version_str_lines = open(os.path.join(source, '_version.py'), "rt").read()
16
    version_str_regex = r"^__version__ = ['\"]([^'\"]*)['\"]"
17
    mo = re.search(version_str_regex, version_str_lines, re.M)
18
    if mo:
19
        return mo.group(1)
20
    else:
21
        raise RuntimeError("Unable to find version string in %s." % os.path.join(source, os.path.basename(source)))
22
23
24
setup(name='looptools',
25
      version=get_version('looptools'),
26
      packages=find_packages(),
27
      install_requires=[],
28
      url='https://github.com/sfneal/looptools',
29
      license='MIT Licence',
30
      author='Stephen Neal',
31
      author_email='[email protected]',
32
      description='Lightweight Python help utility.',
33
      long_description='Helper utility functions for logging output, timing processes and counting iterations.')
34