-
Notifications
You must be signed in to change notification settings - Fork 46
/
setup.py
57 lines (49 loc) · 2.08 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
# Copyright 2016-2018 Dirk Thomas
# Licensed under the Apache License, Version 2.0
import os
import sys
from setuptools import setup
minimum_version = (3, 6)
if sys.version_info < minimum_version:
sys.exit('This package requires at least Python %d.%d' % minimum_version)
cmdclass = {}
try:
from stdeb.command.sdist_dsc import sdist_dsc
except ImportError:
pass
else:
class CustomSdistDebCommand(sdist_dsc):
"""Weird approach to apply the Debian patches during packaging."""
def run(self): # noqa: D102
from stdeb.command import sdist_dsc
build_dsc = sdist_dsc.build_dsc
def custom_build_dsc(*args, **kwargs):
nonlocal build_dsc
debinfo = self.get_debinfo()
repackaged_dirname = \
debinfo.source + '-' + debinfo.upstream_version
dst_directory = os.path.join(
self.dist_dir, repackaged_dirname, 'debian', 'patches')
os.makedirs(dst_directory, exist_ok=True)
# read patch
with open('debian/patches/setup.cfg.patch', 'r') as h:
lines = h.read().splitlines()
print(
"writing customized patch '%s'" %
os.path.join(dst_directory, 'setup.cfg.patch'))
# write patch with modified path
with open(
os.path.join(dst_directory, 'setup.cfg.patch'), 'w'
) as h:
for line in lines:
if line.startswith('--- ') or line.startswith('+++ '):
line = \
line[0:4] + repackaged_dirname + '/' + line[4:]
h.write(line + '\n')
with open(os.path.join(dst_directory, 'series'), 'w') as h:
h.write('setup.cfg.patch\n')
return build_dsc(*args, **kwargs)
sdist_dsc.build_dsc = custom_build_dsc
super().run()
cmdclass['sdist_dsc'] = CustomSdistDebCommand
setup(cmdclass=cmdclass)