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

Add support for pep 660 editable installs in extension #3252

Merged
merged 2 commits into from Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 17 additions & 3 deletions hyperspy/extensions.py
Expand Up @@ -19,6 +19,9 @@
import logging
import copy
import yaml
import json
from urllib.parse import urlparse
from urllib.request import url2pathname

from pathlib import Path
import importlib_metadata as metadata
Expand Down Expand Up @@ -46,9 +49,20 @@
_files = [file for file in _external_extension.dist.files
if "hyperspy_extension.yaml" in str(file)]

if _files:
_path = _files.pop()
with _path.locate().open() as stream:
if not _files: # pragma: no cover
# Editable installs for pyproject.toml based builds
# https://peps.python.org/pep-0610/#example-pip-commands-and-their-effect-on-direct-url-json
# https://peps.python.org/pep-0660/#frontend-requirements
_files = [file for file in _external_extension.dist.files
if "direct_url.json" in str(file)]
with _files[0].locate().open() as json_data:
_path = url2pathname(urlparse(json.load(json_data)['url']).path)
_path = Path(_path) / _external_extension.name / "hyperspy_extension.yaml"
else:
_path = _files.pop().locate()

if _path:
with open(str(_path)) as stream:
_external_extension = yaml.safe_load(stream)
if "signals" in _external_extension:
ALL_EXTENSIONS["signals"].update(_external_extension["signals"])
Expand Down
1 change: 1 addition & 0 deletions upcoming_changes/3252.enhancements.rst
@@ -0,0 +1 @@
Add support for pep 660 on editable installs for pyproject.toml based builds of extension