| 1 |
# |
| 2 |
# This file is part of the PyMeasure package. |
| 3 |
# |
| 4 |
# Copyright (c) 2013-2024 PyMeasure Developers |
| 5 |
# |
| 6 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
# of this software and associated documentation files (the "Software"), to deal |
| 8 |
# in the Software without restriction, including without limitation the rights |
| 9 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 |
# copies of the Software, and to permit persons to whom the Software is |
| 11 |
# furnished to do so, subject to the following conditions: |
| 12 |
# |
| 13 |
# The above copyright notice and this permission notice shall be included in |
| 14 |
# all copies or substantial portions of the Software. |
| 15 |
# |
| 16 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 |
# THE SOFTWARE. |
| 23 |
# |
| 24 |
import warnings |
| 25 |
|
| 26 |
# Maximally flexible approach to obtain version numbers, based on this approach: |
| 27 |
# https://github.com/pypa/setuptools_scm/issues/143#issuecomment-672878863 |
| 28 |
# Sadly, this does not work with editable installs, which bake in version info on installation. |
| 29 |
# see also https://github.com/pyusb/pyusb/pull/307#issuecomment-650797688 |
| 30 |
try: |
| 31 |
# If a user has setuptools_scm installed, assume they want the most up to date version string. |
| 32 |
# Alternatively, we could use a dummy dev module that is never packaged whose presence signals |
| 33 |
# that we are in an editable install/repo, see https://github.com/pycalphad/pycalphad/pull/341 |
| 34 |
import setuptools_scm |
| 35 |
__version__ = setuptools_scm.get_version(root='..', relative_to=__file__) |
| 36 |
del setuptools_scm |
| 37 |
except (ImportError, LookupError): |
| 38 |
# Setuptools_scm was not found, or it could not find a version, so use installation metadata. |
| 39 |
from importlib.metadata import version, PackageNotFoundError |
| 40 |
|
| 41 |
try: |
| 42 |
__version__ = version("pymeasure") |
| 43 |
# Alternatively, if the current approach is too slow, we could add |
| 44 |
# 'write_to = "pymeasure/_version.py"' in pyproject.toml and use the generated file here: |
| 45 |
# from ._version import version as __version__ |
| 46 |
except PackageNotFoundError: |
| 47 |
warnings.warn('Could not find pymeasure version, it does not seem to be installed. ' |
| 48 |
'Either install it (editable or full) or install setuptools_scm') |
| 49 |
__version__ = '0.0.0' |
| 50 |
finally: |
| 51 |
del version, PackageNotFoundError |