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

can't link function short name if it matches module name #243

Open
rdzman opened this issue Mar 7, 2024 · 4 comments · Fixed by #245
Open

can't link function short name if it matches module name #243

rdzman opened this issue Mar 7, 2024 · 4 comments · Fixed by #245

Comments

@rdzman
Copy link
Contributor

rdzman commented Mar 7, 2024

Given a module named foo and a function within that module, also named foo, with matlab_short_links = True, it is not possible to create a working link to the function. Both of the following result in a properly formatted, but not hyperlinked, name.

:func:`foo`
:func:`foo.foo`

With matlab_short_links = False both work just fine.

Note: The behavior of the first one depends on whether you have an .. automodule:: foo anywhere or not. If so, it links to the foo module, if not, to the foo.foo function.

I believe it should behave exactly the same way with matlab_short_links = True, right?

There is an additional issue with matlab_auto_link = "all" that prevents it from recognizing foo as a function in this context and wrapping it with the :func: role. (I think I have a fix for this part.)

Finally, while I haven't tested it, I suspect that a class with the same name as the module probably has the same problem.

@joeced
Copy link
Collaborator

joeced commented Mar 11, 2024

Thanks for the report. I'll try to look at it soon

joeced pushed a commit that referenced this issue May 7, 2024
* Fix "can't link function short name if it matches module name" #243.

* Fix issue with autolinking of functions or classes with same name as module.
@joeced joeced linked a pull request May 7, 2024 that will close this issue
@joeced
Copy link
Collaborator

joeced commented Jul 18, 2024

Short update. I finally had time to work on the project this weekend. Today I started looking into why the links don't work as we expect. The culprit is

def find_obj(self, env, modname, classname, name, type, searchmode=0):
which I have not touched at all. It looks like it was copied verbatim from the Python domain. I'll modify it to match how we want to find objects to link to :)

@joeced
Copy link
Collaborator

joeced commented Jul 18, 2024

I started working on this in a branch: https://github.com/sphinx-contrib/matlabdomain/tree/try-fix-auto-linking.

@rdzman do you have time to test this? I'll be away from a computer for 3 weeks in a few days, so it'll take a while before its out as a release.

@rdzman
Copy link
Contributor Author

rdzman commented Jul 18, 2024

@joeced, is it possible the issue at #246 is getting conflated with this one? From what I understand, the presenting issue here was "fixed", probably incorrectly by #245.

Unfortunately, I have very limited time for testing at the moment, but a quick try on some of my projects with the try-fix-auto-linking branch results in lots of new warnings, such as the following ...

/Users/ray/dev/projects/mp-opt-model/docs/sphinx/docstring of mp_opt_model.have_feature_fsolve:1: WARNING: [sphinxcontrib-matlabdomain] more than one target found for cross-reference 'fsolve': have_feature_fsolve, nleqs_fsolve
/Users/ray/dev/projects/mp-opt-model/docs/sphinx/docstring of mp_opt_model.have_feature_fsolve:3: WARNING: [sphinxcontrib-matlabdomain] more than one target found for cross-reference 'fsolve': have_feature_fsolve, nleqs_fsolve

or

/Users/ray/dev/projects/matpower/docs/sphinx/docstring of matpower.have_feature_most:6: WARNING: [sphinxcontrib-matlabdomain] more than one target found for cross-reference 'most': most.most, mpoption_info_most, t_case30_most, t_case3_most, test_most, have_feature_most

I haven't noticed any changes in links created relative to the above warnings.

However, I am seeing cases where there are functions that were not linked (I think due to #246), that are now being linked, but to the wrong target. E.g. :func:``mpoption`` being linked to a function named t_mpoption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants