-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
91 lines (85 loc) · 4.2 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
#!/usr/bin/env python3
## INFO ########################################################################
## ##
## cutils ##
## ====== ##
## ##
## Modern and Lightweight C Utilities ##
## Version: 0.8.96.268 (20141023) ##
## ##
## File: setup.py ##
## ##
## For more information about the project, visit <http://www.cutils.org>. ##
## Copyright (C) 2014 Peter Varo ##
## ##
## This program is free software: you can redistribute it and/or modify it ##
## under the terms of the GNU General Public License as published by the ##
## Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, but ##
## WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ##
## See the GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program, most likely a file in the root directory, ##
## called 'LICENSE'. If not, see <http://www.gnu.org/licenses>. ##
## ##
######################################################################## INFO ##
import sys
from os.path import join
from os import stat, chmod, symlink, remove
from distutils.core import setup
from distutils.sysconfig import get_python_lib
#------------------------------------------------------------------------------#
# Get command-line input
script, option, *folders = sys.argv
# If binary folder passed
try:
# Installation path
PKG_PATH = get_python_lib()
INC_PATH, LIB_PATH, BIN_PATH = folders
# Set argv back to normal, so that setup() can handle it
sys.argv = script, option
except IndexError:
pass
# Open version file and read back the most recent version info
with open('VERSION') as version:
# Setup python package
setup(name='cutils',
version='.'.join(version.read().split('.')[:-1]),
description='Modern and Lightweight C Utilities',
author='Peter Varo',
author_email='[email protected]',
license='GPLv3',
platforms='Any',
url='http://www.cutils.org',
package_dir={'': 'pycutils'},
packages=['cutils', 'cutils.internal'])
# Create the command-line tools
try:
for file in ('ccom', 'cdoc', 'clic', 'cver', 'cenv'):
dst = join(BIN_PATH, file)
src = join(PKG_PATH, 'cutils', file + '.py')
# If symlink already exists
try:
remove(dst)
except FileNotFoundError:
pass
# Create symlink
symlink(src, dst)
# Change ownership (make it executable for everyone)
chmod(dst, stat(dst).st_mode | 0o111)
print(src, '=>', dst)
# Because 'cenv' was the last one, the 'dst' is related to it
with open(dst, 'r+') as cenv:
# Set include and library locations based on teh makefile
source = cenv.read()
source = source.replace('__INCLUDE_DIR__', INC_PATH)
source = source.replace('__LIBRARY_DIR__', LIB_PATH)
cenv.seek(0)
cenv.write(source)
cenv.truncate()
except NameError as e:
pass