|
1 | 1 | # Copyright 2009-2013 Ram Rachum. |
2 | 2 | # This program is distributed under the MIT license. |
3 | 3 |
|
4 | | -''' |
5 | | -A bootstrap module for `python_toolbox`. |
6 | | -
|
7 | | -It checks all prerequisites are installed. |
8 | | -''' |
9 | | - |
10 | 4 | import sys |
11 | 5 |
|
12 | 6 | ### Confirming correct Python version: ######################################## |
13 | 7 | # # |
14 | 8 | if sys.version_info[0] >= 3: |
15 | 9 | raise Exception("Python 3.x is not supported, only Python 2.6 and Python " |
16 | 10 | "2.7.") |
17 | | -if sys.version_info[1] <= 4: |
| 11 | +if sys.version_info[1] <= 5: |
18 | 12 | raise Exception( |
19 | 13 | "You're using Python <= 2.5, but this package requires either Python " |
20 | 14 | "2.6 or Python 2.7, so you can't use it unless you upgrade your " |
|
24 | 18 | ### Finished confirming correct Python version. ############################### |
25 | 19 |
|
26 | 20 |
|
27 | | -frozen = getattr(sys, 'frozen', None) |
28 | | -is_pypy = ('__pypy__' in sys.builtin_module_names) |
29 | | - |
30 | | - |
31 | | -def __check_prerequisites(): |
32 | | - ''' |
33 | | - Check that all modules required for `python_toolbox` are installed. |
34 | | - |
35 | | - Returns a list of some imported modules: A reference to this list should be |
36 | | - kept alive so to prevent the imported modules from being garbage-collected, |
37 | | - which would cause Python to load them twice, which would needlessly |
38 | | - increase startup time. |
39 | | - ''' |
40 | | - |
41 | | - modules = [] |
42 | | - |
43 | | - class MissingModule(Exception): |
44 | | - '''A required module is not found.''' |
45 | | - |
46 | | - def check_pkg_resources(): |
47 | | - try: |
48 | | - import pkg_resources |
49 | | - except ImportError: |
50 | | - raise MissingModule( |
51 | | - "`pkg_resources` is required, but it's not currently " |
52 | | - "installed on your system. It comes with `distribute`, so " |
53 | | - "please install it according to the instructions here: " |
54 | | - "http://pypi.python.org/pypi/distribute" |
55 | | - ) |
56 | | - else: |
57 | | - return [pkg_resources] |
58 | | - |
59 | | - def check_distribute(): |
60 | | - if frozen: |
61 | | - # Can't check that `distribute` is installed when frozen with |
62 | | - # `py2exe`. |
63 | | - return [] |
64 | | - import pkg_resources |
65 | | - try: |
66 | | - pkg_resources.require('distribute') |
67 | | - except pkg_resources.DistributionNotFound: |
68 | | - raise MissingModule( |
69 | | - "`distribute` is required, but it's not currently installed " |
70 | | - "on your system. Please install it according to the " |
71 | | - "instructions here: http://pypi.python.org/pypi/distribute" |
72 | | - ) |
73 | | - else: |
74 | | - # Returning empty list because we didn't import `distribute`: |
75 | | - return [] |
76 | | - |
77 | | - |
78 | | - checkers = [check_pkg_resources, check_distribute] |
79 | | - |
80 | | - for checker in checkers: |
81 | | - modules += checker() |
82 | | - |
83 | | - return modules |
84 | | - |
85 | | - |
86 | | -__modules_list = __check_prerequisites() |
| 21 | +#frozen = getattr(sys, 'frozen', None) |
| 22 | +#is_pypy = ('__pypy__' in sys.builtin_module_names) |
0 commit comments