Skip to content

Commit

Permalink
Improve getting version when installing from git archive
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpre committed Dec 1, 2023
1 parent add7440 commit d06ef3a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: get repository name
shell: bash
run: echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV

- name: Fetch tags upstream
if: ${{ github.repository_owner != 'hyperspy' }}
# Needs to fetch the tags from upstream to get the
# correct version with setuptools_scm
run: |
git remote add upstream https://github.com/hyperspy/${{ env.REPOSITORY_NAME }}.git
git fetch upstream --tags
- uses: actions/setup-python@v4
name: Install Python
Expand All @@ -37,7 +51,6 @@ jobs:
pip --version
- name: Install
shell: bash
run: |
pip install -e .[tests]
Expand Down
48 changes: 40 additions & 8 deletions exspy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2007-2023 The exSpy developers
#
# This file is part of exSpy.
#
# exSpy is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# exSpy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with exSpy. If not, see <https://www.gnu.org/licenses/#GPL>.

from importlib.metadata import version
from pathlib import Path

from . import components
Expand All @@ -8,16 +27,29 @@
from ._defaults_parser import preferences


if Path(__file__).parent.parent.name == "site-packages": # pragma: no cover
# Tested in the "build" workflow on GitHub CI
from importlib.metadata import version
__version__ = version("exspy")

# For development version, `setuptools_scm` will be used at build time
# to get the dev version, in case of missing vcs information (git archive,
# shallow repository), 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

__version__ = version("rosettasciio")
else:
# Editable install
from setuptools_scm import get_version
# 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(Path(__file__).parent.parent)
__version__ = get_version(_root)
except ImportError: # pragma: no cover
# setuptools_scm not install, we keep the existing __version__
pass


__all__ = [
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,5 @@ include = ["exspy*"]

[tool.setuptools_scm]
# Presence enables setuptools_scm, the version will be determine at build time from git
# The version will be updated by the `prepare_release.py` script
fallback_version = "0.1.dev0"
6 changes: 4 additions & 2 deletions releasing_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ To publish a new exSpy release do the following steps:

## Preparation

- Create a new PR to the 'main' branch for the release process, e.g. `release_v0.1.1`
- Make sure to have the code ready, including changelog
- Create a new PR to the 'main' branch for the release process, e.g. `release_v0.1.1` with
the following changes:
- Update and check release notes
- Update dev `fallback_version` in `pyproject.toml`
- Let that PR collect comments for a day to ensure that other maintainers are comfortable
with releasing
- Set correct date and version number in `CHANGES.rst`
Expand Down

0 comments on commit d06ef3a

Please sign in to comment.