forked from stlehmann/pyads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
157 lines (122 loc) · 3.97 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
156
157
#! /usr/bin/env python
# -*-coding: utf-8 -*-
import io
import os
import re
import sys
import shutil
import subprocess
from setuptools import setup
from setuptools.command.test import test as TestCommand
from setuptools.command.install import install as _install
from distutils.command.build import build as _build
from distutils.command.clean import clean as _clean
from distutils.command.sdist import sdist as _sdist
def read(*names, **kwargs):
with io.open(
os.path.join(os.path.dirname(__file__), *names),
encoding=kwargs.get("encoding", "utf8")
) as fp:
return fp.read()
def find_version(*file_paths):
version_file = read(*file_paths)
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
version_file, re.M)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
def platform_is_linux():
return sys.platform.startswith('linux') or \
sys.platform.startswith('darwin')
def get_files_rec(directory):
res = []
for (path, directory, filenames) in os.walk(directory):
files = [os.path.join(path, fn) for fn in filenames]
res.append((path, files))
return res
data_files = get_files_rec('src')
def create_binaries():
subprocess.call(['make', '-C', 'src'])
def remove_binaries():
subprocess.call(['make', 'clean', '-C', 'src'])
def copy_sharedlib():
try:
shutil.copy('src/adslib.so', 'pyads/adslib.so')
except OSError:
pass
def remove_sharedlib():
try:
os.remove('pyads/adslib.so')
except OSError:
pass
class build(_build):
def run(self):
if platform_is_linux():
remove_binaries()
create_binaries()
copy_sharedlib()
remove_binaries()
_build.run(self)
class clean(_clean):
def run(self):
if platform_is_linux():
remove_binaries()
remove_sharedlib()
_clean.run(self)
class sdist(_sdist):
def run(self):
if platform_is_linux():
remove_binaries()
_sdist.run(self)
class install(_install):
def run(self):
if platform_is_linux():
create_binaries()
copy_sharedlib()
_install.run(self)
class PyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = ['--cov-report', 'html', '--cov-report', 'term',
'--cov=pyads']
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)
cmdclass = {
'test': PyTest,
'build': build,
'clean': clean,
'sdist': sdist,
'install': install,
}
setup(
name="pyads",
version=find_version('pyads', '__init__.py'),
description="Python wrapper for TwinCAT ADS library",
author="Stefan Lehmann",
author_email="Stefan.St.Lehmann@gmail.com",
packages=["pyads", "pyads.testserver_ex"],
package_data={'pyads': ['adslib.so']},
requires=[],
provides=['pyads'],
url='https://github.com/MrLeeh/pyads',
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Topic :: Software Development :: Libraries',
'Operating System :: Microsoft :: Windows',
'Operating System :: Microsoft :: Windows :: Windows 7'
],
cmdclass=cmdclass,
data_files=data_files,
tests_require=['pytest', 'pytest-cov'],
)