numpydoc icon indicating copy to clipboard operation
numpydoc copied to clipboard

Add default linkcode_resolve logic

Open vnavkal opened this issue 6 years ago • 2 comments

Many libraries that use numpydoc also use the Sphinx linkcode feature. In order to use it, they all must define a linkcode_resolve function that returns the web URL where the code for a given Python object can be found.

These libraries mostly seem to be using slightly modified versions of the numpy one -- for example, here are the pandas version and the scikit-learn version. Consequently, an error in the original logic has propagated to these other libraries: decorated functions often generate incorrect links. See e.g. the source code links for numpy.isposinf and sklearn.pipeline.Pipeline.predict_log_proba.

I first noticed this bug in scikit-learn and reported it in https://github.com/scikit-learn/scikit-learn/issues/10542. @jnothman suggested that instead of fixing the bug in scikit-learn only, it might make sense to put a shared, default version of linkcode_resolve in numpydoc, so that changes propagate to other libraries that implement linkcode_resolve.

Does anyone have thoughts about whether

  1. it makes sense to consolidate this logic, and
  2. numpydoc is the right place to put it? (One possible alternative would be to put it in Sphinx.)

I might be able to help with this consolidation, as time permits 😄

vnavkal avatar Jan 28 '18 20:01 vnavkal

It might be best to develop a reusable piece of code and offer it here, so that we can see concretely what can/should be shared. The current implementations depend on the code being hosted at GitHub, on git being used for version control, a specified relationship between version numbers and git tags, source code directory structure, etc.

Yes, it seems like Sphinx could offer a helper for applying heuristics to determine likely source code lines...

jnothman avatar Jan 28 '18 21:01 jnothman

sounds good to me. I'll submit a pull request with some code that can be used to make custom linkcode_resolve functions.

vnavkal avatar Jan 30 '18 18:01 vnavkal