Skip to content

Commit

Permalink
Fix _is_dev_install by using importlib.metadata API
Browse files Browse the repository at this point in the history
Instead of checking the presence of files in the filesystem, use the
importlib.metadata API to check if the installation is in editable mode.
  • Loading branch information
diegorusso committed Nov 26, 2024
1 parent a7585a1 commit 124482b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions pyperformance/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
import os.path
import sys
from importlib.metadata import distribution


VERSION = (1, 11, 0)
Expand Down Expand Up @@ -33,14 +35,8 @@ def _is_devel_install():
# pip install -e <path-to-git-checkout> will do a "devel" install.
# This means it creates a link back to the checkout instead
# of copying the files.
try:
import packaging
except ModuleNotFoundError:
return False
sitepackages = os.path.dirname(os.path.dirname(packaging.__file__))
if os.path.isdir(os.path.join(sitepackages, 'pyperformance')):
return False
if not os.path.exists(os.path.join(sitepackages, 'pyperformance.egg-link')):
# XXX Check the contents?
return False
return True

direct_url = distribution("pyperformance").read_text("direct_url.json")
if direct_url:
return json.loads(direct_url).get("dir_info", {}).get("editable", False)
return False

0 comments on commit 124482b

Please sign in to comment.