-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathsetup.py
403 lines (340 loc) · 11.9 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#!/usr/bin/env python
# Parsec Cloud (https://parsec.cloud) Copyright (c) AGPLv3 2019 Scille SAS
import os
from setuptools import setup, find_packages, distutils, Command
from setuptools.command.build_py import build_py
# Awesome hack to load `__version__`
__version__ = None
exec(open("parsec/_version.py", encoding="utf-8").read())
def fix_pyqt_import():
# PyQt5-sip is a distinct pip package that provides PyQt5.sip
# However it setuptools handles `setup_requires` by downloading the
# dependencies in the `./.eggs` directory without really installing
# them. This causes `import PyQt5.sip` to fail given the `PyQt5` folder
# doesn't contains `sip.so` (or `sip.pyd` on windows)...
import sys
import glob
import importlib
for module_name, path_glob in (
("PyQt5", ".eggs/*PyQt5*/PyQt5/__init__.py"),
("PyQt5.sip", ".eggs/*PyQt5_sip*/PyQt5/sip.*"),
):
# If the module has already been installed in the environment
# setuptools won't populate the `.eggs` directory and we have
# nothing to do
try:
importlib.import_module(module_name)
except ImportError:
pass
else:
continue
for path in glob.glob(path_glob):
spec = importlib.util.spec_from_file_location(module_name, path)
if spec:
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
break
else:
raise RuntimeError("Cannot found module `%s` in .eggs" % module_name)
class GeneratePyQtResourcesBundle(Command):
description = "Generates `parsec.core.gui._resource_rc` bundle module"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
fix_pyqt_import()
try:
from PyQt5.pyrcc_main import processResourceFile
self.announce("Generating `parsec.core.gui._resources_rc`", level=distutils.log.INFO)
processResourceFile(
["parsec/core/gui/rc/resources.qrc"], "parsec/core/gui/_resources_rc.py", False
)
except ImportError:
print("PyQt5 not installed, skipping `parsec.core.gui._resources_rc` generation.")
class GenerateChangelog(Command):
description = "Convert HISTORY.rst to HTML"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import docutils.core
destination_folder = "parsec/core/gui/rc/generated_misc"
self.announce(
f"Converting HISTORY.rst to {destination_folder}/history.html", level=distutils.log.INFO
)
os.makedirs(destination_folder, exist_ok=True)
docutils.core.publish_file(
source_path="HISTORY.rst",
destination_path=f"{destination_folder}/history.html",
writer_name="html",
)
class GeneratePyQtForms(Command):
description = "Generates `parsec.core.ui.*` forms module"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import os
import pathlib
from collections import namedtuple
fix_pyqt_import()
try:
from PyQt5.uic.driver import Driver
except ImportError:
print("PyQt5 not installed, skipping `parsec.core.gui.ui` generation.")
return
self.announce("Generating `parsec.core.gui.ui`", level=distutils.log.INFO)
Options = namedtuple(
"Options",
["output", "import_from", "debug", "preview", "execute", "indent", "resource_suffix"],
)
ui_dir = pathlib.Path("parsec/core/gui/forms")
ui_path = "parsec/core/gui/ui"
os.makedirs(ui_path, exist_ok=True)
for f in ui_dir.iterdir():
o = Options(
output=os.path.join(ui_path, "{}.py".format(f.stem)),
import_from="parsec.core.gui",
debug=False,
preview=False,
execute=False,
indent=4,
resource_suffix="_rc",
)
d = Driver(o, str(f))
d.invoke()
class ExtractTranslations(Command):
description = "Extract translation strings"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import os
import pathlib
from unittest.mock import patch
from babel.messages.frontend import CommandLineInterface
fix_pyqt_import()
try:
from PyQt5.pylupdate_main import main as pylupdate_main
except ImportError:
print("PyQt5 not installed, skipping `parsec.core.gui.ui` generation.")
return
self.announce("Generating ui translation files", level=distutils.log.INFO)
ui_dir = pathlib.Path("parsec/core/gui")
tr_dir = ui_dir / "tr"
os.makedirs(tr_dir, exist_ok=True)
new_args = ["pylupdate", str(ui_dir / "parsec-gui.pro")]
with patch("sys.argv", new_args):
pylupdate_main()
files = [str(f) for f in ui_dir.iterdir() if f.is_file() and f.suffix == ".py"]
files.sort()
files.append(str(tr_dir / "parsec_en.ts"))
args = [
"_",
"extract",
"-k",
"translate",
"-s",
"--no-location",
"-F",
".babel.cfg",
"--omit-header",
"-o",
str(tr_dir / "translation.pot"),
*files,
]
CommandLineInterface().run(args)
languages = ["fr", "en"]
for lang in languages:
po_file = tr_dir / f"parsec_{lang}.po"
if not po_file.is_file():
po_file.touch()
args = [
"_",
"update",
"-i",
str(tr_dir / "translation.pot"),
"-o",
str(po_file),
"-l",
lang,
]
CommandLineInterface().run(args)
class CompileTranslations(Command):
description = "Compile translations"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import os
import pathlib
from babel.messages.frontend import CommandLineInterface
self.announce("Compiling ui translation files", level=distutils.log.INFO)
ui_dir = pathlib.Path("parsec/core/gui")
tr_dir = ui_dir / "tr"
rc_dir = ui_dir / "rc" / "translations"
os.makedirs(rc_dir, exist_ok=True)
languages = ["fr", "en"]
for lang in languages:
args = [
"_",
"compile",
"-i",
str(tr_dir / f"parsec_{lang}.po"),
"-o",
str(rc_dir / f"parsec_{lang}.mo"),
]
CommandLineInterface().run(args)
class build_py_with_pyqt(build_py):
def run(self):
self.run_command("generate_pyqt_forms")
self.run_command("compile_translations")
self.run_command("generate_changelog")
self.run_command("generate_pyqt_resources_bundle")
return super().run()
class build_py_with_pyqt_resource_bundle_generation(build_py):
def run(self):
self.run_command("generate_pyqt_resources_bundle")
return super().run()
with open("README.rst") as readme_file:
readme = readme_file.read()
with open("HISTORY.rst") as history_file:
history = history_file.read()
requirements = [
"attrs==19.2.0",
"click==7.0",
"msgpack==0.6.0",
"wsproto==0.15.0",
"h11==0.10.0",
# Can use marshmallow or the toasted flavour as you like ;-)
# "marshmallow==2.14.0",
"toastedmarshmallow==0.2.6",
"pendulum==2.1.2",
"PyNaCl==1.4.0",
"trio==0.16.0",
"trio_typing==0.5.0",
"async_generator>=1.9",
'contextvars==2.1;python_version<"3.7"',
"sentry-sdk==0.14.3",
"structlog==19.2.0",
"importlib_resources==1.0.2",
"colorama==0.4.0", # structlog colored output
"async_exit_stack==1.0.1",
"outcome==1.0.0",
"packaging==20.4",
]
test_requirements = [
"pytest==5.4.3",
"pytest-cov==2.10.0",
"pytest-xdist==1.32.0",
"pytest-trio==0.5.2",
"pytest-qt==3.3.0",
"pytest-rerunfailures==9.0",
"hypothesis==5.3.0",
"hypothesis-trio==0.5.0",
"trustme==0.6.0",
# Winfsptest requirements
# We can't use `winfspy[test]` because of some pip limitations
# - see pip issues #7096/#6239/#4391/#988
# Looking forward to the new pip dependency resolver!
'pywin32==227;platform_system=="Windows"',
# Fix botocore and sphinx conflicting requirements on docutils
"docutils>=0.12,<0.16",
# Documentation generation requirements
"sphinx==2.4.3",
"sphinx-intl==2.0.0",
"sphinx-rtd-theme==0.4.3",
"psutil==5.7.3",
]
PYQT_DEPS = ["PyQt5==5.14.2", "pyqt5-sip==12.8.0"]
BABEL_DEP = "Babel==2.6.0"
WHEEL_DEP = "wheel==0.34.2"
DOCUTILS_DEP = "docutils==0.15"
extra_requirements = {
"core": [
*PYQT_DEPS,
BABEL_DEP,
'fusepy==3.0.1;platform_system=="Linux" or platform_system=="Darwin"',
'winfspy==0.8.0;platform_system=="Windows"',
"zxcvbn==4.4.27",
'psutil==5.7.3;platform_system=="Windows"',
],
"backend": [
"jinja2==2.11.2",
# PostgreSQL
"triopg==0.5.0",
"trio-asyncio==0.11.0",
# S3
"boto3==1.12.34",
"botocore==1.15.34",
# Swift
"python-swiftclient==3.5.0",
"pbr==4.0.2",
],
"dev": test_requirements,
}
extra_requirements["all"] = sum(extra_requirements.values(), [])
extra_requirements["oeuf-jambon-fromage"] = extra_requirements["all"]
setup(
name="parsec-cloud",
version=__version__,
description="Secure cloud framework",
long_description=readme + "\n\n" + history,
author="Scille SAS",
author_email="[email protected]",
url="https://github.com/Scille/parsec-cloud",
python_requires="~=3.6",
packages=find_packages(include=["parsec", "parsec.*"]),
package_dir={"parsec": "parsec"},
setup_requires=[WHEEL_DEP, *PYQT_DEPS, BABEL_DEP, DOCUTILS_DEP], # To generate resources bundle
install_requires=requirements,
extras_require=extra_requirements,
cmdclass={
"generate_pyqt_resources_bundle": GeneratePyQtResourcesBundle,
"generate_changelog": GenerateChangelog,
"generate_pyqt_forms": GeneratePyQtForms,
"extract_translations": ExtractTranslations,
"compile_translations": CompileTranslations,
"generate_pyqt": build_py_with_pyqt,
"build_py": build_py_with_pyqt,
},
# Omitting GUI resources given they end up packaged in `parsec/core/gui/_resources_rc.py`
package_data={
"parsec.backend.postgresql.migrations": ["*.sql"],
"parsec.backend.templates": ["*"],
"parsec.backend.static": ["*"],
"parsec.core.resources": ["*.ico", "*.icns", "*.ignore"],
},
entry_points={
"console_scripts": ["parsec = parsec.cli:cli"],
"babel.extractors": ["extract_qt = misc.babel_qt_extractor.extract_qt"],
},
license="AGPLv3",
zip_safe=False,
keywords="parsec",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
"Natural Language :: English",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
test_suite="tests",
tests_require=test_requirements,
long_description_content_type="text/x-rst",
)