Skip to content

Commit

Permalink
Use importlib instead of pkg_resources
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantam626 committed Apr 16, 2023
1 parent 8d007f1 commit f5ac6ce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
16 changes: 3 additions & 13 deletions jupyterlab_code_formatter/handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

import pkg_resources
from importlib.metadata import version
from jupyter_server.base.handlers import APIHandler
from jupyter_server.serverapp import ServerWebApplication
from jupyter_server.utils import url_path_join
Expand Down Expand Up @@ -48,9 +48,7 @@ def setup_handlers(web_app: ServerWebApplication) -> None:


def check_plugin_version(handler: APIHandler):
server_extension_version = pkg_resources.get_distribution(
"jupyterlab_code_formatter"
).version
server_extension_version = version("jupyterlab_code_formatter")
lab_extension_version = handler.request.headers.get("Plugin-Version")
version_matches = server_extension_version == lab_extension_version
if not version_matches:
Expand Down Expand Up @@ -125,12 +123,4 @@ def post(self) -> None:
class VersionAPIHandler(APIHandler):
def get(self) -> None:
"""Show what version is this server plugin on."""
self.finish(
json.dumps(
{
"version": pkg_resources.get_distribution(
"jupyterlab_code_formatter"
).version
}
)
)
self.finish(json.dumps({"version": version("jupyterlab_code_formatter")}))
5 changes: 3 additions & 2 deletions jupyterlab_code_formatter/tests/test_handlers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import json
import typing as t

import pkg_resources

import pytest
from importlib.metadata import version
from jsonschema import validate
from tornado.httpclient import HTTPResponse

Expand Down Expand Up @@ -79,7 +80,7 @@ def _create_headers(plugin_version: t.Optional[str] = None) -> t.Dict[str, str]:
return {
"Plugin-Version": plugin_version
if plugin_version is not None
else pkg_resources.get_distribution("jupyterlab_code_formatter").version
else version("jupyterlab_code_formatter")
}


Expand Down

0 comments on commit f5ac6ce

Please sign in to comment.