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