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

Intersphinx: log warnings for ambiguous target resolutions. #12329

Conversation

jayaddison
Copy link
Contributor

Feature or Bugfix

  • Refactoring

Purpose

Detail

Relates

cc @goerz from the initial discussion in #12009, and @picnixz as reviewer of the approved replacement pull request #12033.

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heya thanks, I would suggest though that the warning requires extra metadata, including a type/subtype and a source/origin location

It would also be good to fully check the warnings in the test.

Perhaps have a look at #12193, where I did something similar

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops that was meant to be request change

@goerz
Copy link
Contributor

goerz commented Apr 26, 2024

Not much to add: the warning seems useful.

Marginally related: why can I no longer comment on #12009? That PR was superseded by #12033 and is no longer relevant. It doesn't need an "awaiting:response" tag. There's nothing open to respond to.

@jayaddison
Copy link
Contributor Author

@goerz can you confirm that the absence of the messaging logic that we discussed in the original pull-request from your follow-up changeset was not an attempt to check whether it's possible to bypass our review processes?

I feel that some institutions do spend time attempting such things (such as a case involving the University of Minnesota and the Linux kernel, for example) -- and to some extent I can understand that confirming and reporting those possibilities can provide research data. However, generally I feel like that time would be better spent assisting projects rather than confirming that human error can occur.

@goerz
Copy link
Contributor

goerz commented Apr 26, 2024

Are you asking whether I deliberately not implemented the warning messages as a form of pentesting? Definitely not. I can confirm that I wasn't trying to poke holes in your review process as some kind of research activity.

