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

BUG: Fix serialization with Sphinx 7.3 #1289

Merged
merged 21 commits into from
Apr 24, 2024
Merged

Conversation

larsoner
Copy link
Contributor

Closes #1286

  1. Support fully qualified names of classes / callables
  2. Add aliases for our own ones like "FileNameSortKey" as an alias for "sphinx_gallery.sorting.FileNameSortKey"
  3. Keep sphinx_gallery_conf clean: don't store app in there or any functions
    1. Check for existence when filling the conf
    2. Load them on the fly when they need to be used
  4. Add to release notes

Kind of a pain to figure out but ultimately it does seem cleaner!

@larsoner larsoner added the bug label Apr 18, 2024
@larsoner
Copy link
Contributor Author

@maxnoe can you see if the documented changes here make sense to you?

@larsoner
Copy link
Contributor Author

@lucyleeow ready for review/merge from my end

Copy link
Contributor

@lucyleeow lucyleeow left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this, does not look like it was a simple fix. Lots of nits that can be fixed later really.

.pre-commit-config.yaml Show resolved Hide resolved
CHANGES.rst Outdated Show resolved Hide resolved
dev-requirements.txt Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
doc/configuration.rst Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
sphinx_gallery/gen_rst.py Show resolved Hide resolved
@NirobNabil
Copy link

NirobNabil commented Apr 19, 2024

subsection_order field on the conf still requires a callable which is called directly in gen_gallery and thus generates the non pickleable warning. I also went through the tests of sphinx_gallery and couldn't find any testcase covering the subsection_order field making sure having a callable in this field doesn't mess up anything.

while working on the same issue at matplotlib i made some changes in gen_gallery and gen_rst to handle the issue with subsection_order and it seemed to build without any issue.

  • changed line 447 in gen_gallery to

    sortkey = _get_class(gallery_conf, "subsection_order")
  • and changed the _get_class function in gen_rst at line 1503 to

    if not inspect.isclass(val) and not hasattr(val, '__class__'):
            raise ConfigError(
                f"{what} must be 1) a fully qualified name (string) that resolves "
                f"to a class or 2) or a class itself 3) or an instance of a class,"
                f" got {val.__class__.__name__} ({repr(val)})"
            )

    so that it passes with both a class definition or an instance of a class

@larsoner
Copy link
Contributor Author

I'll probably try modifying it just to use _get_callables instead so that a callable needs to be passed rather than a class

@larsoner larsoner changed the title BUG: Fix serialization with Sphinx 7.2.3 BUG: Fix serialization with Sphinx 7.3 Apr 19, 2024
@larsoner
Copy link
Contributor Author

Pushed a commit, feel free to give it a try / another look @NirobNabil @lucyleeow !

CHANGES.rst Outdated Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved


def _get_callables(gallery_conf, key):
# the following should be the case (internal use only)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what this means.

Maybe we could add a docstring one liner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it refers to the following assert line which should always pass because we've ensured it elsewhere

sphinx_gallery/gen_rst.py Show resolved Hide resolved
sphinx_gallery/gen_rst.py Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
CHANGES.rst Outdated Show resolved Hide resolved
CHANGES.rst Outdated Show resolved Hide resolved
CHANGES.rst Outdated Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
larsoner and others added 3 commits April 22, 2024 09:26
Co-authored-by: Lucy Liu <jliu176@gmail.com>
Co-authored-by: Lucy Liu <jliu176@gmail.com>
@larsoner
Copy link
Contributor Author

Okay docs hopefully fixed. Realized there were a few to fix in advanced.rst as well!

@NirobNabil
Copy link

Been waiting for this PR to go into a release so that the fix at matplotlib can be merged. Any idea when the next release window of sphinx-gallery might be?

@lucyleeow
Copy link
Contributor

lucyleeow commented Apr 23, 2024

We'll release after this PR goes in.

Edit: 🤦 wait I better investigate CI failures (#1291 (review)) first nevermind, this PR fixes them

Copy link
Contributor

@lucyleeow lucyleeow left a comment

Choose a reason for hiding this comment

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

Haven't looked deeply in the tests but should we parametrize some to test config value being str and callable (since we still want to support callable atm). Can be done in separate PR. I guess we would eventually remove callable support if Sphinx moves to toml conf file.

Thanks for fixing this, not an easy one.

CHANGES.rst Outdated Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
sphinx_gallery/gen_rst.py Outdated Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
doc/configuration.rst Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
doc/configuration.rst Outdated Show resolved Hide resolved
doc/advanced.rst Outdated Show resolved Hide resolved
doc/advanced.rst Show resolved Hide resolved
@larsoner
Copy link
Contributor Author

@lucyleeow are you up for pushing directly? I think it will be faster

@lucyleeow
Copy link
Contributor

lucyleeow commented Apr 24, 2024

Can be done in separate PR but what do you think about just updating the gallery_conf value in _get_callables, so we don't have to do it twice (call _get_callables twice)?

@lucyleeow
Copy link
Contributor

@lucyleeow are you up for pushing directly? I think it will be faster

Done, only changed docs.

@larsoner
Copy link
Contributor Author

what do you think about just updating the gallery_conf value in _get_callables, so we don't have to do it twice (call _get_callables twice

I wish we could but the env (including gallery conf) is cached after SG runs so it would cause the same serializing problems

@lucyleeow
Copy link
Contributor

Ah I didn't realise that. Can't see a way around that. Feel free to merge!

@lucyleeow
Copy link
Contributor

Ah I forgot about the tests, I can update in a separate PR.

@larsoner
Copy link
Contributor Author

Yeah let's get this in and I can start testing with MNE-Python for example. Then maybe release Friday?

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

Successfully merging this pull request may close these issues.

Allow configuration of sort orders in a way that does not mess with the sphinx cache
5 participants