##// END OF EJS Templates
reformat
Matthias Bussonnier -
Show More
@@ -1,122 +1,123 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """
2 """
3 Utilities for timing code execution.
3 Utilities for timing code execution.
4 """
4 """
5
5
6 #-----------------------------------------------------------------------------
6 #-----------------------------------------------------------------------------
7 # Copyright (C) 2008-2011 The IPython Development Team
7 # Copyright (C) 2008-2011 The IPython Development Team
8 #
8 #
9 # Distributed under the terms of the BSD License. The full license is in
9 # Distributed under the terms of the BSD License. The full license is in
10 # the file COPYING, distributed as part of this software.
10 # the file COPYING, distributed as part of this software.
11 #-----------------------------------------------------------------------------
11 #-----------------------------------------------------------------------------
12
12
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16
16
17 import time
17 import time
18
18
19 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
20 # Code
20 # Code
21 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
22
22
23 # If possible (Unix), use the resource module instead of time.clock()
23 # If possible (Unix), use the resource module instead of time.clock()
24 try:
24 try:
25 import resource
25 import resource
26 except ImportError:
26 except ImportError:
27 resource = None
27 resource = None
28
28
29 # Some implementations (like jyputerlite) don't have getrusage
29 # Some implementations (like jyputerlite) don't have getrusage
30 if resource is not None and hasattr(resource, "getrusage"):
30 if resource is not None and hasattr(resource, "getrusage"):
31 def clocku():
31 def clocku():
32 """clocku() -> floating point number
32 """clocku() -> floating point number
33
33
34 Return the *USER* CPU time in seconds since the start of the process.
34 Return the *USER* CPU time in seconds since the start of the process.
35 This is done via a call to resource.getrusage, so it avoids the
35 This is done via a call to resource.getrusage, so it avoids the
36 wraparound problems in time.clock()."""
36 wraparound problems in time.clock()."""
37
37
38 return resource.getrusage(resource.RUSAGE_SELF)[0]
38 return resource.getrusage(resource.RUSAGE_SELF)[0]
39
39
40 def clocks():
40 def clocks():
41 """clocks() -> floating point number
41 """clocks() -> floating point number
42
42
43 Return the *SYSTEM* CPU time in seconds since the start of the process.
43 Return the *SYSTEM* CPU time in seconds since the start of the process.
44 This is done via a call to resource.getrusage, so it avoids the
44 This is done via a call to resource.getrusage, so it avoids the
45 wraparound problems in time.clock()."""
45 wraparound problems in time.clock()."""
46
46
47 return resource.getrusage(resource.RUSAGE_SELF)[1]
47 return resource.getrusage(resource.RUSAGE_SELF)[1]
48
48
49 def clock():
49 def clock():
50 """clock() -> floating point number
50 """clock() -> floating point number
51
51
52 Return the *TOTAL USER+SYSTEM* CPU time in seconds since the start of
52 Return the *TOTAL USER+SYSTEM* CPU time in seconds since the start of
53 the process. This is done via a call to resource.getrusage, so it
53 the process. This is done via a call to resource.getrusage, so it
54 avoids the wraparound problems in time.clock()."""
54 avoids the wraparound problems in time.clock()."""
55
55
56 u,s = resource.getrusage(resource.RUSAGE_SELF)[:2]
56 u,s = resource.getrusage(resource.RUSAGE_SELF)[:2]
57 return u+s
57 return u+s
58
58
59 def clock2():
59 def clock2():
60 """clock2() -> (t_user,t_system)
60 """clock2() -> (t_user,t_system)
61
61
62 Similar to clock(), but return a tuple of user/system times."""
62 Similar to clock(), but return a tuple of user/system times."""
63 return resource.getrusage(resource.RUSAGE_SELF)[:2]
63 return resource.getrusage(resource.RUSAGE_SELF)[:2]
64
64
65
65 else:
66 else:
66 # There is no distinction of user/system time under windows, so we just use
67 # There is no distinction of user/system time under windows, so we just use
67 # time.perff_counter() for everything...
68 # time.perff_counter() for everything...
68 clocku = clocks = clock = time.perf_counter
69 clocku = clocks = clock = time.perf_counter
69 def clock2():
70 def clock2():
70 """Under windows, system CPU time can't be measured.
71 """Under windows, system CPU time can't be measured.
71
72
72 This just returns perf_counter() and zero."""
73 This just returns perf_counter() and zero."""
73 return time.perf_counter(),0.0
74 return time.perf_counter(),0.0
74
75
75
76
76 def timings_out(reps,func,*args,**kw):
77 def timings_out(reps,func,*args,**kw):
77 """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output)
78 """timings_out(reps,func,*args,**kw) -> (t_total,t_per_call,output)
78
79
79 Execute a function reps times, return a tuple with the elapsed total
80 Execute a function reps times, return a tuple with the elapsed total
80 CPU time in seconds, the time per call and the function's output.
81 CPU time in seconds, the time per call and the function's output.
81
82
82 Under Unix, the return value is the sum of user+system time consumed by
83 Under Unix, the return value is the sum of user+system time consumed by
83 the process, computed via the resource module. This prevents problems
84 the process, computed via the resource module. This prevents problems
84 related to the wraparound effect which the time.clock() function has.
85 related to the wraparound effect which the time.clock() function has.
85
86
86 Under Windows the return value is in wall clock seconds. See the
87 Under Windows the return value is in wall clock seconds. See the
87 documentation for the time module for more details."""
88 documentation for the time module for more details."""
88
89
89 reps = int(reps)
90 reps = int(reps)
90 assert reps >=1, 'reps must be >= 1'
91 assert reps >=1, 'reps must be >= 1'
91 if reps==1:
92 if reps==1:
92 start = clock()
93 start = clock()
93 out = func(*args,**kw)
94 out = func(*args,**kw)
94 tot_time = clock()-start
95 tot_time = clock()-start
95 else:
96 else:
96 rng = range(reps-1) # the last time is executed separately to store output
97 rng = range(reps-1) # the last time is executed separately to store output
97 start = clock()
98 start = clock()
98 for dummy in rng: func(*args,**kw)
99 for dummy in rng: func(*args,**kw)
99 out = func(*args,**kw) # one last time
100 out = func(*args,**kw) # one last time
100 tot_time = clock()-start
101 tot_time = clock()-start
101 av_time = tot_time / reps
102 av_time = tot_time / reps
102 return tot_time,av_time,out
103 return tot_time,av_time,out
103
104
104
105
105 def timings(reps,func,*args,**kw):
106 def timings(reps,func,*args,**kw):
106 """timings(reps,func,*args,**kw) -> (t_total,t_per_call)
107 """timings(reps,func,*args,**kw) -> (t_total,t_per_call)
107
108
108 Execute a function reps times, return a tuple with the elapsed total CPU
109 Execute a function reps times, return a tuple with the elapsed total CPU
109 time in seconds and the time per call. These are just the first two values
110 time in seconds and the time per call. These are just the first two values
110 in timings_out()."""
111 in timings_out()."""
111
112
112 return timings_out(reps,func,*args,**kw)[0:2]
113 return timings_out(reps,func,*args,**kw)[0:2]
113
114
114
115
115 def timing(func,*args,**kw):
116 def timing(func,*args,**kw):
116 """timing(func,*args,**kw) -> t_total
117 """timing(func,*args,**kw) -> t_total
117
118
118 Execute a function once, return the elapsed total CPU time in
119 Execute a function once, return the elapsed total CPU time in
119 seconds. This is just the first value in timings_out()."""
120 seconds. This is just the first value in timings_out()."""
120
121
121 return timings_out(1,func,*args,**kw)[0]
122 return timings_out(1,func,*args,**kw)[0]
122
123
@@ -1,183 +1,185 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Setup script for IPython.
2 """Setup script for IPython.
3
3
4 Under Posix environments it works like a typical setup.py script.
4 Under Posix environments it works like a typical setup.py script.
5 Under Windows, the command sdist is not supported, since IPython
5 Under Windows, the command sdist is not supported, since IPython
6 requires utilities which are not available under Windows."""
6 requires utilities which are not available under Windows."""
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (c) 2008-2011, IPython Development Team.
9 # Copyright (c) 2008-2011, IPython Development Team.
10 # Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>
10 # Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>
11 # Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
11 # Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
12 # Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
12 # Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
13 #
13 #
14 # Distributed under the terms of the Modified BSD License.
14 # Distributed under the terms of the Modified BSD License.
15 #
15 #
16 # The full license is in the file COPYING.rst, distributed with this software.
16 # The full license is in the file COPYING.rst, distributed with this software.
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18
18
19 import os
19 import os
20 import sys
20 import sys
21 from itertools import chain
21 from itertools import chain
22
22
23 # **Python version check**
23 # **Python version check**
24 #
24 #
25 # This check is also made in IPython/__init__, don't forget to update both when
25 # This check is also made in IPython/__init__, don't forget to update both when
26 # changing Python version requirements.
26 # changing Python version requirements.
27 if sys.version_info < (3, 8):
27 if sys.version_info < (3, 8):
28 pip_message = 'This may be due to an out of date pip. Make sure you have pip >= 9.0.1.'
28 pip_message = 'This may be due to an out of date pip. Make sure you have pip >= 9.0.1.'
29 try:
29 try:
30 import pip
30 import pip
31 pip_version = tuple([int(x) for x in pip.__version__.split('.')[:3]])
31 pip_version = tuple([int(x) for x in pip.__version__.split('.')[:3]])
32 if pip_version < (9, 0, 1) :
32 if pip_version < (9, 0, 1) :
33 pip_message = 'Your pip version is out of date, please install pip >= 9.0.1. '\
33 pip_message = 'Your pip version is out of date, please install pip >= 9.0.1. '\
34 'pip {} detected.'.format(pip.__version__)
34 'pip {} detected.'.format(pip.__version__)
35 else:
35 else:
36 # pip is new enough - it must be something else
36 # pip is new enough - it must be something else
37 pip_message = ''
37 pip_message = ''
38 except Exception:
38 except Exception:
39 pass
39 pass
40
40
41
41
42 error = """
42 error = """
43 IPython 8+ supports Python 3.8 and above, following NEP 29.
43 IPython 8+ supports Python 3.8 and above, following NEP 29.
44 When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
44 When using Python 2.7, please install IPython 5.x LTS Long Term Support version.
45 Python 3.3 and 3.4 were supported up to IPython 6.x.
45 Python 3.3 and 3.4 were supported up to IPython 6.x.
46 Python 3.5 was supported with IPython 7.0 to 7.9.
46 Python 3.5 was supported with IPython 7.0 to 7.9.
47 Python 3.6 was supported with IPython up to 7.16.
47 Python 3.6 was supported with IPython up to 7.16.
48 Python 3.7 was still supported with the 7.x branch.
48 Python 3.7 was still supported with the 7.x branch.
49
49
50 See IPython `README.rst` file for more information:
50 See IPython `README.rst` file for more information:
51
51
52 https://github.com/ipython/ipython/blob/master/README.rst
52 https://github.com/ipython/ipython/blob/master/README.rst
53
53
54 Python {py} detected.
54 Python {py} detected.
55 {pip}
55 {pip}
56 """.format(py=sys.version_info, pip=pip_message )
56 """.format(py=sys.version_info, pip=pip_message )
57
57
58 print(error, file=sys.stderr)
58 print(error, file=sys.stderr)
59 sys.exit(1)
59 sys.exit(1)
60
60
61 # At least we're on the python version we need, move on.
61 # At least we're on the python version we need, move on.
62
62
63 from setuptools import setup
63 from setuptools import setup
64
64
65 # Our own imports
65 # Our own imports
66 from setupbase import target_update
66 from setupbase import target_update
67
67
68 from setupbase import (
68 from setupbase import (
69 setup_args,
69 setup_args,
70 check_package_data_first,
70 check_package_data_first,
71 find_data_files,
71 find_data_files,
72 git_prebuild,
72 git_prebuild,
73 install_symlinked,
73 install_symlinked,
74 install_lib_symlink,
74 install_lib_symlink,
75 install_scripts_for_symlink,
75 install_scripts_for_symlink,
76 unsymlink,
76 unsymlink,
77 )
77 )
78
78
79 #-------------------------------------------------------------------------------
79 #-------------------------------------------------------------------------------
80 # Handle OS specific things
80 # Handle OS specific things
81 #-------------------------------------------------------------------------------
81 #-------------------------------------------------------------------------------
82
82
83 if os.name in ('nt','dos'):
83 if os.name in ('nt','dos'):
84 os_name = 'windows'
84 os_name = 'windows'
85 else:
85 else:
86 os_name = os.name
86 os_name = os.name
87
87
88 # Under Windows, 'sdist' has not been supported. Now that the docs build with
88 # Under Windows, 'sdist' has not been supported. Now that the docs build with
89 # Sphinx it might work, but let's not turn it on until someone confirms that it
89 # Sphinx it might work, but let's not turn it on until someone confirms that it
90 # actually works.
90 # actually works.
91 if os_name == 'windows' and 'sdist' in sys.argv:
91 if os_name == 'windows' and 'sdist' in sys.argv:
92 print('The sdist command is not available under Windows. Exiting.')
92 print('The sdist command is not available under Windows. Exiting.')
93 sys.exit(1)
93 sys.exit(1)
94
94
95
95
96 #-------------------------------------------------------------------------------
96 #-------------------------------------------------------------------------------
97 # Things related to the IPython documentation
97 # Things related to the IPython documentation
98 #-------------------------------------------------------------------------------
98 #-------------------------------------------------------------------------------
99
99
100 # update the manuals when building a source dist
100 # update the manuals when building a source dist
101 if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'):
101 if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'):
102
102
103 # List of things to be updated. Each entry is a triplet of args for
103 # List of things to be updated. Each entry is a triplet of args for
104 # target_update()
104 # target_update()
105 to_update = [
105 to_update = [
106 ('docs/man/ipython.1.gz',
106 (
107 ['docs/man/ipython.1'],
107 "docs/man/ipython.1.gz",
108 'cd docs/man && python -m gzip --best ipython.1'),
108 ["docs/man/ipython.1"],
109 ]
109 "cd docs/man && python -m gzip --best ipython.1",
110 ),
111 ]
110
112
111
113
112 [ target_update(*t) for t in to_update ]
114 [ target_update(*t) for t in to_update ]
113
115
114 #---------------------------------------------------------------------------
116 #---------------------------------------------------------------------------
115 # Find all the packages, package data, and data_files
117 # Find all the packages, package data, and data_files
116 #---------------------------------------------------------------------------
118 #---------------------------------------------------------------------------
117
119
118 data_files = find_data_files()
120 data_files = find_data_files()
119
121
120 setup_args['data_files'] = data_files
122 setup_args['data_files'] = data_files
121
123
122 #---------------------------------------------------------------------------
124 #---------------------------------------------------------------------------
123 # custom distutils commands
125 # custom distutils commands
124 #---------------------------------------------------------------------------
126 #---------------------------------------------------------------------------
125 # imports here, so they are after setuptools import if there was one
127 # imports here, so they are after setuptools import if there was one
126 from setuptools.command.sdist import sdist
128 from setuptools.command.sdist import sdist
127
129
128 setup_args['cmdclass'] = {
130 setup_args['cmdclass'] = {
129 'build_py': \
131 'build_py': \
130 check_package_data_first(git_prebuild('IPython')),
132 check_package_data_first(git_prebuild('IPython')),
131 'sdist' : git_prebuild('IPython', sdist),
133 'sdist' : git_prebuild('IPython', sdist),
132 'symlink': install_symlinked,
134 'symlink': install_symlinked,
133 'install_lib_symlink': install_lib_symlink,
135 'install_lib_symlink': install_lib_symlink,
134 'install_scripts_sym': install_scripts_for_symlink,
136 'install_scripts_sym': install_scripts_for_symlink,
135 'unsymlink': unsymlink,
137 'unsymlink': unsymlink,
136 }
138 }
137
139
138
140
139 #---------------------------------------------------------------------------
141 #---------------------------------------------------------------------------
140 # Handle scripts, dependencies, and setuptools specific things
142 # Handle scripts, dependencies, and setuptools specific things
141 #---------------------------------------------------------------------------
143 #---------------------------------------------------------------------------
142
144
143 # setuptools requirements
145 # setuptools requirements
144
146
145 extras_require = dict(
147 extras_require = dict(
146 parallel=["ipyparallel"],
148 parallel=["ipyparallel"],
147 qtconsole=["qtconsole"],
149 qtconsole=["qtconsole"],
148 doc=["Sphinx>=1.3"],
150 doc=["Sphinx>=1.3"],
149 test=[
151 test=[
150 "pytest",
152 "pytest",
151 "testpath",
153 "testpath",
152 "pygments",
154 "pygments",
153 ],
155 ],
154 test_extra=[
156 test_extra=[
155 "pytest",
157 "pytest",
156 "testpath",
158 "testpath",
157 "curio",
159 "curio",
158 "matplotlib!=3.2.0",
160 "matplotlib!=3.2.0",
159 "nbformat",
161 "nbformat",
160 "numpy>=1.17",
162 "numpy>=1.17",
161 "pandas",
163 "pandas",
162 "pygments",
164 "pygments",
163 "trio",
165 "trio",
164 ],
166 ],
165 terminal=[],
167 terminal=[],
166 kernel=["ipykernel"],
168 kernel=["ipykernel"],
167 nbformat=["nbformat"],
169 nbformat=["nbformat"],
168 notebook=["notebook", "ipywidgets"],
170 notebook=["notebook", "ipywidgets"],
169 nbconvert=["nbconvert"],
171 nbconvert=["nbconvert"],
170 )
172 )
171
173
172
174
173 everything = set(chain.from_iterable(extras_require.values()))
175 everything = set(chain.from_iterable(extras_require.values()))
174 extras_require['all'] = list(sorted(everything))
176 extras_require['all'] = list(sorted(everything))
175
177
176 setup_args["extras_require"] = extras_require
178 setup_args["extras_require"] = extras_require
177
179
178 #---------------------------------------------------------------------------
180 #---------------------------------------------------------------------------
179 # Do the actual setup now
181 # Do the actual setup now
180 #---------------------------------------------------------------------------
182 #---------------------------------------------------------------------------
181
183
182 if __name__ == "__main__":
184 if __name__ == "__main__":
183 setup(**setup_args)
185 setup(**setup_args)
General Comments 0
You need to be logged in to leave comments. Login now