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

RFC: Cache filename #156

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/hawkmoth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ class _AutoSymbolDirective(_AutoBaseDirective):
def _get_filenames(self):
filename = self.options.get('file')

# Cache filename across directives in rst document
if filename:
self.env.temp_data['hawkmoth_current_file'] = filename
else:
filename = self.env.temp_data.get('hawkmoth_current_file')
Copy link
Collaborator

@BrunoMSantos BrunoMSantos May 28, 2023

Choose a reason for hiding this comment

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

Right, so having looked into this I stand by my comment in #157: I don't like the idea of stateful directives too much. But I've also reconsidered things a bit, even if I would still personally vote this particular implementation down in favour of having a specialized directive to select a file.

Not only that would be much more explicit, we could later combine it with full lookup / cache as a way of speeding things up by limiting the search to a (set of) directory --- i.e.: .. autoresolve:: some/dir. And in that case, adding the new directive with support for a single file only could be done without implying future breaking API changes.

Thoughts?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Right, so having looked into this I stand by my comment in #157: I don't like the idea of stateful directives too much. But I've also reconsidered things a bit, even if I would still personally vote this particular implementation down in favour of having a specialized directive to select a file.

Agreed. If there are going to be stateful directives, they should be explicit rather than implicit like this.


# Note: For the time being the file option is mandatory (sic).
if not filename:
self.logger.warning(':file: option missing.',
Expand Down