-
Notifications
You must be signed in to change notification settings - Fork 312
/
setup.py
161 lines (136 loc) · 5.04 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
import os
import sys
import subprocess
import shutil
from distutils.sysconfig import get_python_lib
from setuptools import setup
VERSION = "3.3.3"
SKELETON_FOLDERS = ['pages', 'plugins', 'static/css', 'static/images', 'static/js', 'templates', 'locale']
SKELETON_GLOB = ['skeleton/{0}/*'.format(folder) for folder in SKELETON_FOLDERS]
if "uninstall" in sys.argv:
def run(command):
try:
return subprocess.check_output(command, shell = True).strip()
except subprocess.CalledProcessError:
pass
cactusBinPath = run('which cactus')
cactusPackagePath = None
for p in os.listdir(get_python_lib()):
if p.lower().startswith('cactus') and p.lower().endswith('.egg'):
cactusPackagePath = os.path.join(get_python_lib(), p)
if cactusBinPath and os.path.exists(cactusBinPath):
sys.stdout.write('Removing cactus script at %s' % cactusBinPath)
os.unlink(cactusBinPath)
if cactusPackagePath and os.path.isdir(cactusPackagePath):
sys.stdout.write('Removing cactus package at %s' % cactusPackagePath)
shutil.rmtree(cactusPackagePath)
sys.exit()
if "install" in sys.argv or "bdist_egg" in sys.argv:
# Check if we have an old version of cactus installed
p1 = '/usr/local/bin/cactus.py'
p2 = '/usr/local/bin/cactus.pyc'
if os.path.exists(p1) or os.path.exists(p2):
sys.stdout.write("Error: you have an old version of Cactus installed, we need to move it:")
if os.path.exists(p1):
sys.stderr.write(" sudo rm %s" % p1)
if os.path.exists(p2):
sys.stderr.write(" sudo rm %s" % p2)
sys.exit()
# From Django
def fullsplit(path, result=None):
"""
Split a pathname into components (the opposite of os.path.join)
in a platform-neutral way.
"""
if result is None:
result = []
head, tail = os.path.split(path)
if head == '':
return [tail] + result
if head == path:
return result
return fullsplit(head, [tail] + result)
EXCLUDE_FROM_PACKAGES = ['cactus.skeleton',]
def is_package(package_name):
for pkg in EXCLUDE_FROM_PACKAGES:
if package_name.startswith(pkg):
return False
return True
# Compile the list of packages available, because distutils doesn't have
# an easy way to do this.
packages, package_data = [], {}
root_dir = os.path.dirname(__file__)
if root_dir != '':
os.chdir(root_dir)
cactus_dir = 'cactus'
for dirpath, dirnames, filenames in os.walk(cactus_dir):
# Ignore PEP 3147 cache dirs and those whose names start with '.'
dirnames[:] = [d for d in dirnames if not d.startswith('.') and d != '__pycache__']
parts = fullsplit(dirpath)
package_name = '.'.join(parts)
if '__init__.py' in filenames and is_package(package_name):
packages.append(package_name)
elif filenames:
relative_path = []
while '.'.join(parts) not in packages:
relative_path.append(parts.pop())
relative_path.reverse()
path = os.path.join(*relative_path)
package_files = package_data.setdefault('.'.join(parts), [])
package_files.extend([os.path.join(path, f) for f in filenames])
def find_requirements():
# Find all requirements.VERSION.txt files that match (e.g. Python 2.6 matches
# requirements.2.6.txt, requirements.2.txt, and requirments.txt).
v = [str(x) for x in sys.version_info[:2]]
requirements = []
while True:
reqs_file = '.'.join(["requirements"] + v + ["txt"])
try:
with open(os.path.join(root_dir, reqs_file)) as f:
requirements.extend(f.readlines())
except IOError:
pass
try:
v.pop()
except IndexError:
break
return requirements
setup(
name='Cactus',
version=VERSION,
description="Static site generation and deployment.",
long_description=open('README.md').read(),
url='http://github.com/koenbok/Cactus',
author='Koen Bok',
author_email='[email protected]',
license='BSD',
packages=packages,
package_data=package_data,
entry_points={
'console_scripts': [
'cactus = cactus.cli:cli_entrypoint',
],
},
install_requires=find_requirements(),
extras_require={
'GCS Deployment': ['google-api-python-client'],
'Cloud Files Deployment': ['pyrax'],
'Mac Native FSEvents': ['macfsevents'],
},
tests_require=open(os.path.join(root_dir, "test_requirements.txt")).readlines(),
zip_safe=False,
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Topic :: Internet :: WWW/HTTP",
],
)