Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add source link to classes and method #94

Closed
shimizukawa opened this issue Jan 2, 2015 · 10 comments
Closed

Add source link to classes and method #94

shimizukawa opened this issue Jan 2, 2015 · 10 comments
Labels
closed:duplicate type:enhancement enhance or introduce a new feature

Comments

@shimizukawa
Copy link
Member

I start hacking autodoc in Sphinx to add a //source// link after each class/method/function name. This link will link to web page showing the code of the current module, like the browse view in Trac.

To attemp to do this I hack the //desc_directive()// function like this (from line 420:

#!python

    for i, sig in enumerate(signatures):
        # add a signature node for each signature in the current unit
        # and add a reference target for it
        sig = sig.strip()
        signode = addnodes.desc_signature(sig, '')
        signode['first'] = False

        # MY CODE START HERE
        # Create a reference
        newnode = nodes.reference('', '')
        innernode = nodes.emphasis('Source', 'Source')
        newnode['refuri'] = 'https://www.example.com/trac/project/browser/trunk/py/' + options['module'].replace('.', '/') + '.py'
        newnode.append(innernode)
        signode.append(newnode)
        # MY CODE FINISH HERE

        node.append(signode)

This is really preliminary code with everything hard coded. In the final version the URL will be taken from the conf.py file and a directive option (like :source:) will be added to the automodule directive.

Side note: I saw your proposal //Easily extendable autodoc// (issue #3), it looks a very very good idea. Any idea of a timeframe for when you will add this ? Hacking //desc_directive()// is not a good way to go.

In my attemp to do this I hit 2 problems:

The first one is the //Source// link was in front of the method name instead of after (HTML output):

#!html

<dt id="ui.cli.cli.CliController">
<!--[ui.cli.cli.CliController]-->
class <a class="reference external" href="www.example.com/trac/project/browser/trunk/py/ui/cli/cli.py"><em>Source</em></a>
<tt class="descname">CliController</tt>
<big>(</big><em>subject</em><big>)</big>
<a class="headerlink" href="#ui.cli.cli.CliController" title="Permalink to this definition">¶</a>
</dt>

I have no idea why because the nodes I add are childrens of the signode ?

My second problem is that I wish to add the line number to the URL of the class/method/function so we can jump directly to the good place in the code. The URL will be of this form:
www.example.com/trac/project/browser/trunk/py/ui/cli/cli.py#L234

There's a //lineno// variable in the //desc_directive()// function, but the number it give don't correspond to the real line number. But after I dig a little more into the Sphinx/docutils code, I was with the impression that //lineno// is supposed to be the real line number ?

Is there's a way to get the real line number (line number in the script file) in the //desc_directive()// function ?


@shimizukawa shimizukawa added closed:duplicate type:enhancement enhance or introduce a new feature labels Jan 2, 2015
@shimizukawa
Copy link
Member Author

From Anonymous on 2009-01-17 20:13:29+00:00

Bump!

@shimizukawa
Copy link
Member Author

From Georg Brandl on 2009-02-20 09:37:41+00:00

An extensive source link extension is planned for some later release.

It will include options to either let Sphinx generate highlighted sources, or just generate links to an external source like you do here.

@shimizukawa
Copy link
Member Author

From Georg Brandl on 2009-02-20 10:03:03+00:00

Closing in favor of #12.

Duplicate of #12.

@shimizukawa
Copy link
Member Author

From Anonymous on 2009-02-28 15:47:34+00:00

Bump!

@shimizukawa
Copy link
Member Author

From Anonymous on 2009-03-12 01:59:52+00:00

Bump!

@shimizukawa
Copy link
Member Author

From Anonymous on 2009-07-10 10:45:23+00:00

Bump!

@shimizukawa
Copy link
Member Author

From Anonymous on 2009-07-21 10:52:19+00:00

Online shopping is a wonderful way to save time as well as money.<<issue http://www.coupons4save.comAnjolee>> often have great sales and many even have free shipping coupons. These tips will help you find the coolest gifts for the best prices, all without leaving your house.

@shimizukawa
Copy link
Member Author

From Anonymous on 2009-07-24 12:09:17+00:00

Bump!

@shimizukawa
Copy link
Member Author

From Anonymous on 2010-01-31 10:30:10+00:00

Bump!

@shimizukawa
Copy link
Member Author

From Anonymous on 2012-06-26 02:07:37+00:00

baobao If you are able to keep both cover plans utilizing the same insurance broker, it could save you time and keep the two insurance policies ordered.So one can discover van and car cover policy at the cheapest charge for the company, it is best to go looking and evaluate cover firms. Perhaps you have learnt many people are coughing up a lot for van insurance. Should you put some effort and study into some insurance agencies, you will discover an inexpensive quote which effort pays out for you. http://www.fakeoakleyssunglasses4u.com/ Fake Oakleys http://www.coachonlineoutlet-us.org/ Coach Online Outlet http://www.nikehyperfuselow-2012.com/ Nike Hyperfuse Low

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closed:duplicate type:enhancement enhance or introduce a new feature
Projects
None yet
Development

No branches or pull requests

1 participant