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

[fix] Failed to start Jedi EPC server / DeprecationWarning: pkg_resources #371

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions jediepcserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@
"""

import argparse
import glob
import itertools
import logging
import logging.handlers
import os
import re
import site
import sys
import pkg_resources
from collections import namedtuple
import packaging.version

import jedi
import jedi.api
Expand Down Expand Up @@ -127,8 +124,8 @@ def jedi_create_environment(venv, safe=False):
return jedienv

jedi_script_wrapper = jedi.Script
JEDI_VERSION = pkg_resources.parse_version(jedi.__version__)
if JEDI_VERSION < pkg_resources.parse_version('0.16.0'):
JEDI_VERSION = packaging.version.parse(jedi.__version__)
if JEDI_VERSION < packaging.version.parse('0.16.0'):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you use packaging here and importlib below? packaging is an external package so if it's added here it will need to be added as a dependency in setup.py

Copy link
Author

Choose a reason for hiding this comment

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

Why do you use packaging here and importlib below?

deprecated pkg_resources includes methods for semantic versioning and module handling. Use of pkg_resources is deprecated in favor of importlib .. .. but the problem is that importlib does not have methods for semantic versioning .. as we want to do a comparison of semantic versions here, we have to use packaging.

packaging is an external package so if it's added here it will need to be added as a dependency in setup.py

Thanks for pointing out, I added it --> https://github.com/tkf/emacs-jedi/compare/eb6d5a8fa5af5d07d14acd3cc05772c6edde50e0..6c36a91cd0cec35d1714929d4e74aff2b23b9367

class JediScriptCompatWrapper:
def __init__(self, code, path, **kwargs):
self.source = code
Expand Down Expand Up @@ -382,19 +379,18 @@ def get_names_recursively(definition, parent=None):


def get_module_version(module):
notfound = object()
for key in ['__version__', 'version']:
version = getattr(module, key, notfound)
if version is not notfound:
return version
try:
from pkg_resources import get_distribution, DistributionNotFound
from importlib.metadata import version, PackageNotFoundError
try:
return get_distribution(module.__name__).version
except DistributionNotFound:
return version(module.__name__)
except PackageNotFoundError:
pass
except ImportError:
pass
notfound = object()
for key in ['__version__', 'version']:
version = getattr(module, key, notfound)
if version is not notfound:
return version


def path_expand_vars_and_user(p):
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"epc>=0.0.4",
"argparse",
"setuptools",
"packaging",
],
entry_points={
'console_scripts': ['jediepcserver = jediepcserver:main'],
Expand Down