-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathsetup.py
66 lines (55 loc) · 1.92 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
import os, stat, shutil
from subprocess import call
import venv
import pip
import platform
isWindows = platform.system() == "Windows"
def shell(command):
return call(command.split(' '))
def runPython(command):
if isWindows:
shell('env/scripts/python ' + command)
else:
shell('env/bin/python ' + command)
# helper function that allows deleting read only files when using rmtree
def remove_readonly(func, path, excinfo):
os.chmod(path, stat.S_IWRITE)
func(path)
# cleanup any previous demo files
for folder in ['hello-stackoverflow', 'myapp', 'newapp', 'env']:
if os.path.exists(folder):
shutil.rmtree(folder, onerror=remove_readonly)
shell("git clone https://github.com/qubitron/hello-stackoverflow")
os.chdir("hello-stackoverflow")
venv.create("env", with_pip=True)
runPython('-m pip install -r requirements.txt')
os.chdir('..')
shell("git clone https://github.com/qubitron/stackoverflow-flask")
os.chdir("stackoverflow-flask")
venv.create("env", with_pip=True)
runPython('-m pip install -r requirements.txt')
os.chdir('..')
os.mkdir('myapp')
os.chdir('myapp')
venv.create("env", with_pip=True)
runPython('-m pip install pylint')
os.chdir('..')
snippetsPath = ''
if isWindows:
snippetsPath = os.getenv('APPDATA') + '\\Code\\User\\snippets'
else:
snippetsPath = os.path.expanduser("~/Library/Application Support/Code/User/snippets")
snippetsFile = snippetsPath + '/python.json'
if not os.path.exists(snippetsPath):
os.mkdir(snippetsPath)
if os.path.exists(snippetsFile):
# Merge the snippets in, blow away comments
print("Merging snippets into existing code")
venv.create("env", with_pip=True)
runPython('-m pip install jstyleson')
if runPython('mergesnippets.py') != 0:
# something failed, blow away the snippets file
shutil.copy('python.json', snippetsPath)
shutil.rmtree('env', onerror=remove_readonly)
else:
shutil.copy('python.json', snippetsPath)