-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·68 lines (54 loc) · 1.88 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
#!/usr/bin/env python3
"""Entrypoint for setuptools package installation.
isort:skip_file
"""
import sys
if sys.version_info <= (3, 3):
raise RuntimeError("Only Python >= 3.4 supported")
from os import path, chdir
from shlex import quote
from distutils.errors import DistutilsOptionError
try:
import pkg_resources
from setuptools import setup, find_namespace_packages
from setuptools.config import read_configuration
except ImportError:
raise RuntimeError(
"The setuptools package is missing or broken. To (re)install it run:\n"
"{} -m pip install -U setuptools".format(sys.executable)
)
def has_requirement(req):
try:
pkg_resources.require(req)
except pkg_resources.ResolutionError:
return False
else:
return True
if __name__ == "__main__":
# Allow setup.py to run from another directory
chdir(path.dirname(__file__) or ".")
SETUP_CONFIG = "setup.cfg"
if not path.isfile(SETUP_CONFIG):
raise RuntimeError("Unsupported package structure, a setup.cfg file is required")
config = read_configuration(SETUP_CONFIG)
options = config.get("options", {})
metadata = config.get("metadata", {})
missing_install_requires = tuple(
filter(lambda req: not has_requirement(req), options.get("setup_requires", []))
)
if missing_install_requires:
raise RuntimeError(
"Missing dependencies to install {}. To fix run:\n{} -m pip install {}".format(
metadata.get("name", "this package"),
sys.executable,
" ".join(map(quote, missing_install_requires)),
)
)
try:
setup()
except DistutilsOptionError:
raise RuntimeError(
"Perhaps your setuptools package is too old. To update it run:\n"
"{} -m pip install -U setuptools",
sys.executable,
)