-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
86 lines (70 loc) · 2.46 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
#!/usr/bin/env python
"""Setup for quaerere-base-common
"""
import os
import re
import sys
from setuptools import setup
from setuptools.command.install import install
PROJECT_NAME = 'quaerere-base-common'
INSTALL_REQUIRES = [
'marshmallow<3,>=2.16.0',
]
SETUP_REQUIRES = [
'pytest-runner',
'Sphinx<2,>=1.8.0',
'sphinx-rtd-theme',
'setuptools',
]
TESTS_REQUIRES = [
'pytest>=4.2.0',
'pytest-cov>=2.6.0',
'pytest-flake8',
]
def get_version():
with open('VERSION') as f:
return f.readline().strip()
PROJECT_RELEASE = get_version()
PROJECT_VERSION = '.'.join(PROJECT_RELEASE.split('.')[:2])
# Taken from https://circleci.com/blog/continuously-deploying-python-\
# packages-to-pypi-with-circleci/
class VerifyVersionCommand(install):
"""Custom command to verify that the git tag matches our version"""
description = 'verify that the git tag matches our version'
def run(self):
release_regex = re.compile(r'^[0-9]+\.[0-9]+\.[0-9]+$')
if not release_regex.match(PROJECT_RELEASE):
sys.exit(0)
tag = os.getenv('CIRCLE_TAG')
if tag != 'v' + PROJECT_RELEASE:
info = "Git tag: {0} does not match the version of this " \
"app: {1}".format(tag, PROJECT_RELEASE)
sys.exit(info)
class WriteRequirementsCommand(install):
"""Writes all package requirements into requirements.txt"""
description = 'creates requirements.txt'
def run(self):
header = '# Generated file, do not edit\n'
all_requirements = INSTALL_REQUIRES + SETUP_REQUIRES + TESTS_REQUIRES
all_requirements = [I + '\n' for I in all_requirements]
all_requirements.insert(0, header)
with open('requirements.txt', 'w') as fh:
fh.writelines(all_requirements)
setup(name=PROJECT_NAME,
version=PROJECT_RELEASE,
test_suite='tests',
install_requires=INSTALL_REQUIRES,
setup_requires=SETUP_REQUIRES,
tests_require=TESTS_REQUIRES,
entry_points={
'distutils.commands': [
'build_sphinx = sphinx.setup_command:BuildDoc']},
command_options={
'build_sphinx': {
'project': ('setup.py', PROJECT_NAME),
'version': ('setup.py', PROJECT_VERSION),
'release': ('setup.py', PROJECT_RELEASE),
'source_dir': ('setup.py', 'docs'), }, },
cmdclass={
'mk_reqs': WriteRequirementsCommand,
'verify': VerifyVersionCommand, }, )