I forget what my exact reasoning was for why I didn't feel it necessary to include log messages in the second PR. Probably that it ended up being a trivial extension of code that had been there for years, and that it wasn't really my responsibility to add extra bikeshedding to that existing code (in particular because messaging with localization isn't completely trivial). And maybe even more importantly: None of the two systems that I'm aware of that can write objects.inv files (Sphinx iteself and Documenter.jl) have the possibility to generate inventories with the kind of ambiguous targets being addressed in the PR. At least not ambiguous in Sphinx, given Sphinxes reference syntax. What could happen is that Sphinx generates an inventory that's ambiguous for use within Documenter.jl, but that's an issue for Documenter.jl to address.

Frankly, Sphinx is much too big and contributions to it are too bureaucratized (as a consequence, I'm not pointing fingers at anyone), and thus I would like to limit my development interactions with it to the smallest amount possible. In this case, there was a bug that made interoperability with Julia's documentation generator impossible, and that was something that I felt really needed fixing (and is now fixed), thanks to the latest release. Implementing error handling for errors that cannot currently occur is just not something I have the capacity for.

But of course, I have no objection if someone else wants to add more error logging to the inventory resolution, so I fully support this PR. But it really only addresses objects.inv files from a hypothetical future documentation generator, or specific hand-crafted files.

@jayaddison
Copy link
Contributor Author

Are you asking whether I deliberately not implemented the warning messages as a form of pentesting? Definitely not. I can confirm that I wasn't trying to poke holes in your review process as some kind of research activity.

Thank you! Yes; I didn't think it would be the case, but I did want some kind of logging for the ambiguous-resolution scenario. My sense was that we had agreed that, so it surprised me to later learn that the feature had been implemented without it.

I forget what my exact reasoning was for why I didn't feel it necessary to include log messages in the second PR. Probably that it ended up being a trivial extension of code that had been there for years, and that it wasn't really my responsibility to add extra bikeshedding to that existing code (in particular because messaging with localization isn't completely trivial). And maybe even more importantly: None of the two systems that I'm aware of that can write objects.inv files (Sphinx iteself and Documenter.jl) have the possibility to generate inventories with the kind of ambiguous targets being addressed in the PR. At least not ambiguous in Sphinx, given Sphinxes reference syntax. What could happen is that Sphinx generates an inventory that's ambiguous for use within Documenter.jl, but that's an issue for Documenter.jl to address.

Yep - the PR I'm suggesting here lacks localization so far, and I don't know whether it'll be acceptable without that. I'm not too familiar with the objects.inv-related tooling, but I do think that client software should be cautious about the input it accepts, and also that it's good to make it possible to report problems upstream when they're found.

Frankly, Sphinx is much too big and contributions to it are too bureaucratized (as a consequence, I'm not pointing fingers at anyone), and thus I would like to limit my development interactions with it to the smallest amount possible. In this case, there was a bug that made interoperability with Julia's documentation generator impossible, and that was something that I felt really needed fixing (and is now fixed), thanks to the latest release. Implementing error handling for errors that cannot currently occur is just not something I have the capacity for.

Indeed, I understand that it can feel like results are more likely to be accepted on a prompt timeline when changes are minimized; and also, yes, thank you for stepping in to fix a system compatibility problem - that is much appreciated.

But of course, I have no objection if someone else wants to add more error logging to the inventory resolution, so I fully support this PR. But it really only addresses objects.inv files from a hypothetical future documentation generator, or specific hand-crafted files.

👍

@AA-Turner AA-Turner changed the title Intersphinx lookups: log warning for ambiguous target resolution. Intersphinx lookups: log warning for ambiguous target resolution Apr 29, 2024
@AA-Turner AA-Turner dismissed chrisjsewell’s stale review April 29, 2024 01:58

sub-type and location information has been added to the warning

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly all good cheers, just a nitpick

sphinx/ext/intersphinx/_resolve.py Outdated Show resolved Hide resolved
jayaddison and others added 2 commits April 29, 2024 11:17
@chrisjsewell
Copy link
Member

@jayaddison I'm -1 on 72b266d; you've taken a simple PR and suddenly increased its complexity 10-fold, for minimal gain 😅

@chrisjsewell
Copy link
Member

If you want to include inv_name in the message, sure, but the path to the objects.inv is overkill, and really an implementation detail that users should not be particularly concerned

@jayaddison
Copy link
Contributor Author

Yep, it does raise the complexity and that is unfortunate. However, if we discover ambiguous entries within an objects.inv file, then I think it's important to report the specific source of that at the time-of-detection; otherwise it could be more difficult than necessary for users to determine where it originated.

@chrisjsewell
Copy link
Member

I think it's important to report the specific source

Yes and reporting the inventory key inv_name is sufficient for this,
I don't think intersphinx_mapping[inv_name][1][0] is even handling it correctly, because this could just be None https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#confval-intersphinx_mapping

@jayaddison
Copy link
Contributor Author

I think it's important to report the specific source

Yes and reporting the inventory key inv_name is sufficient for this, I don't think intersphinx_mapping[inv_name][1][0] is even handling it correctly, because this could just be None https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#confval-intersphinx_mapping

Mostly agree, although I do worry about time spent trying to figure out what the inventory mapping config evaluated was at the time-of-build. I've added logging of the inv_name at load-time too, although that is at info-level (and so there's a possibility that only the warning would appear, under some circumstances).

@jayaddison
Copy link
Contributor Author

A thought: perhaps the warnings could/should be detected during the inventory loading process instead of at resolution-time?

@jayaddison jayaddison changed the title Intersphinx lookups: log warning for ambiguous target resolution Intersphinx lookups: log warnings for ambiguous target definitions and resolutions. Apr 29, 2024
@jayaddison
Copy link
Contributor Author

Ok; I've no further changes planned on this branch and will await further review.

The changeset has been expanded to emit warnings when ambiguous references are discovered during loading of an inventory file -- I believe that this is only relevant for V2 inventories -- in addition to the initial logic to detect ambiguous-resolution of targets.


@classmethod
def load_v1(
cls: type[InventoryFile],
stream: InventoryFileReader,
uri: str,
join: Callable[[str, str], str],
) -> Inventory:
) -> tuple[Inventory, set[str]]:
Copy link
Member

@chrisjsewell chrisjsewell May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change to public API which, without deprecation warnings, I think is not ideal.

either,

just log the warnings within load_v2 (this seems easiest)

or you should create two methods for each version, like: load_v2_with_ambiguties (new signature), load_v2 (calls load_v2_with_ambiguties, but then just drops the ambiguties and only returns the inventory)

@jayaddison jayaddison requested a review from chrisjsewell June 13, 2024 11:25
Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all good cheers

@chrisjsewell chrisjsewell changed the title Intersphinx lookups: log warnings for ambiguous target definitions and resolutions. Intersphinx: log warnings for ambiguous target resolutions. Jun 17, 2024
@chrisjsewell chrisjsewell merged commit 799ae16 into sphinx-doc:master Jun 17, 2024
23 checks passed
@jayaddison
Copy link
Contributor Author

Thank you @chrisjsewell!

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

Successfully merging this pull request may close these issues.

4 participants