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

Url handler order different dependent on whether config is by traitlets vs entry_points #326

Open
metafeather opened this issue Feb 18, 2022 · 3 comments
Labels

Comments

@metafeather
Copy link

Docs: https://jupyter-server-proxy.readthedocs.io/en/latest/server-process.html#specifying-config-via-traitlets

When using traitlets (in a jupyter_lab_config.py file) the declared order of the urls to proxy is used when being turned in to url handlers inside the Tornado server 1.

But when using entry_points (in a python package) pkg_resources.iter_entry_points('jupyter_serverproxy_servers') is used to get the list of paths to proxy and this is sorted alphabetically by setuptools first 2.

This means that url handlers can mask each other and be unreachable, e.g. if the order declared is:

  • a/b/some/path/
  • a/b/

with entry_points the order returned will be:

  • a/b/
  • a/b/some/path/

and so the proxy to a/b/some/path/ cannot be reached.

As the list of entry_points is global to all installed packages this can be hard to track down.

A quick fix for this would be to reverse the results of pkg_resources.iter_entry_points('jupyter_serverproxy_servers') before using them, as these would be in an appropriate order for url routing.

In my particular case I wanted to proxy to my wiki server under my application root so that links from the app worked as expected, and was forced to use traitlets, with my users copy and pasting configs rather than being able to install a module.

@welcome
Copy link

welcome bot commented Feb 18, 2022

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@metafeather
Copy link
Author

Somewhat related, but not so well documented is that you can declare multiple entry_points in a setup.py to aid code reuse, e.g.

entry_points={
        "jupyter_serverproxy_servers": [
            # name = packagename:function_name
            "research/wiki = wiki_server_proxies:setup_research_wiki_service",
            "research = wiki_server_proxies:setup_research_docs_service",
            "platform/wiki = wiki_server_proxies:setup_platform_wiki_service",
            "platform= wiki_server_proxies:setup_platform_docs_service",
        ]
    }

However these still get sorted globally.

@takluyver
Copy link
Member

Does importlib.metadata give you the names in the order you specified them?

from importlib.metadata import entry_points
entry_points(group='jupyter_serverproxy_servers')

This is the modern replacement for pkg_resources, so if it fixes this problem, it should be easy for JSP to switch over.

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

No branches or pull requests

2 participants