forked from Kethsar/ytarchive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
95 lines (79 loc) · 2.61 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
try:
from setuptools import Command, setup
except ImportError:
from distutils.core import Command, setup
from distutils.spawn import find_executable
from novaytarchive.util import derive_binname, golang_target
# we query the system or env for cross-compiling
go_target = golang_target(True, True)
binname = derive_binname(*go_target)
def du_spawn(cmd, dry_run=0, env=None):
""" Modified version of distutils.spawn.spawn that accepts env """
import subprocess
from distutils.errors import DistutilsExecError
from distutils.debug import DEBUG
from distutils import log
# cmd is documented as a list, but just in case some code passes a tuple
# in, protect our %-formatting code against horrible death
cmd = list(cmd)
log.info(' '.join(cmd))
if dry_run:
return
executable = find_executable(cmd[0])
if executable is not None:
cmd[0] = executable
try:
proc = subprocess.Popen(cmd, env=env)
proc.wait()
exitcode = proc.returncode
except OSError as exc:
if not DEBUG:
cmd = cmd[0]
raise DistutilsExecError(
"command %r failed: %s" % (cmd, exc.args[-1])) from exc
if exitcode:
if not DEBUG:
cmd = cmd[0]
raise DistutilsExecError(
"command %r failed with exit code %s" % (cmd, exitcode))
class BuildGolangPart(Command):
description = 'Build the golang counterpart of this module'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
du_spawn([
"go", "build",
"-buildmode=c-shared", "-o",
binname],
dry_run=self.dry_run,
env={
"GOOS": go_target[0],
"GOARCH": go_target[1],
"CGO_ENABLED": "1",
})
setup(
name='nova-ytarchive',
version='0.1.0',
maintainer='Lesmiscore',
maintainer_email='[email protected]',
description='Golang version of ytarchive to be called from Python',
url='https://github.com/ytdl-patched/ytarchive',
packages=['novaytarchive'],
project_urls={
'Source': 'https://github.com/ytdl-patched/ytarchive',
},
classifiers=[
'Development Status :: 4 - Beta',
'Programming Language :: Python',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'License :: OSI Approved :: MIT License',
],
python_requires='>=3.6',
data_files=[binname],
cmdclass={'BuildGolangPart': BuildGolangPart},
)