forked from Grokzen/pykwalify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·172 lines (135 loc) · 4.76 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
import re
import os
import sys
PACKAGE_NAME = "pykwalify"
IN_VIRTUALENV = True if 'VIRTUAL_ENV' in os.environ else False
def _load_version(filename='pykwalify/__init__.py'):
"Parse a __version__ number from a source file"
with open(filename) as source:
text = source.read()
match = re.search(r"__foobar__ = ['\"]([^'\"]*)['\"]", text)
if not match:
msg = "Unable to find version number in {}".format(filename)
raise RuntimeError(msg)
version = match.group(1)
return version
def list_dir(dirname):
import os
results = []
for root,dirs,files in os.walk(dirname):
for f in files:
results.append(os.path.join(root,f))
return results
settings = dict()
def split_path(string):
"""Takes a string containing a filesystem path and returns a list of
normalized pieces of that path.
Note that this function makes an absolute path into a relative, so use with caution.
Example: split_path('/foo/bar')
Returns: ['foo', 'bar']
Example: split_path('foo/bar/baz/')
Returns: ['foo', 'bar', 'baz']
Example: split_path('foo.txt')
Returns: ['foo.txt']
Arguments:
- `string`: string that might contain os.sep (likely "/")
"""
res = []
if os.sep in string:
splitted = string.split(os.sep)
for piece in reversed(splitted):
if piece: # remove empty pieces from split, e.g. /foo/bar is ['', 'foo', 'bar']
res.append(piece)
else:
res.append(string)
return res
def list_path(*args):
"""Takes strings containing filesystem paths and returns a list of
normalized and split pieces of those paths.
Note: this is analogous to concat_path() except that this function returns
a list, which in turn be used as an *args input to os.path.join() and be
cross-platform since all parts of the code uses os.sep instead of a
hardcoded "/".
Example: list_path('foo+bar', 'foo/bar/', '/one/two', 'bar')
Returns: ['foo+bar', 'foo', 'bar', 'one', 'two', 'bar']
Arguments:
- `*args`: strings
"""
res = []
for arg in args:
if os.sep in arg:
splitted = split_path(arg)
for piece in reversed(splitted):
res.append(piece)
else:
res.append(arg)
return res
def concat_path(b, *args):
""" Concats b with all arguments in '*args', handles if any argument contains more then 1 directory, example: foo/bar/asd/
Note: this is analogous to list_path() except that this function returns a
string, though this function is not cross-platform since it uses a
hardcoded "/" instead of os.sep.
Arguments:
- `b`: string - base from where to concat all '*args'
- `*args`: strings - all extra paths to concat, concats in order of list
"""
base = b # tmp var
for a in args:
if "/" in a:
for s in a.split("/"):
base = os.path.join(base, s)
else:
base = os.path.join(base, a)
return base
def get_install_path(*args):
""" Returns the root directory, either the root of the filesystem or the
virtualenv root.
Arguments:
- `*args`: string that will be concatenated with the root directory
"""
if IN_VIRTUALENV:
path = sys.prefix
else:
# TODO can this be done in a more portable fashion? Untested on
# Windows.
path = os.sep
return concat_path(path, *args)
def get_etc_path(*args):
base = [get_install_path(), 'etc', PACKAGE_NAME]
path = base + list_path(*args)
return os.path.join(*path)
def get_share_path(*args):
base = [get_install_path(), 'usr', 'share', PACKAGE_NAME]
path = base + list_path(*args)
return os.path.join(*path)
settings.update(
name = PACKAGE_NAME,
version = "0.1.2",
description = 'Python lib/cli for JSON/YAML schema validation',
long_description = 'Python lib/cli for JSON/YAML schema validation',
author = "Grokzen",
author_email = "Grokzen@gmail.com",
exclude_package_data = { '': ['slask.py'] },
packages = ['pykwalify'],
scripts = ['scripts/pykwalify'],
data_files = [ (get_etc_path(), list_dir("config") ) ],
install_requires = [
'docopt==0.6.0',
'PyYAML==3.10',
],
classifiers = (
'Development Status :: 1 - Alpha',
'Environment :: Console',
'Operating System :: POSIX',
'Operating System :: Microsoft :: Windows',
'Programming Language :: Python',
'Programming Language :: Python :: 3.1',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
)
)
setup(**settings)