Skip to content

asset_files is a class attribute #6

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

Open
thdhondt opened this issue Oct 29, 2024 · 4 comments · May be fixed by #7
Open

asset_files is a class attribute #6

thdhondt opened this issue Oct 29, 2024 · 4 comments · May be fixed by #7

Comments

@thdhondt
Copy link

Hello Jonas,

Currently, asset_files is defined as a class attribute:

class ExcludeUnusedFilesPlugin(BasePlugin[ExcludeUnusedFilesPluginConfig]):
    asset_files: Set[str] = set()

I'm currently working on a use case where I need to build several mkdocs websites consecutively from a script.
Each website uses your plugin to get rid of unused files.

Since asset_files is a class attribute, its value is common for all instances of the ExcludeUnusedFilesPlugin.
In practice, this means that the Set is not reset in between two consecutive builds.
So, the next build complains because it tries to delete files that were already deleted during the previous build.

Do you think it would be possible to make asset_files an instance attribute instead?
According to the mkdocs documentation, the right place to instantiate this variable would be the on_config callback or __init__ method: https://www.mkdocs.org/dev-guide/plugins/#on_startup

Note that for initializing variables, the init method is still preferred. For initializing per-build variables (and whenever in doubt), use the on_config event.

Following this advise, I think some of the stuff that is currently in on_startup might be better suited for on_config.

Thanks for your help

Thomas

@thdhondt
Copy link
Author

thdhondt commented Nov 6, 2024

Would you be open to a PR that fixes this issue?

@JonasDoesThings
Copy link
Owner

Hey, thanks for poking me again and sorry for not responding earlier - the issue was buried in my todo-stack.
Sounds like a good improvement and yeah, I would definitely be open to changing that @thdhondt

If you would write a PR yourself that would be wonderful, else I could look into it and code it myself sometime next week, just let me know

Greetings from Austria :)

@thdhondt
Copy link
Author

thdhondt commented Nov 6, 2024

Sure, I will propose something later this week :).

@thdhondt thdhondt linked a pull request May 19, 2025 that will close this issue
@thdhondt
Copy link
Author

So, it took a bit more than a week 😁 ... But I finally made the changes.

I had to remove a line in the pyproject.toml to get the plugin to install itself and the tests to pass.
Otherwise, I was receiving the following errors:

ERROR: Exception:
Traceback (most recent call last):
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 106, in _run_wrapper
    status = _inner_run()
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_internal/cli/base_command.py", line 97, in _inner_run
    return self.run(options, args)
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_internal/cli/req_command.py", line 67, in wrapper
    return func(self, options, args)
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_internal/commands/install.py", line 458, in run
    installed = install_given_reqs(
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_internal/req/__init__.py", line 70, in install_given_reqs
    requirement.install(
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_internal/req/req_install.py", line 867, in install
    install_wheel(
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_internal/operations/install/wheel.py", line 732, in install_wheel
    _install_wheel(
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_internal/operations/install/wheel.py", line 556, in _install_wheel
    console, gui = get_entrypoints(distribution)
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_internal/operations/install/wheel.py", line 121, in get_entrypoints
    for entry_point in dist.iter_entry_points():
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_internal/metadata/pkg_resources.py", line 214, in iter_entry_points
    for group, entries in self._dist.get_entry_map().items():
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 3190, in get_entry_map
    self._ep_map = EntryPoint.parse_map(
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2852, in parse_map
    maps[group] = cls.parse_group(group, lines, dist)
  File "/data/home/thomas.dhondt/thomas.dhondt/dev/mkdocs-exclude-unused-files/.venv/lib/python3.9/site-packages/pip/_vendor/pkg_resources/__init__.py", line 2822, in parse_group
    raise ValueError("Invalid group name", group)
ValueError: ('Invalid group name', 'poetry-plugin-up')

I am using poetry v1.8.4. While investigating this issue, I realized that there are quite some changes in the pyproject.toml file if you want to pass to Poetry v2.0.0. I have decided not to implement those changes in this MR.

Feel free to provide feedback on this topic.

@thdhondt thdhondt reopened this May 20, 2025
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