mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-25 23:08:22 -05:00
Use abspath when determining api_doc file paths.
This commit is contained in:
@@ -2,9 +2,9 @@ import re
|
||||
from collections import defaultdict
|
||||
from itertools import chain
|
||||
import inspect
|
||||
from os.path import relpath
|
||||
from os.path import abspath, relpath
|
||||
|
||||
from pylons import config
|
||||
from pylons import g
|
||||
from pylons.i18n import _
|
||||
from reddit_base import RedditController
|
||||
from r2.lib.utils import Storage
|
||||
@@ -59,8 +59,13 @@ def api_doc(section, **kwargs):
|
||||
kwargs['extends'] = kwargs['extends']._api_doc
|
||||
doc.update(kwargs)
|
||||
doc['section'] = section
|
||||
doc['filepath'] = api_function.func_code.co_filename
|
||||
doc['lineno'] = api_function.func_code.co_firstlineno
|
||||
|
||||
file_path = abspath(api_function.func_code.co_filename)
|
||||
root_dir = g.paths['root']
|
||||
if file_path.startswith(root_dir):
|
||||
doc['relfilepath'] = relpath(file_path, root_dir)
|
||||
|
||||
return api_function
|
||||
return add_metadata
|
||||
|
||||
@@ -82,7 +87,6 @@ class ApidocsController(RedditController):
|
||||
- `extends`: API method from which to inherit documentation
|
||||
"""
|
||||
|
||||
root_dir = config['pylons.paths']['root']
|
||||
api_docs = defaultdict(lambda: defaultdict(dict))
|
||||
for name, func in controller.__dict__.iteritems():
|
||||
method, sep, action = name.partition('_')
|
||||
@@ -108,11 +112,6 @@ class ApidocsController(RedditController):
|
||||
del docs['extensions']
|
||||
docs['uri'] = uri
|
||||
|
||||
# make the file path relative to the module root for use in
|
||||
# github source link generation
|
||||
if docs['filepath'].startswith(root_dir):
|
||||
docs['relfilepath'] = relpath(docs['filepath'], root_dir)
|
||||
|
||||
# add every variant to the index -- the templates will filter
|
||||
# out variants in the long-form documentation
|
||||
for variant in chain([uri], docs.get('uri_variants', [])):
|
||||
|
||||
Reference in New Issue
Block a user