Skip to content

Commit 6f6dc28

Browse files
committed
Always use setuptools in setup.py
This copies what we've already done for some other packages: always use setuptools but disable its implicit egg building which causes so many headaches. The setup code can be significantly simpler if it's not trying to handle the case where setuptools isn't in use.
1 parent de92a2b commit 6f6dc28

File tree

1 file changed

+51
-105
lines changed

1 file changed

+51
-105
lines changed

setup.py

Lines changed: 51 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,25 @@
1313

1414
from __future__ import print_function
1515

16+
import os
17+
import sys
18+
1619
name = "notebook"
1720

18-
#-----------------------------------------------------------------------------
1921
# Minimal Python version sanity check
20-
#-----------------------------------------------------------------------------
21-
22-
import sys
23-
2422
v = sys.version_info
2523
if v[:2] < (2,7) or (v[0] >= 3 and v[:2] < (3,3)):
2624
error = "ERROR: %s requires Python version 2.7 or 3.3 or above." % name
2725
print(error, file=sys.stderr)
2826
sys.exit(1)
2927

30-
PY3 = (sys.version_info[0] >= 3)
31-
3228
# At least we're on the python version we need, move on.
3329

34-
35-
#-------------------------------------------------------------------------------
36-
# Imports
37-
#-------------------------------------------------------------------------------
38-
39-
import os
40-
41-
from glob import glob
42-
4330
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
4431
# update it when the contents of directories change.
4532
if os.path.exists('MANIFEST'): os.remove('MANIFEST')
4633

47-
from distutils.core import setup
48-
49-
# Our own imports
34+
from setuptools import setup
5035

5136
from setupbase import (
5237
version,
@@ -60,9 +45,6 @@
6045
css_js_prerelease,
6146
)
6247

