-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
156 lines (142 loc) · 4.68 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
import os
import shutil
import subprocess
import sys
from setuptools import Extension
from setuptools import find_packages
from setuptools import setup
from setuptools.command.build_ext import build_ext
base_path = os.path.abspath(os.path.dirname(__file__))
class NodeJsExtension(Extension):
def __init__(self, name, source_dir=''):
super().__init__(name, sources=[])
self.source_dir = os.path.abspath(source_dir)
class SetupHelper:
def __init__(
self,
source_dir: str,
ext_dir: str,
tmp_dir: str,
):
folder_package = ''
for item in sys.path:
if 'dist-packages' in item or 'site-packages' in item:
folder_package = item
break
self._source_dir = source_dir
self._ext_dir = ext_dir
self._tmp_dir = tmp_dir
self._folder_package = folder_package
def clean_old_installation(self):
# CHECK IF IS INSTALLATION FROM PYPI
if os.path.isdir(os.path.join(self._source_dir, 'src')):
try:
shutil.rmtree(
os.path.join(
self._folder_package,
'newcalls', 'node_modules',
),
)
except OSError:
pass
try:
shutil.rmtree(
os.path.join(
self._folder_package, 'newcalls', 'dist',
),
),
except OSError:
pass
try:
shutil.rmtree(os.path.join(self._tmp_dir))
except OSError:
pass
def run_installation(self):
# CHECK IF IS INSTALLATION FROM PYPI
if os.path.isdir(os.path.join(self._source_dir, 'src')):
# COPY NEEDED FILES
shutil.copytree(
os.path.join(self._source_dir, 'src'),
os.path.join(self._tmp_dir, 'src'),
)
shutil.copyfile(
os.path.join(self._source_dir, 'package.json'),
os.path.join(self._tmp_dir, 'package.json'),
)
shutil.copyfile(
os.path.join(self._source_dir, 'tsconfig.json'),
os.path.join(self._tmp_dir, 'tsconfig.json'),
)
shutil.copyfile(
os.path.join(self._source_dir, '.npmignore'),
os.path.join(self._tmp_dir, '.npmignore'),
)
# START COMPILATION
subprocess.check_call(
'npm install .',
shell=True,
cwd=self._tmp_dir,
)
shutil.copytree(
os.path.join(self._tmp_dir, 'node_modules'),
os.path.join(self._ext_dir, 'newcalls', 'node_modules'),
)
shutil.copytree(
os.path.join(self._tmp_dir, 'dist'),
os.path.join(self._ext_dir, 'newcalls', 'dist'),
)
class NodeJsBuilder(build_ext):
def run(self):
super().run()
def build_extension(self, ext):
ext_dir = os.path.abspath(
os.path.dirname(self.get_ext_fullpath(ext.name)),
)
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
sh = SetupHelper(
ext.source_dir,
ext_dir,
self.build_temp,
)
sh.clean_old_installation()
sh.run_installation()
with open(os.path.join(base_path, 'README.md'), encoding='utf-8') as f:
readme = f.read()
setup(
name='tg-newcalls',
version='0.0.2',
long_description=readme,
long_description_content_type='text/markdown',
url='https://github.com/jokokendi/newcalls',
author='jokokendi',
author_email='ajual7832@gmail.com',
license='LGPL-3.0',
license_file='LICENSE',
classifiers=[
'License :: OSI Approved :: '
'GNU Lesser General Public License v3 (LGPLv3)',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
ext_modules=[NodeJsExtension('newcalls')],
packages=find_packages(),
install_requires=[
'aiohttp',
'psutil',
'screeninfo',
],
python_requires='>=3.6.1',
include_package_data=True,
universal=True,
cmdclass={
'build_ext': NodeJsBuilder,
},
zip_safe=False,
)