-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
155 lines (126 loc) · 4.57 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Note: To use the 'upload' functionality of this file, you must:
# $ pip install twine
import io
import os
import subprocess
import sys
import unittest
from setuptools import find_packages, setup, Command
# conditionally import to allow setup.py install introduce requirements
try:
from sphinx.setup_command import BuildDoc
except ImportError:
BuildDoc = None
# Fixed Package meta-data.
NAME = 'pyedm'
DESCRIPTION = 'tools for emobon-datamanagement'
URL = 'https://embrc.eu/emo-bon'
EMAIL = '[email protected]'
AUTHOR = 'Marc Portier'
LICENSE = 'MIT'
CONSOLE_SCRIPTS = ['pyedm = pyedm.__main__:main']
TROVE_CLASSES = [
# Trove classifiers
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3.8',
]
TEST_FOLDER = 'tests'
TEST_PATTERN = 'test_*.py'
# Dynamic Packge meta-data - read from different local files
here = os.path.abspath(os.path.dirname(__file__))
# Import the README and use it as the long-description.
# Note: this will only work if 'README.rst' is present in your MANIFEST.in file!
with io.open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
long_description = '\n' + f.read()
def required(sfx=''):
""" Load the requirements from the requirements.txt file"""
reqs = []
try:
with open(f"requirements{sfx}.txt") as f:
reqs = [ln.strip() for ln in f.readlines() if not ln.startswith('-') and not ln.startswith('#') and ln.strip() != '']
finally:
return reqs
requirements = required()
requirements_dev = required('-dev')
# Load the package's __version__.py module as a dictionary.
about = {}
with io.open(os.path.join(here, NAME, '__version__.py')) as f:
exec(f.read(), about)
# define specific setup commands
class CommandBase(Command):
""""AbstractBase for our own commands"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
@staticmethod
def status(s):
"""Prints things in bold."""
print('\033[1m{0}\033[0m'.format(s))
class TestCommand(CommandBase):
""""Support setup.py test"""
description = 'Perform the tests'
def run(self):
self.status('Discovering tests with pattern %s in folder %s' % (TEST_PATTERN, TEST_FOLDER))
suite = unittest.TestLoader().discover(TEST_FOLDER, pattern=TEST_PATTERN)
runner = unittest.TextTestRunner()
result = runner.run(suite)
exit(0 if result.wasSuccessful() else 1)
class ReleaseCommand(CommandBase):
"""Support setup.py release."""
description = 'Tag the package.'
def run(self):
self.version_tag = 'v' + about['__version__']
self.status('Commiting this build...')
os.system('git commit -am "Setup.py commit for version {0}" '.format(self.version_tag))
self.status('Tagging this build with {0}'.format(self.version_tag))
try:
subprocess.run(['git', 'tag', self.version_tag], check=True)
self.status('Git push')
os.system('git push --tags')
except subprocess.CalledProcessError:
self.status('Rolling back last commit...')
os.system('git reset --soft HEAD~1')
# Delete old tag. This is not safe, needs to be done when pushing a new version only...
# os.system('git tag -d {0}'.format(self.version_tag))
sys.exit()
commands = {'release': ReleaseCommand, 'test': TestCommand}
# Conditionally add the BuildDoc command (if sphinx is available)
cmd_opts = dict()
if BuildDoc is not None:
commands['build_sphinx'] = BuildDoc
cmd_opts['build_sphinx'] = {
'project': ('setup.py', NAME),
'version': ('setup.py', about['__version__']),
'release': ('setup.py', about['__version__']),
'source_dir': ('setup.py', 'docs'),
}
# Where the magic happens:
setup(
name=NAME,
version=about['__version__'],
description=DESCRIPTION,
long_description=long_description,
author=AUTHOR,
author_email=EMAIL,
url=URL,
test_suite=TEST_FOLDER,
packages=find_packages(exclude=('tests',)),
# If your package is a single module, use this instead of 'packages':
# py_modules=['mypackage'],
entry_points={
'console_scripts': CONSOLE_SCRIPTS,
},
install_requires=requirements,
extras_require={'dev': requirements_dev},
include_package_data=True,
license=LICENSE,
classifiers=TROVE_CLASSES,
cmdclass=commands,
command_options=cmd_opts,
)