63-
isfile = os.path.isfile
64-
pjoin = os.path.join
65-
6648
setup_args = dict(
6749
name = name,
6850
description = "A web-based notebook environment for interactive computing",
@@ -76,7 +58,6 @@
7658
for more information.
7759
""",
7860
version = version,
79-
scripts = glob(pjoin('scripts', '*')),
8061
packages = find_packages(),
8162
package_data = find_package_data(),
8263
author = 'Jupyter Development Team',
@@ -94,105 +75,70 @@
9475
'Programming Language :: Python :: 2.7',
9576
'Programming Language :: Python :: 3',
9677
],
78+
zip_safe = False,
79+
install_requires = [
80+
'jinja2',
81+
'tornado>=4',
82+
'ipython_genutils',
83+
'traitlets>=4.2.1',
84+
'jupyter_core>=4.4.0',
85+
'jupyter_client>=5.2.0',
86+
'nbformat',
87+
'nbconvert',
88+
'ipykernel', # bless IPython kernel for now
89+
'Send2Trash',
90+
'terminado>=0.8.1'
91+
],
92+
extras_require = {
93+
'test:python_version == "2.7"': ['mock'],
94+
'test': ['nose', 'coverage', 'requests', 'nose_warnings_filters', 'nbval'],
95+
'test:sys_platform == "win32"': ['nose-exclude'],
96+
},
97+
entry_points = {
98+
'console_scripts': [
99+
'jupyter-notebook = notebook.notebookapp:main',
100+
'jupyter-nbextension = notebook.nbextensions:main',
101+
'jupyter-serverextension = notebook.serverextensions:main',
102+
'jupyter-bundlerextension = notebook.bundler.bundlerextensions:main',
103+
]
104+
},
97105
)
98106

99-
100-
101-
#---------------------------------------------------------------------------
102-
# Find all the packages, package data, and data_files
103-
#---------------------------------------------------------------------------
104-
105-
packages = find_packages()
106-
package_data = find_package_data()
107-
108-
#---------------------------------------------------------------------------
109-
# custom distutils commands
110-
#---------------------------------------------------------------------------
111-
# imports here, so they are after setuptools import if there was one
107+
# Custom distutils/setuptools commands ----------
112108
from distutils.command.build_py import build_py
113109
from distutils.command.sdist import sdist
110+
from setuptools.command.bdist_egg import bdist_egg
111+
from setuptools.command.develop import develop
112+
113+
class bdist_egg_disabled(bdist_egg):
114+
"""Disabled version of bdist_egg
114115
116+
Prevents setup.py install from performing setuptools' default easy_install,
117+
which it should never ever do.
118+
"""
119+
def run(self):
120+
sys.exit("Aborting implicit building of eggs. Use `pip install .` to install from source.")
115121

116122
setup_args['cmdclass'] = {
117123
'build_py': css_js_prerelease(
118124
check_package_data_first(build_py)),
119125
'sdist' : css_js_prerelease(sdist, strict=True),
126+
'develop': css_js_prerelease(develop),
120127
'css' : CompileCSS,
121128
'js' : CompileJS,
122129
'jsdeps' : Bower,
123130
'jsversion' : JavascriptVersion,
131+
'bdist_egg': bdist_egg if 'bdist_egg' in sys.argv else bdist_egg_disabled,
124132
}
125133

134+
try:
135+
from wheel.bdist_wheel import bdist_wheel
136+
except ImportError:
137+
pass
138+
else:
139+
setup_args['cmdclass']['bdist_wheel'] = css_js_prerelease(bdist_wheel)
126140

127-
128-
#---------------------------------------------------------------------------
129-
# Handle scripts, dependencies, and setuptools specific things
130-
#---------------------------------------------------------------------------
131-
132-
if any(arg.startswith('bdist') for arg in sys.argv):
133-
import setuptools
134-
135-
# This dict is used for passing extra arguments that are setuptools
136-
# specific to setup
137-
setuptools_extra_args = {}
138-
139-
# setuptools requirements
140-
141-
pyzmq = 'pyzmq>=13'
142-
143-
setup_args['scripts'] = glob(pjoin('scripts', '*'))
144-
145-
install_requires = [
146-
'jinja2',
147-
'tornado>=4',
148-
'ipython_genutils',
149-
'traitlets>=4.2.1',
150-
'jupyter_core>=4.4.0',
151-
'jupyter_client>=5.2.0',
152-
'nbformat',
153-
'nbconvert',
154-
'ipykernel', # bless IPython kernel for now
155-
'Send2Trash',
156-
'terminado>=0.8.1'
157-
]
158-
extras_require = {
159-
'test:python_version == "2.7"': ['mock'],
160-
'test': ['nose', 'coverage', 'requests', 'nose_warnings_filters', 'nbval'],
161-
'test:sys_platform == "win32"': ['nose-exclude'],
162-
}
163-
164-
if 'setuptools' in sys.modules:
165-
# setup.py develop should check for submodules
166-
from setuptools.command.develop import develop
167-
setup_args['cmdclass']['develop'] = css_js_prerelease(develop)
168-
169-
try:
170-
from wheel.bdist_wheel import bdist_wheel
171-
except ImportError:
172-
pass
173-
else:
174-
setup_args['cmdclass']['bdist_wheel'] = css_js_prerelease(bdist_wheel)
175-
176-
setuptools_extra_args['zip_safe'] = False
177-
setup_args['extras_require'] = extras_require
178-
requires = setup_args['install_requires'] = install_requires
179-
180-
setup_args['entry_points'] = {
181-
'console_scripts': [
182-
'jupyter-notebook = notebook.notebookapp:main',
183-
'jupyter-nbextension = notebook.nbextensions:main',
184-
'jupyter-serverextension = notebook.serverextensions:main',
185-
'jupyter-bundlerextension = notebook.bundler.bundlerextensions:main',
186-
]
187-
}
188-
setup_args.pop('scripts', None)
189-
190-
#---------------------------------------------------------------------------
191-
# Do the actual setup now
192-
#---------------------------------------------------------------------------
193-
194-
setup_args.update(setuptools_extra_args)
195-
141+
# Run setup --------------------
196142
def main():
197143
setup(**setup_args)
198144

0 commit comments

Comments
 (0)