-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
executable file
·105 lines (92 loc) · 3.25 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
#!/usr/bin/env python3
import os, io
import sys
from glob import glob
from pprint import pprint
from setuptools import setup
try:
VERSION = f"{io.open('VERSION').read().strip()}.{io.open('.build-id').read().strip()}"
except Exception:
try:
import yaml
pkginfo = yaml.safe_load(io.open('PKG-INFO').read())
VERSION = pkginfo['Version']
except ModuleNotFoundError:
with io.open('PKG-INFO') as fd:
for line in fd:
if 'Version' in line:
VERSION = line.split(': ')[1].strip()
break
try:
requirements = io.open('requirements.txt').read().strip().split('\n')
except Exception:
try:
requirements = io.open('smartmetertx2mongo.egg-info/requires.txt').read().strip().split('\n')
except Exception:
requirements = '''dateparser
kizano
pymongo
requests
cherrypy
PyYAML
python-gnupg
jinja2'''.split()
setup_opts = {
'name' : 'smartmetertx2mongo',
# We change this default each time we tag a release.
'version' : VERSION,
'description' : 'Implementation of smartmetertx to save records to mongodb with config driven via YAML.',
'author' : 'Markizano Draconus',
'author_email' : '[email protected]',
'url' : 'https://markizano.net/',
'license' : 'GNU',
'tests_require' : ['nose', 'mock', 'coverage'],
'setup_requires' : ['PyYAML>=6.0.1', 'boto3>=1.34.155'],
'install_requires' : requirements,
'package_dir' : { 'smartmetertx': 'lib/smartmetertx' },
'package_data' : { '': ['VERSION', 'requirements.txt'] },
'include_package_data': True,
'packages' : [
'smartmetertx',
],
'scripts' : glob('bin/*'),
'test_suite' : 'tests',
'data_files' : [
('share/smartmetertx', glob('lib/ui/*')),
]
}
try:
import argparse
HAS_ARGPARSE = True
except:
HAS_ARGPARSE = False
if not HAS_ARGPARSE: setup_opts['install_requires'].append('argparse')
# I botch this too many times.
if sys.argv[1] == 'test':
sys.argv[1] = 'nosetests'
if 'DEBUG' in os.environ: pprint(setup_opts)
setup(**setup_opts)
if 'sdist' in sys.argv:
import gnupg, hashlib
gpg = gnupg.GPG()
for artifact in glob('dist/*.tar.gz'):
# Detach sign the artifact in dist/ folder.
fd = open(artifact, 'rb')
checksums = open('dist/CHECKSUMS.txt', 'w+b')
status = gpg.sign_file(fd, detach=True, output=f'{artifact}.asc')
print(f'Signed {artifact} with {status.fingerprint}')
# create a MD5, SHA1 and SHA256 hash of the artifact.
for hashname in ['md5', 'sha1', 'sha256']:
hasher = getattr(hashlib, hashname)()
fd.seek(0,0)
hasher.update(fd.read())
digest = hasher.hexdigest()
checksums.write(f'''{hashname.upper()}:
{digest} {artifact}
'''.encode('utf-8'))
print(f'Got {artifact}.{hashname} as {digest}')
checksums.seek(0, 0)
chk_status = gpg.sign_file(checksums, detach=True, output=f'dist/CHECKSUMS.txt.asc')
checksums.close()
fd.close()
print(f'Signed CHECKSUMS.txt with {chk_status.fingerprint}')