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

Privacy plugin no longer works with extra_javascript configured #5772

Closed
4 tasks done
jonaharagon opened this issue Jul 28, 2023 · 13 comments
Closed
4 tasks done

Privacy plugin no longer works with extra_javascript configured #5772

jonaharagon opened this issue Jul 28, 2023 · 13 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@jonaharagon
Copy link

Context

When I upgrade mkdocs-material and my site dependencies from 9.1.18+insiders.4.37.0 to the current commit, my site can no longer be built.

Bug description

The build fails when extra_javascript is configured in mkdocs.yml and the privacy plugin is enabled.

INFO    -  DeprecationWarning: pkg_resources is deprecated as an API
             File "/Users/jonah/GitHub/mkdocs-testing/venv/lib/python3.11/site-packages/material/plugins/info/plugin.py", line 33, in <module>
               from pkg_resources import get_distribution, working_set
             File "/Users/jonah/GitHub/mkdocs-testing/venv/lib/python3.11/site-packages/pkg_resources/__init__.py", line 121, in <module>
               warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: /Users/jonah/GitHub/mkdocs-testing/site
Traceback (most recent call last):
  File "/Users/jonah/GitHub/mkdocs-testing/venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/Users/jonah/GitHub/mkdocs-testing/venv/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jonah/GitHub/mkdocs-testing/venv/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/jonah/GitHub/mkdocs-testing/venv/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jonah/GitHub/mkdocs-testing/venv/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jonah/GitHub/mkdocs-testing/venv/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jonah/GitHub/mkdocs-testing/venv/lib/python3.11/site-packages/mkdocs/__main__.py", line 286, in build_command
    build.build(cfg, dirty=not clean)
  File "/Users/jonah/GitHub/mkdocs-testing/venv/lib/python3.11/site-packages/mkdocs/commands/build.py", line 304, in build
    files = config.plugins.on_files(files, config=config)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jonah/GitHub/mkdocs-testing/venv/lib/python3.11/site-packages/mkdocs/plugins.py", line 533, in on_files
    return self.run_event('files', files, config=config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jonah/GitHub/mkdocs-testing/venv/lib/python3.11/site-packages/mkdocs/plugins.py", line 507, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jonah/GitHub/mkdocs-testing/venv/lib/python3.11/site-packages/material/plugins/privacy/plugin.py", line 110, in on_files
    url = urlparse(path)
          ^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/parse.py", line 394, in urlparse
    url, scheme, _coerce_result = _coerce_args(url, scheme)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/parse.py", line 133, in _coerce_args
    return _decode_args(args) + (_encode_result,)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/parse.py", line 117, in _decode_args
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/urllib/parse.py", line 117, in <genexpr>
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
                 ^^^^^^^^
AttributeError: 'ExtraScriptValue' object has no attribute 'decode'

Related links

Reproduction

example.zip

Also, I had to set plugins.info.archive_stop_on_violation: false, otherwise it would say Please update from 9.1.20+insiders.4.37.0 to 9.2.0b2. even though 9.2.0b2 is not available on the insiders repo. Bonus bug? This reproduction ZIP is built with the latest (https://github.com/squidfunk/mkdocs-material-insiders/commit/d2033e5aee7d006f15b5d872834875f221bc6d23) commit though.

Steps to reproduce

  1. Enable the privacy plugin
  2. Add a JS file to extra_javascript in mkdocs.yml

Browser

No response

Before submitting

@discdiver
Copy link

Thank you for the report and solution! Affected by the same bug.

@squidfunk
Copy link
Owner

Thanks for reporting. Definitely related to the recent release of MkDocs 1.5.0 which changed internal APIs. We'll upgrade Insiders to MkDocs 1.5.0 and issue a new release later this day. In the meantime, to mitigate, pin MkDocs to 1.4:

pip install mkdocs==1.4

@squidfunk squidfunk added the bug Issue reports a bug label Jul 28, 2023
@squidfunk
Copy link
Owner

Also, I had to set plugins.info.archive_stop_on_violation: false, otherwise it would say Please update from 9.1.20+insiders.4.37.0 to 9.2.0b2. even though 9.2.0b2 is not available on the insiders repo. Bonus bug? This reproduction ZIP is built with the latest (https://github.com/squidfunk/mkdocs-material-insiders/commit/d2033e5aee7d006f15b5d872834875f221bc6d23) commit though.

Yes, that's still kind of an oddity if versions between Insiders and community edition are not the same. You can open an issue for that as well, so we don't forget it.

@squidfunk
Copy link
Owner

The problem has been resolved in MkDocs 1.5.1 which now allows to use config.extra_javascript as before. Additionally, I've resolved another deprecation warning in the social plugin in squidfunk/mkdocs-material-insiders@a71a438a2ca2e073e998d9736db6e120aebcfa9f and updated the dependency to 1.5.1 in squidfunk/mkdocs-material-insiders@64dbfd2a8.

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Jul 28, 2023
@squidfunk
Copy link
Owner

Released as part of 9.1.21+insiders-4.37.1.

@jonaharagon
Copy link
Author

I'm unfortunately not seeing this fixed on my end. Attaching a reproduction if you want to double-check I installed the update correctly, but yeah the same reproduction build fails on 9.1.21+insiders.4.37.1.

example.zip

@squidfunk
Copy link
Owner

squidfunk commented Jul 28, 2023

Did you upgrade your dependencies after pulling the latest release? Make sure that MkDocs 1.5.1 is installed.

@discdiver
Copy link

discdiver commented Jul 28, 2023

Still failing for me, too. And I have the latest dependencies including mkdocs 1.5.1

1:57:02 PM: Requirement already satisfied: mkdocs>=1.5.1 in /opt/buildhome/python3.8/lib/python3.8/site-packages (from mkdocs-material==9.1.21+insiders.4.37.1)(1.5.1)

Traceback:

1:57:09 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/mike/mkdocs_plugin.py, line 6, in <module>
1:57:09 PM:     from pkg_resources import iter_entry_points
1:57:09 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/pkg_resources/__init__.py, line 118, in <module>
1:57:09 PM:     warnings.warn(
1:57:09 PM: INFO    -  DeprecationWarning: warning_filter doesn't do anything since MkDocs 1.2 and will be removed soon. All messages on the `mkdocs` logger get counted automatically.
  File /opt/buildhome/python3.8/lib/python3.8/site-packages/mkdocs_autorefs/plugin.py, line 23, in <module>
1:57:09 PM:     from mkdocs.utils import warning_filter
1:57:09 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/mkdocs/utils/__init__.py, line 453, in __getattr__
1:57:09 PM:     warnings.warn(
1:57:10 PM: INFO    -  Cleaning site directory
1:57:10 PM: INFO    -  Building documentation to directory: /opt/build/repo/site
1:57:10 PM: Traceback (most recent call last):
1:57:10 PM:   File /opt/buildhome/python3.8/bin/mkdocs, line 8, in <module>
1:57:10 PM:     sys.exit(cli())
1:57:10 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/click/core.py, line 1157, in __call__
1:57:10 PM:     return self.main(*args, **kwargs)
1:57:10 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/click/core.py, line 1078, in main
1:57:10 PM:     rv = self.invoke(ctx)
1:57:10 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/click/core.py, line 1688, in invoke
1:57:10 PM:     return _process_result(sub_ctx.command.invoke(sub_ctx))
1:57:10 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/click/core.py, line 1434, in invoke
1:57:10 PM:     return ctx.invoke(self.callback, **ctx.params)
1:57:10 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/click/core.py, line 783, in invoke
1:57:10 PM:     return __callback(*args, **kwargs)
1:57:10 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/mkdocs/__main__.py, line 286, in build_command
1:57:10 PM:     build.build(cfg, dirty=not clean)
1:57:10 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/mkdocs/commands/build.py, line 304, in build
1:57:10 PM:     files = config.plugins.on_files(files, config=config)
1:57:10 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/mkdocs/plugins.py, line 533, in on_files
1:57:10 PM:     return self.run_event('files', files, config=config)
1:57:10 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/mkdocs/plugins.py, line 507, in run_event
1:57:10 PM:     result = method(item, **kwargs)
1:57:10 PM:   File /opt/buildhome/python3.8/lib/python3.8/site-packages/material/plugins/privacy/plugin.py, line 110, in on_files
1:57:10 PM:     url = urlparse(path)
1:57:10 PM:   File /usr/lib/python3.8/urllib/parse.py, line 383, in urlparse
1:57:10 PM:     url, scheme, _coerce_result = _coerce_args(url, scheme)
1:57:10 PM:   File /usr/lib/python3.8/urllib/parse.py, line 135, in _coerce_args
1:57:10 PM:     return _decode_args(args) + (_encode_result,)
1:57:10 PM:   File /usr/lib/python3.8/urllib/parse.py, line 119, in _decode_args
1:57:10 PM:     return tuple(x.decode(encoding, errors) if x else '' for x in args)
1:57:10 PM:   File /usr/lib/python3.8/urllib/parse.py, line 119, in <genexpr>
1:57:10 PM:     return tuple(x.decode(encoding, errors) if x else '' for x in args)
1:57:10 PM: AttributeError: 'ExtraScriptValue' object has no attribute 'decode'

@squidfunk
Copy link
Owner

squidfunk commented Jul 28, 2023

Okay, thanks. Does it reproduce for you with the example provided in the OP?

Edit: Ah wait, @jonaharagon already confirmed that.

@squidfunk squidfunk reopened this Jul 28, 2023
@squidfunk squidfunk added needs investigation Issue must be investigated by the maintainers and removed resolved Issue is resolved, yet unreleased if open needs investigation Issue must be investigated by the maintainers labels Jul 28, 2023
@squidfunk
Copy link
Owner

squidfunk commented Jul 29, 2023

Fixed in 58b7dba42, and verified with the provided example. Could you both check the master of Insiders to verify whether your installations/actions now work again? The changes in MkDocs are quite fundamental, so it could be that there are more third-party plugins that will now break due to the changed internal API. For us, only the privacy plugin makes use of extra_javascript, so we should be done here. If you can confirm that it works, I'll issue a new release.

@squidfunk squidfunk added the resolved Issue is resolved, yet unreleased if open label Jul 29, 2023
@discdiver
Copy link

Yep, I can confirm that works for me. Thank you!

@squidfunk
Copy link
Owner

Perfect, thanks for confirming! Released as part of 9.1.21+insiders-4.38.0.

@jonaharagon
Copy link
Author

Working for me as well 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

3 participants