forked from man-group/pkglib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
100 lines (84 loc) · 3.6 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
#!/bin/env python
import sys
# We wouldn't be a proper Python Packaging tool without a bit of monkey
# patching now would we :)
# Here we monkey patch the distutils.config.PyPIRCCommand to add support
# for the prompting of PyPI login details with performing any
# distutils/setuptools command which pushes data to the PyPI server.
#
# It also prevents the saving of passwords to the .pypirc file in the
# user's home directory and prompts of the password if it has been left
# out of the configuration file.
#
# This has to be done very first thing to get around the convoluted class
# hierarchy of the upload/register commands.
from pkglib.setuptools.command.pypirc import PyPIRCCommand
import distutils.config
distutils.config.PyPIRCCommand = PyPIRCCommand
from distutils import log
try:
from setuptools import _distribute
except ImportError, e:
log.fatal("Please install distribute to continue. "
"Eg: 'easy_install distribute'. \n"
"If using virtualenv you can do this with "
"'virtualenv pyenv --distribute'")
sys.exit(1)
from setuptools.command import develop, easy_install
from setuptools.dist import Distribution
from pkglib import config, CONFIG
from pkglib.setuptools import _setup
from pkglib.setuptools.command import develop as pkglib_develop
def get_index_url():
url = CONFIG.pypi_url
if not url.endswith('/simple') and not url.endswith('/simple/'):
url += '/simple'
return url
class PkgLibBootStrapDistribution(Distribution):
""" Used to enable our config system for pre-setup reqs.
"""
def fetch_build_egg(self, req):
try:
cmd = self._egg_fetcher
except AttributeError:
dist = self.__class__({'script_args': ['easy_install']})
dist.parse_config_files()
cmd = easy_install.easy_install(dist, args=['x'],
index_url=get_index_url())
cmd.ensure_finalized()
self._egg_fetcher = cmd
return cmd.easy_install(req)
# These are the setup arguments used when bootstrapping pkglib
setup_args = dict(
entry_points={
'pytest11': ['pytest_profile = pkglib.testing.pytest.profile'],
'paste.paster_create_template':
['pkglib_project = pkglib.project_template.paste_template:' \
'CorePackage']
},
extras_require={'dot': ['gprof2dot']},
# We have to use vanilla develop command here, as we require 3rd party
# libraries for our installer to work.
cmdclass={'develop': develop.develop},
distclass=PkgLibBootStrapDistribution,
)
if __name__ == '__main__':
# This defaults to WARN, not so fun for debugging setup_requires
log.set_threshold(log.INFO)
if 'develop' in sys.argv and '--help' not in sys.argv \
and '-h' not in sys.argv:
# We have to use vanilla develop command here, as we require 3rd party
# libraries for our installer to work.
# First strip off any of our extra options as these will break vanilla
# easy_install.
for (l_arg, s_arg, desc) in pkglib_develop.develop._user_options:
if '--%s' % l_arg in sys.argv:
sys.argv.remove('--%s' % l_arg)
if s_arg and '-%s' % s_arg in sys.argv:
sys.argv.remove('-%s' % s_arg)
# Read in our org config as to use a non-standard package index we'll
# need to set vanilla develop's command-line manually
config.setup_org_config()
sys.argv.extend(['-i', get_index_url()])
# Run setup with our boostrapping args
_setup.setup(**setup_args)