Show More
@@ -1,118 +1,120 b'' | |||
|
1 | """Find files and directories which IPython uses. | |
|
2 | """ | |
|
1 | 3 | import os.path |
|
2 | 4 | import shutil |
|
3 | 5 | import tempfile |
|
4 | 6 | from warnings import warn |
|
5 | 7 | |
|
6 | 8 | import IPython |
|
7 | 9 | from IPython.utils.importstring import import_item |
|
8 | 10 | from IPython.utils.path import ( |
|
9 | 11 | get_home_dir, get_xdg_dir, get_xdg_cache_dir, compress_user, _writable_dir, |
|
10 | 12 | ensure_dir_exists, fs_encoding, filefind |
|
11 | 13 | ) |
|
12 | 14 | from IPython.utils import py3compat |
|
13 | 15 | |
|
14 | 16 | def get_ipython_dir(): |
|
15 | 17 | """Get the IPython directory for this platform and user. |
|
16 | 18 | |
|
17 | 19 | This uses the logic in `get_home_dir` to find the home directory |
|
18 | 20 | and then adds .ipython to the end of the path. |
|
19 | 21 | """ |
|
20 | 22 | |
|
21 | 23 | env = os.environ |
|
22 | 24 | pjoin = os.path.join |
|
23 | 25 | |
|
24 | 26 | |
|
25 | 27 | ipdir_def = '.ipython' |
|
26 | 28 | |
|
27 | 29 | home_dir = get_home_dir() |
|
28 | 30 | xdg_dir = get_xdg_dir() |
|
29 | 31 | |
|
30 | 32 | # import pdb; pdb.set_trace() # dbg |
|
31 | 33 | if 'IPYTHON_DIR' in env: |
|
32 | 34 | warn('The environment variable IPYTHON_DIR is deprecated. ' |
|
33 | 35 | 'Please use IPYTHONDIR instead.') |
|
34 | 36 | ipdir = env.get('IPYTHONDIR', env.get('IPYTHON_DIR', None)) |
|
35 | 37 | if ipdir is None: |
|
36 | 38 | # not set explicitly, use ~/.ipython |
|
37 | 39 | ipdir = pjoin(home_dir, ipdir_def) |
|
38 | 40 | if xdg_dir: |
|
39 | 41 | # Several IPython versions (up to 1.x) defaulted to .config/ipython |
|
40 | 42 | # on Linux. We have decided to go back to using .ipython everywhere |
|
41 | 43 | xdg_ipdir = pjoin(xdg_dir, 'ipython') |
|
42 | 44 | |
|
43 | 45 | if _writable_dir(xdg_ipdir): |
|
44 | 46 | cu = compress_user |
|
45 | 47 | if os.path.exists(ipdir): |
|
46 | 48 | warn(('Ignoring {0} in favour of {1}. Remove {0} to ' |
|
47 | 49 | 'get rid of this message').format(cu(xdg_ipdir), cu(ipdir))) |
|
48 | 50 | elif os.path.islink(xdg_ipdir): |
|
49 | 51 | warn(('{0} is deprecated. Move link to {1} to ' |
|
50 | 52 | 'get rid of this message').format(cu(xdg_ipdir), cu(ipdir))) |
|
51 | 53 | else: |
|
52 | 54 | warn('Moving {0} to {1}'.format(cu(xdg_ipdir), cu(ipdir))) |
|
53 | 55 | shutil.move(xdg_ipdir, ipdir) |
|
54 | 56 | |
|
55 | 57 | ipdir = os.path.normpath(os.path.expanduser(ipdir)) |
|
56 | 58 | |
|
57 | 59 | if os.path.exists(ipdir) and not _writable_dir(ipdir): |
|
58 | 60 | # ipdir exists, but is not writable |
|
59 | 61 | warn("IPython dir '{0}' is not a writable location," |
|
60 | 62 | " using a temp directory.".format(ipdir)) |
|
61 | 63 | ipdir = tempfile.mkdtemp() |
|
62 | 64 | elif not os.path.exists(ipdir): |
|
63 | 65 | parent = os.path.dirname(ipdir) |
|
64 | 66 | if not _writable_dir(parent): |
|
65 | 67 | # ipdir does not exist and parent isn't writable |
|
66 | 68 | warn("IPython parent '{0}' is not a writable location," |
|
67 | 69 | " using a temp directory.".format(parent)) |
|
68 | 70 | ipdir = tempfile.mkdtemp() |
|
69 | 71 | |
|
70 | 72 | return py3compat.cast_unicode(ipdir, fs_encoding) |
|
71 | 73 | |
|
72 | 74 | |
|
73 | 75 | def get_ipython_cache_dir(): |
|
74 | 76 | """Get the cache directory it is created if it does not exist.""" |
|
75 | 77 | xdgdir = get_xdg_cache_dir() |
|
76 | 78 | if xdgdir is None: |
|
77 | 79 | return get_ipython_dir() |
|
78 | 80 | ipdir = os.path.join(xdgdir, "ipython") |
|
79 | 81 | if not os.path.exists(ipdir) and _writable_dir(xdgdir): |
|
80 | 82 | ensure_dir_exists(ipdir) |
|
81 | 83 | elif not _writable_dir(xdgdir): |
|
82 | 84 | return get_ipython_dir() |
|
83 | 85 | |
|
84 | 86 | return py3compat.cast_unicode(ipdir, fs_encoding) |
|
85 | 87 | |
|
86 | 88 | |
|
87 | 89 | def get_ipython_package_dir(): |
|
88 | 90 | """Get the base directory where IPython itself is installed.""" |
|
89 | 91 | ipdir = os.path.dirname(IPython.__file__) |
|
90 | 92 | return py3compat.cast_unicode(ipdir, fs_encoding) |
|
91 | 93 | |
|
92 | 94 | |
|
93 | 95 | def get_ipython_module_path(module_str): |
|
94 | 96 | """Find the path to an IPython module in this version of IPython. |
|
95 | 97 | |
|
96 | 98 | This will always find the version of the module that is in this importable |
|
97 | 99 | IPython package. This will always return the path to the ``.py`` |
|
98 | 100 | version of the module. |
|
99 | 101 | """ |
|
100 | 102 | if module_str == 'IPython': |
|
101 | 103 | return os.path.join(get_ipython_package_dir(), '__init__.py') |
|
102 | 104 | mod = import_item(module_str) |
|
103 | 105 | the_path = mod.__file__.replace('.pyc', '.py') |
|
104 | 106 | the_path = the_path.replace('.pyo', '.py') |
|
105 | 107 | return py3compat.cast_unicode(the_path, fs_encoding) |
|
106 | 108 | |
|
107 | 109 | def locate_profile(profile='default'): |
|
108 | 110 | """Find the path to the folder associated with a given profile. |
|
109 | 111 | |
|
110 | 112 | I.e. find $IPYTHONDIR/profile_whatever. |
|
111 | 113 | """ |
|
112 | 114 | from IPython.core.profiledir import ProfileDir, ProfileDirError |
|
113 | 115 | try: |
|
114 | 116 | pd = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), profile) |
|
115 | 117 | except ProfileDirError: |
|
116 | 118 | # IOError makes more sense when people are expecting a path |
|
117 | 119 | raise IOError("Couldn't find profile %r" % profile) |
|
118 | 120 | return pd.location |
@@ -1,81 +1,72 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | """Script to auto-generate our API docs. |
|
3 | 3 | """ |
|
4 | 4 | # stdlib imports |
|
5 | 5 | import os |
|
6 | 6 | import sys |
|
7 | 7 | |
|
8 | 8 | # local imports |
|
9 | 9 | sys.path.append(os.path.abspath('sphinxext')) |
|
10 | 10 | from apigen import ApiDocWriter |
|
11 | 11 | |
|
12 | 12 | #***************************************************************************** |
|
13 | 13 | if __name__ == '__main__': |
|
14 | 14 | pjoin = os.path.join |
|
15 | 15 | package = 'IPython' |
|
16 | 16 | outdir = pjoin('source','api','generated') |
|
17 | 17 | docwriter = ApiDocWriter(package,rst_extension='.rst') |
|
18 | 18 | # You have to escape the . here because . is a special char for regexps. |
|
19 | 19 | # You must do make clean if you change this! |
|
20 | 20 | docwriter.package_skip_patterns += [r'\.external$', |
|
21 | 21 | # Extensions are documented elsewhere. |
|
22 | 22 | r'\.extensions', |
|
23 | r'\.config\.profile', | |
|
24 | # Old nbformat versions | |
|
25 | r'\.nbformat\.v[1-2]', | |
|
26 | # Public API for this is in kernel.zmq.eventloops | |
|
27 | r'\.kernel\.zmq\.gui', | |
|
28 | 23 | # Magics are documented separately |
|
29 | 24 | r'\.core\.magics', |
|
25 | # This isn't API | |
|
26 | r'\.sphinxext', | |
|
27 | # Shims | |
|
28 | r'\.kernel', | |
|
30 | 29 | ] |
|
31 | 30 | |
|
32 | 31 | # The inputhook* modules often cause problems on import, such as trying to |
|
33 | 32 | # load incompatible Qt bindings. It's easiest to leave them all out. The |
|
34 | # main API is in the inputhook module, which is documented. | |
|
35 | 33 | docwriter.module_skip_patterns += [ r'\.lib\.inputhook.+', |
|
36 | 34 | r'\.ipdoctest', |
|
37 | 35 | r'\.testing\.plugin', |
|
38 | # This just prints a deprecation msg: | |
|
39 | r'\.frontend$', | |
|
40 | 36 | # Deprecated: |
|
41 | 37 | r'\.core\.magics\.deprecated', |
|
42 | 38 | # Backwards compat import for lib.lexers |
|
43 | 39 | r'\.nbconvert\.utils\.lexers', |
|
44 | 40 | # We document this manually. |
|
45 | 41 | r'\.utils\.py3compat', |
|
46 | # These are exposed by nbformat | |
|
47 | r'\.nbformat\.convert', | |
|
48 | r'\.nbformat\.validator', | |
|
49 | r'\.nbformat\.notebooknode', | |
|
50 | # Deprecated | |
|
51 | r'\.nbformat\.current', | |
|
52 | # Exposed by nbformat.vN | |
|
53 | r'\.nbformat\.v[3-4]\.nbbase', | |
|
54 | 42 | # These are exposed in display |
|
55 | 43 | r'\.core\.display', |
|
56 | 44 | r'\.lib\.display', |
|
57 |
# |
|
|
58 |
r'\. |
|
|
59 |
|
|
|
60 |
r'\. |
|
|
45 | # Shims | |
|
46 | r'\.config', | |
|
47 | r'\.consoleapp', | |
|
48 | r'\.frontend$', | |
|
49 | r'\.html', | |
|
50 | r'\.nbconvert', | |
|
51 | r'\.nbformat', | |
|
52 | r'\.parallel', | |
|
53 | r'\.qt', | |
|
61 | 54 | ] |
|
55 | # main API is in the inputhook module, which is documented. | |
|
62 | 56 | |
|
63 | 57 | # These modules import functions and classes from other places to expose |
|
64 | 58 | # them as part of the public API. They must have __all__ defined. The |
|
65 | 59 | # non-API modules they import from should be excluded by the skip patterns |
|
66 | 60 | # above. |
|
67 | 61 | docwriter.names_from__all__.update({ |
|
68 | 'IPython.nbformat', | |
|
69 | 'IPython.nbformat.v3', | |
|
70 | 'IPython.nbformat.v4', | |
|
71 | 62 | 'IPython.display', |
|
72 | 63 | }) |
|
73 | 64 | |
|
74 | 65 | # Now, generate the outputs |
|
75 | 66 | docwriter.write_api_docs(outdir) |
|
76 | 67 | # Write index with .txt extension - we can include it, but Sphinx won't try |
|
77 | 68 | # to compile it |
|
78 | 69 | docwriter.write_index(outdir, 'gen.txt', |
|
79 | 70 | relative_to = pjoin('source','api') |
|
80 | 71 | ) |
|
81 | 72 | print ('%d files written' % len(docwriter.written_modules)) |
General Comments 0
You need to be logged in to leave comments.
Login now