-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.py
109 lines (93 loc) · 3.53 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
#######################################################################
#
# See setup.cfg for most of the settings, this is just some custom
# commands related to the Sphinx docs and previous versions of our
# build system.
#
#######################################################################
from setuptools import setup, Command
from pkg_resources import load_entry_point
from wheel.bdist_wheel import bdist_wheel
import os, re, shutil, subprocess, sys, glob
doc_path = 'plink_src/doc'
# A real clean
class PLinkClean(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
for dir in ['build', 'dist', 'plink.egg-info', '__pycache__', doc_path]:
shutil.rmtree(dir, ignore_errors=True)
os.mkdir(doc_path)
for file in glob.glob('*.pyc'):
if os.path.exists(file):
os.remove(file)
# Building the documentation
class PLinkBuildDocs(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
sphinx_cmd = load_entry_point('sphinx>=1.7', 'console_scripts', 'sphinx-build')
sphinx_args = ['-a', '-E', '-d', 'doc_source/_build/doctrees',
'doc_source', 'plink_src/doc']
sphinx_cmd(sphinx_args)
def check_call(args):
try:
subprocess.check_call(args)
except subprocess.CalledProcessError:
executable = args[0]
command = [a for a in args if not a.startswith('-')][-1]
raise RuntimeError(command + ' failed for ' + executable)
class PlinkBuildWheel(bdist_wheel):
def run(self):
python = sys.executable
check_call([python, 'setup.py', 'build'])
check_call([python, 'setup.py', 'build_docs'])
check_call([python, 'setup.py', 'build'])
bdist_wheel.run(self)
class PLinkRelease(Command):
user_options = [('install', 'i', 'install the release into each Python')]
def initialize_options(self):
self.install = False
def finalize_options(self):
pass
def run(self):
if os.path.exists('build'):
shutil.rmtree('build')
if os.path.exists('dist'):
shutil.rmtree('dist')
pythons = os.environ.get('RELEASE_PYTHONS', sys.executable).split(',')
for python in pythons:
check_call([python, 'setup.py', 'build_all'])
if self.install:
check_call([python, 'setup.py', 'pip_install'])
# Build sdist/universal wheels using the *first* specified Python
check_call([pythons[0], 'setup.py', 'sdist'])
check_call([pythons[0], 'setup.py', 'bdist_wheel'])
class PLinkPipInstall(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
python = sys.executable
check_call([python, 'setup.py', 'bdist_wheel'])
egginfo = 'plink.egg-info'
if os.path.exists(egginfo):
shutil.rmtree(egginfo)
wheels = glob.glob('dist' + os.sep + '*.whl')
new_wheel = max(wheels, key=os.path.getmtime)
check_call([python, '-m', 'pip', 'uninstall', '-y', 'plink'])
check_call([python, '-m', 'pip', 'install',
'--upgrade-strategy', 'only-if-needed',
new_wheel])
setup(cmdclass={'clean': PLinkClean,
'build_docs': PLinkBuildDocs,
'bdist_wheel': PlinkBuildWheel,
'pip_install':PLinkPipInstall})