Skip to content

Commit 008b5e3

Browse files
authored
Fix _is_dev_install by using importlib.metadata API (#371)
Instead of checking the presence of files in the filesystem, use the importlib.metadata API to check if the installation is in editable mode.
1 parent a7585a1 commit 008b5e3

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

pyperformance/__init__.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import json
12
import os.path
23
import sys
4+
from importlib.metadata import distribution
35

46

57
VERSION = (1, 11, 0)
@@ -33,14 +35,8 @@ def _is_devel_install():
3335
# pip install -e <path-to-git-checkout> will do a "devel" install.
3436
# This means it creates a link back to the checkout instead
3537
# of copying the files.
36-
try:
37-
import packaging
38-
except ModuleNotFoundError:
39-
return False
40-
sitepackages = os.path.dirname(os.path.dirname(packaging.__file__))
41-
if os.path.isdir(os.path.join(sitepackages, 'pyperformance')):
42-
return False
43-
if not os.path.exists(os.path.join(sitepackages, 'pyperformance.egg-link')):
44-
# XXX Check the contents?
45-
return False
46-
return True
38+
39+
direct_url = distribution("pyperformance").read_text("direct_url.json")
40+
if direct_url:
41+
return json.loads(direct_url).get("dir_info", {}).get("editable", False)
42+
return False

0 commit comments

Comments
 (0)