forked from twidi/py-dataql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·88 lines (69 loc) · 2.25 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
import ast
import codecs
import os
from pip.req import parse_requirements
from setuptools import setup, find_packages
# Configuration
package_name = 'dataql'
long_doc_file = 'DESCRIPTION.rst'
classifiers = [
"Development Status :: 4 - Beta",
"Operating System :: OS Independent",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
]
# Code
# The `session` argument for the `parse_requirements` function is available (but
# optional) in pip 1.5, and mandatory in next versions
try:
from pip.download import PipSession
except ImportError:
parse_args = {}
else:
parse_args = {'session': PipSession()}
def get_requirements(source):
install_reqs = parse_requirements(source, **parse_args)
return set([str(ir.req) for ir in install_reqs])
class VersionFinder(ast.NodeVisitor):
def __init__(self):
self.data = {}
def visit_Assign(self, node):
if node.targets[0].id in (
'__version__',
'__author__',
'__contact__',
'__homepage__',
'__license__',
):
self.data[node.targets[0].id[2:-2]] = node.value.s
def read(*path_parts):
filename = os.path.join(os.path.dirname(__file__), *path_parts)
with codecs.open(filename, encoding='utf-8') as fp:
return fp.read()
def find_info(*path_parts):
finder = VersionFinder()
node = ast.parse(read(*path_parts))
finder.visit(node)
info = finder.data
info['docstring'] = ast.get_docstring(node)
return info
package_info = find_info(package_name, '__init__.py')
setup(
name=package_name,
version=package_info['version'],
packages=find_packages(),
include_package_data=True,
description=package_info['docstring'],
long_description=read(long_doc_file),
url=package_info['homepage'],
author=package_info['author'],
author_email=package_info['contact'],
install_requires=get_requirements('requirements.txt'),
license=package_info['license'],
classifiers=classifiers,
)