Skip to content

Commit

Permalink
Fix get version in various scenarios:
Browse files Browse the repository at this point in the history
- debian use `dist-packages` instead of `site-packages`
- dev version, opt in to use setuptools_scm when possible, for example for non shallow checkout
  • Loading branch information
ericpre committed Nov 25, 2023
1 parent a8a6eaa commit bc4c395
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/dist/*
/RosettaSciIO.egg-info/*
*__pycache__*
*test_compilers.o
*test_compilers.o*
*pyd
.spyproject/*
.idea
rsciio/bruker/unbcf_fast.c
rsciio/bruker/*.so
rsciio/bruker/*.pyd
rsciio/bruker/*.pyd
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ include = ["rsciio*"]

[tool.setuptools_scm]
# Presence enables setuptools_scm, the version will be determine at build time from git
fallback_version = "0.0+UNKNOWN"

[tool.towncrier]
package = "rsciio"
Expand Down
35 changes: 25 additions & 10 deletions rsciio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,39 @@
# You should have received a copy of the GNU General Public License
# along with RosettaSciIO. If not, see <https://www.gnu.org/licenses/#GPL>.

from importlib.metadata import version
import logging
import os
from pathlib import Path
import yaml


if Path(__file__).parent.parent.name == "site-packages": # pragma: no cover
# Tested in the "build" workflow on GitHub CI
from importlib.metadata import version
_logger = logging.getLogger(__name__)
IO_PLUGINS = []

__version__ = version("rosettasciio")
else:
# Editable install
from setuptools_scm import get_version
__version__ = version("rosettasciio")

__version__ = get_version(Path(__file__).parent.parent)
# For development version, `setuptools_scm` will be used at
# build time to get the dev version, in case of missing vcs information
# the fallback version defined in pyproject.toml will be used

# if we have a editable install from a git repository try to use
# `setuptools_scm` to find a more accurate version:
# `importlib.metadata` will provide the version at installation
# time and for editable version this may be different

# we only do that if we have enough git history, e.g. not shallow checkout
_root = Path(__file__).resolve().parents[1]
if (_root / ".git").exists() and not (_root / ".git/shallow").exists():
try:
# setuptools_scm may not be installed
from setuptools_scm import get_version

__version__ = get_version(_root)
except ImportError: # pragma: no cover
# setuptools_scm not install, we keep the existing __version__
pass

IO_PLUGINS = []
_logger = logging.getLogger(__name__)

for sub, _, _ in os.walk(os.path.abspath(os.path.dirname(__file__))):
_specsf = os.path.join(sub, "specifications.yaml")
Expand All @@ -45,6 +59,7 @@
_specs["api"] = "rsciio.%s" % os.path.split(sub)[1]
IO_PLUGINS.append(_specs)


__all__ = [
"__version__",
"IO_PLUGINS",
Expand Down

0 comments on commit bc4c395

Please sign in to comment.