-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
117 lines (95 loc) · 3.05 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
# coding: utf-8
import re
import fnmatch
import shutil
import os.path
from setuptools import Command, setup
VENDOR_PATH = 'src/watch_rsync/vendor'
def get_version():
with open('src/watch_rsync/__version__.py', 'rb') as f:
content = f.read().decode('utf-8')
quotes = '[{}{}]'.format('"', "'")
pattern = r'__version__ = {q}([\d\.]+?){q}'.format(q=quotes)
return re.search(pattern, content).group(1)
__version__ = get_version()
def _clean(patterns):
base = os.getcwd().rstrip('/')
for root, dirnames, filenames in os.walk(base):
for name in dirnames + filenames:
fullpath = os.path.join(root, name)
fullname = fullpath[len(base) + 1:]
for pattern in patterns:
if fnmatch.fnmatch(fullname, pattern):
print(fullname)
if os.path.isdir(fullpath):
shutil.rmtree(fullpath)
elif os.path.exists(fullpath):
os.remove(fullpath)
class VendorCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
shutil.rmtree(VENDOR_PATH)
os.system('pip install --no-binary :all --no-compile --no-deps -r requirements.txt -t {}'
.format(VENDOR_PATH))
_clean([
'**/vendor/bin',
'**/vendor/*.dist-info',
'**/vendor/*.so',
'**/*.egg-info',
'**/__pycache__',
'**/*.py[co]',
])
class PackageCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
_clean([
'**/*.egg-info',
'**/__pycache__',
'**/*.py[co]',
])
if not os.path.exists('dist'):
os.makedirs('dist')
os.system("cd src && zip -r - * > ../dist/watch-rsync")
with open('dist/watch-rsync', 'rb+') as f:
data = f.read()
f.seek(0)
f.write(b'#!/usr/bin/env python\n')
f.write(data)
os.system('chmod u+x dist/watch-rsync')
setup(
cmdclass={
'vendor': VendorCommand,
'package': PackageCommand,
},
name='watch-rsync',
version=__version__,
description='Watch PATH and rsync to DEST',
author='guyskk',
author_email='[email protected]',
url='https://github.com/guyskk/watch-rsync',
packages=['watch_rsync'],
package_dir={'': 'src'},
include_package_data=True,
entry_points={
'console_scripts': ['watch-rsync=watch_rsync.main:main']
},
license='MIT',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: MIT License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX',
'Programming Language :: Python',
],
)