-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
executable file
·126 lines (112 loc) · 3.69 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
#!/bin/env python3
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright (C) 2020-21 Sean Anderson <[email protected]>
from distutils.command.build import build as distutils_build
import setuptools
from setuptools.command.develop import develop as setuptools_develop
import os
class build_fetch(setuptools.Command):
def initialize_options(self):
self.build_lib = None
self.inplace = False
self.package_dir = None
def finalize_options(self):
self.set_undefined_options('build_ext',
('build_lib', 'build_lib'),
('inplace', 'inplace'),
)
def run(self):
import requests
if self.inplace:
build_py = self.get_finalized_command('build_py')
vendor = f"{build_py.get_package_dir('trends.site')}/static/vendor"
else:
vendor = f"{self.build_lib}/trends/site/static/vendor"
try:
os.mkdir(vendor)
except FileExistsError:
pass
ts = ["js/tom-select.popular.min.js", "css/tom-select.min.css"]
ts += [f"{file}.map" for file in ts]
urls = [f"https://cdn.jsdelivr.net/npm/[email protected]/dist/{file}" for file in ts]
urls.append("https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min.js")
with requests.Session() as s:
for url in urls:
file = os.path.basename(url)
etag = f".{file}.etag"
file = os.path.join(vendor, file)
etag = os.path.join(vendor, etag)
print(f"Saving {url} to {file}")
headers = {}
try:
with open(etag) as e:
headers['If-None-Match'] = e.read()
except FileNotFoundError:
pass
resp = s.get(url, headers=headers)
resp.raise_for_status()
if not len(headers) or resp.status_code != requests.codes.not_modified:
with open(file, 'wb') as f:
f.write(resp.content)
with open(etag, 'w') as e:
e.write(resp.headers['etag'])
class develop(setuptools_develop):
def run(self):
self.reinitialize_command('build_fetch', inplace=1)
self.run_command('build_fetch')
super().run()
class build(distutils_build):
sub_commands = [('build_fetch', None)] + distutils_build.sub_commands
setuptools.setup(
name = 'trends.tf',
use_scm_version = {
'local_scheme': lambda version: \
version.format_choice("+{node}", "+{node}.d{time:%Y%m%d.h%H%M%S}"),
},
description = "Team Fortress 2 stats and trends",
author = 'Sean Anderson',
author_email = '[email protected]',
url = 'https://trends.tf/',
packages = ['trends'],
license = 'AGPL-3.0-only',
license_files = [
'COPYING',
'LICENSES/*',
],
setup_requires = [
'requests',
'setuptools_scm',
],
install_requires = [
'flask >= 2.0',
'mpmetrics',
'prometheus-flask-exporter',
'psycopg2',
'pylibmc',
'python-dateutil',
'requests',
'sentry-sdk[flask]',
'systemd-watchdog',
'zstandard',
],
extras_require = {
'tests': [
'hypothesis',
'pytest',
'python-testing-crawler',
'responses',
'testing.postgresql'
],
},
cmdclass = {
'build': build,
'build_fetch': build_fetch,
'develop': develop,
},
entry_points = {
'console_scripts': [
"trends_importer=trends.importer.cli:main",
],
},
include_package_data = True,
)