-
Notifications
You must be signed in to change notification settings - Fork 149
/
lg_cffi_setup.py
94 lines (81 loc) · 2.76 KB
/
lg_cffi_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
# adapted from https://caremad.io/2015/06/distributing-a-cffi-project-redux/ on 18 May 2016
from distutils.command.build import build
from setuptools.command.install import install
SETUP_REQUIRES_ERROR = (
"Requested setup command that needs 'setup_requires' while command line "
"arguments implied a side effect free command or option."
)
NO_SETUP_REQUIRES_ARGUMENTS = [
"-h", "--help",
"-n", "--dry-run",
"-q", "--quiet",
"-v", "--verbose",
"-v", "--version",
"--author",
"--author-email",
"--classifiers",
"--contact",
"--contact-email",
"--description",
"--egg-base",
"--fullname",
"--help-commands",
"--keywords",
"--licence",
"--license",
"--long-description",
"--maintainer",
"--maintainer-email",
"--name",
"--no-user-cfg",
"--obsoletes",
"--platforms",
"--provides",
"--requires",
"--url",
"clean",
"egg_info",
"register",
"sdist",
"upload",
]
class DummyCFFIBuild(build):
def run(self):
raise RuntimeError(SETUP_REQUIRES_ERROR)
class DummyCFFIInstall(install):
def run(self):
raise RuntimeError(SETUP_REQUIRES_ERROR)
def keywords_with_side_effects(argv, **kwargs):
def is_short_option(argument):
"""Check whether a command line argument is a short option."""
return len(argument) >= 2 and argument[0] == '-' and argument[1] != '-'
def expand_short_options(argument):
"""Expand combined short options into canonical short options."""
return ('-' + char for char in argument[1:])
def argument_without_setup_requirements(argv, i):
"""Check whether a command line argument needs setup requirements."""
if argv[i] in NO_SETUP_REQUIRES_ARGUMENTS:
# Simple case: An argument which is either an option or a command
# which doesn't need setup requirements.
return True
elif (is_short_option(argv[i]) and
all(option in NO_SETUP_REQUIRES_ARGUMENTS
for option in expand_short_options(argv[i]))):
# Not so simple case: Combined short options none of which need
# setup requirements.
return True
elif argv[i - 1:i] == ['--egg-base']:
# Tricky case: --egg-info takes an argument which should not make
# us use setup_requires (defeating the purpose of this code).
return True
else:
return False
if all(argument_without_setup_requirements(argv, i)
for i in range(1, len(argv))):
try:
cmdclass = kwargs["cmdclass"]
except KeyError:
cmdclass = kwargs["cmdclass"] = {}
cmdclass["build"] = DummyCFFIBuild
cmdclass["install"] = DummyCFFIInstall
return kwargs