-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.py
85 lines (69 loc) · 2.38 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import json
import shutil
import zipfile
from urllib2 import urlopen
from setuptools import setup
from cStringIO import StringIO
BASE_URL = "https://github.com/cloudhead/less.js"
DEFAULT_VERSION = os.getenv('LESS_VERSION', '1.6.2')
PROJECT_DIR = os.environ.get('PROJECT_DIR')
def get_version():
if not PROJECT_DIR:
return DEFAULT_VERSION
package_file = os.path.join(PROJECT_DIR, 'package.json')
try:
package_json = json.load(open(package_file))
except (IOError, ValueError):
print "cannot find custom node version in package.json, using default"
else:
version = package_json.get('dependencies', {}).get('less', '')
if version.startswith('=='):
return version.replace('==', '')
return DEFAULT_VERSION
less_zip = urlopen("%s/archive/v%s.zip" % (BASE_URL, get_version()))
less_dir = zipfile.ZipFile(StringIO(less_zip.read()))
for entry in less_dir.namelist():
root_dir, __ = entry.split('/', 1)
break
less_dir.extractall()
scripts = []
data_files = []
lib_dir = os.path.join(root_dir, 'lib')
bin_dir = os.path.join(root_dir, 'bin')
for info in less_dir.infolist():
if info.filename.startswith(lib_dir) and info.filename.endswith('.js'):
path = '/'.join(info.filename.split('/')[1:-1])
data_files.append((path, [info.filename]))
elif info.filename.startswith(bin_dir) and os.path.isfile(info.filename):
scripts.append(info.filename)
setup(
name='virtual-less',
version='0.0.2',
description='Install lessc into your virtualenv',
author='Sebastian Vetter',
author_email='sebastian@roadside-developer.com',
url='http://github.com/elbaschid/virtual-less',
long_description="%s\n\n%s" % (open('README.rst').read(),
open('CHANGELOG.rst').read()),
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: POSIX',
'Programming Language :: JavaScript',
'Topic :: Software Development :: Libraries',
],
install_requires=[
'virtual-node>=0.0.3',
],
license='BSD',
scripts=scripts,
data_files=data_files,
)
# remove extracted files
shutil.rmtree(root_dir)