-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
145 lines (108 loc) · 3.95 KB
/
setup.py
File metadata and controls
145 lines (108 loc) · 3.95 KB
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
import os
import platform
from pathlib import Path
import urllib
from urllib import request
from configparser import ConfigParser
import subprocess
from distutils.util import convert_path
from distutils.spawn import find_executable
from setuptools import setup, find_packages
from setuptools.command.develop import develop
from setuptools.command.install import install
def create_application_directory(name):
directory = Path.home() / f'.{name}'
os.makedirs(directory, exist_ok = True)
return directory
def install_virtualbox(version, build_version, directory):
url = f'https://download.virtualbox.org/virtualbox/{version}/VirtualBox-{version}-{build_version}-Linux_amd64.run'
intermediate_path = directory / Path('bin')
path = (intermediate_path / 'virtualbox.run').resolve()
os.makedirs(intermediate_path, exist_ok = True)
try:
request.urlretrieve(url, path)
except urllib.error.HTTPError as error:
if error.code == 404:
raise ValueError('unsupported version')
else:
raise error
subprocess.check_call(f'chmod +x {path}', shell = True)
subprocess.check_call(f'sudo sh {path} --nox11 n', shell = True)
subprocess.check_call(f'rm {path}', shell = True)
def install_docker_machine(version, platform_name, directory):
executable_extension = '.exe' if platform_name == 'Windows' else ''
url = f'https://github.com/docker/machine/releases/download/v{version}/docker-machine-{platform_name}-x86_64{executable_extension}'
intermediate_path = directory / Path('bin')
path = (intermediate_path / f'docker-machine{executable_extension}').resolve()
os.makedirs(intermediate_path, exist_ok = True)
try:
request.urlretrieve(url, path)
except urllib.error.HTTPError as error:
if error.code == 404:
raise ValueError('unsupported platform')
else:
raise error
if platform_name != 'Windows':
subprocess.check_call(f'chmod +x {path}', shell = True)
def write_configuration_file(configuration, directory):
parser = ConfigParser()
parser['DEFAULT'] = configuration
path = directory / 'configuration.ini'
with open(path, 'w') as file:
parser.write(file)
package_name = 'renderable-catalyst'
virtualbox_version = '6.1.16'
virtualbox_build_version = '140961'
docker_machine_version = '0.16.0'
application_directory = create_application_directory(package_name)
default_configuration = {
'root_path': str(application_directory.resolve()),
'api_hostname': '<api.renderable.com>',
'api_port': 443,
'api_version': 'v1',
'api_secure': True,
'machine_name': 'renderable-machine'
}
package_directory = package_name.replace('-', '_')
package_info = {}
with open(convert_path(f'{package_directory}/package.py'), 'r') as file:
exec(file.read(), package_info)
def install_dependencies():
platform_name = platform.system()
if platform_name != 'Windows' and find_executable('virtualbox') is None:
install_virtualbox(virtualbox_version, virtualbox_build_version, application_directory)
install_docker_machine(docker_machine_version, platform_name, application_directory)
write_configuration_file(default_configuration, application_directory)
class DevelopCommand(develop):
def run(self):
install_dependencies()
super().run()
class InstallCommand(install):
def run(self):
install_dependencies()
super().run()
requirements = [
'renderable-core@git+https://github.com/therenderable/renderable-core.git'
]
entrypoints = {
'console_scripts': [
f'{package_name} = {package_directory}.cli.__main__:main'
]
}
commands = {
'develop': DevelopCommand,
'install': InstallCommand
}
setup(
name = package_name,
version = package_info['__version__'],
description = package_info['__description__'],
author = package_info['__author__'],
author_email = package_info['__email__'],
license = package_info['__license__'],
python_requires = '>=3.7.0',
install_requires = requirements,
packages = find_packages(),
entry_points = entrypoints,
cmdclass = commands,
zip_safe = False)