-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
107 lines (81 loc) · 2.94 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import codecs
import os
import re
import sys
import shutil
import setuptools
PACKAGE = 'granula'
ROOT = os.path.dirname(os.path.abspath(__file__))
def get_path(filename):
return os.path.join(ROOT, filename)
def get_version():
pattern = re.compile(r'__version__\s*=\s*\'(?P<version>\d+\.\d+\.\d+)\'')
with codecs.open(get_path('{}/__init__.py'.format(PACKAGE))) as f:
match = pattern.search(f.read())
if match is not None:
return match.group('version')
raise ValueError('Version not found for package "{}"'.format(PACKAGE))
def get_description():
with codecs.open(get_path('README.rst'), encoding='utf-8') as f:
return '\n' + f.read()
def get_requirements():
requirements = []
with codecs.open(get_path('requirements.txt'), encoding='utf-8') as f:
for requirement in f:
if '#' in requirement:
requirement, _, _ = requirement.partition('#')
requirement = requirement.strip()
if requirement and not requirement.startswith('-r '):
requirements.append(requirement)
return requirements
class UploadCommand(setuptools.Command):
"""
Support setup.py upload
"""
description = 'Build the package and upload it to PyPI'
user_options = []
@staticmethod
def _print_status(text):
"""Prints things in bold."""
print('\033[1m{0}\033[0m'.format(text))
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
self._print_status('Removing previous builds...')
shutil.rmtree('dist', ignore_errors=True)
self._print_status('Building source distribution...')
os.system('{} setup.py sdist bdist_wheel'.format(sys.executable))
self._print_status('Uploading the package to PyPi via Twine...')
os.system('twine upload dist/*')
self._print_status('Pushing git tags...')
os.system('git tag v{}'.format(get_version()))
os.system('git push --tags')
sys.exit()
setuptools.setup(
name=PACKAGE,
version=get_version(),
description='Multi-file Configurations for Python Applications',
long_description=get_description(),
author='Vladislav Blinov',
author_email='cunningplan@yandex.ru',
url='https://github.com/chomechome/granula',
packages=setuptools.find_packages(exclude=['tests']),
install_requires=get_requirements(),
include_package_data=True,
license='MIT',
classifiers=[
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
],
cmdclass={
'upload': UploadCommand,
},
)