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

Update version detection #3364

Merged
merged 1 commit into from
Feb 21, 2024
Merged
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
35 changes: 24 additions & 11 deletions src/metpy/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,29 @@
"""Get MetPy's version.

Either get it from package metadata, or get it using version control information if
a development install.
an editable installation.
"""
from importlib.metadata import distribution, PackageNotFoundError

try:
from setuptools_scm import get_version
return get_version(root='../..', relative_to=__file__,
version_scheme='post-release')
except (ImportError, LookupError):
from importlib.metadata import PackageNotFoundError, version

try:
return version(__package__)
except PackageNotFoundError:
return 'Unknown'
dist = distribution(__package__)

# First see if we can find this file from pip to check for an editable install
if direct := dist.read_text('direct_url.json'):
import json

# Parse file and look for editable key
info = json.loads(direct)
if info.get('dir_info', {}).get('editable'):
import contextlib

Check warning on line 25 in src/metpy/_version.py

View check run for this annotation

Codecov / codecov/patch

src/metpy/_version.py#L25

Added line #L25 was not covered by tests

# If editable try to get version using setuptools_scm
with contextlib.suppress(ImportError, LookupError):
from setuptools_scm import get_version
return get_version(root='../..', relative_to=__file__,

Check warning on line 30 in src/metpy/_version.py

View check run for this annotation

Codecov / codecov/patch

src/metpy/_version.py#L28-L30

Added lines #L28 - L30 were not covered by tests
version_scheme='post-release')

# With any error or not an editable install, we use the version from the metadata
return dist.version
except PackageNotFoundError:
return 'Unknown'

Check warning on line 36 in src/metpy/_version.py

View check run for this annotation

Codecov / codecov/patch

src/metpy/_version.py#L35-L36

Added lines #L35 - L36 were not covered by tests