Skip to content

Commit 3d926c7

Browse files
authored
version: add get_version_info_v2() (#1231)
+ version: add `get_version_info_v2()` using `importlib.metadata` module, but it's not working yet, as described below, thus, not used yet. - 1st, the returned version is not correct: 1.5.1.post55, which should be 1.5.3.post2 - 2nd, the returned date is not correct: None, which should be 2023-12-05 + version: remove the unused `website` and `description` vars + docs/demo*: update relevant literature for the San Francisco Bay dataset using GMTSAR to Xu et al. (2021, JGR)
1 parent 457ac4e commit 3d926c7

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

docs/demo_dataset.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ smallbaselineApp.py ${MINTPY_HOME}/docs/templates/SanFranBaySenD42.txt
7474

7575
Relevant literature:
7676

77-
+ Chaussard, E., R. Bürgmann, H. Fattahi, R. M. Nadeau, T. Taira, C. W. Johnson, and I. Johanson (2015), Potential for larger earthquakes in the East San Francisco Bay Area due to the direct connection between the Hayward and Calaveras Faults, _Geophysical Research Letters,_ 42(8), 2734-2741, doi:10.1002/2015GL063575.
77+
+ Xu, X., Sandwell, D. T., Klein, E., & Bock, Y. (2021). Integrated Sentinel-1 InSAR and GNSS Time-Series Along the San Andreas Fault System. _Journal of Geophysical Research: Solid Earth, 126_(11), e2021JB022579, doi:10.1029/2021JB022579
7878

7979
### Envisat of the 2008 Wells, Nevada earthquake with Gamma ###
8080

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools>=64.0", "setuptools_scm[toml]"]
2+
requires = ["setuptools>=64.0", "setuptools_scm[toml]>=8"]
33
build-backend = "setuptools.build_meta"
44

55
[project]

src/mintpy/version.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
# grab version / date of the latest commit
2-
1+
############################################################
2+
# Program is part of MintPy #
3+
# Copyright (c) 2013, Zhang Yunjun, Heresh Fattahi #
4+
# Author: Zhang Yunjun, Mar 2018 #
5+
############################################################
6+
# Recommend import:
7+
# from mintpy.version import version, version_description, logo
38

49
import collections
510
import os
611
import subprocess
12+
from importlib.metadata import PackageNotFoundError, metadata
713

814
###########################################################################
915
Tag = collections.namedtuple('Tag', 'version date')
@@ -35,11 +41,9 @@
3541
Tag('0.2.0', '2016-07-14'),
3642
Tag('0.1.0', '2015-11-23'),
3743
)
38-
release_version = release_history[0].version
39-
release_date = release_history[0].date
4044

4145
def get_version_info():
42-
"""Grab version and date of the latest commit from a git repository"""
46+
"""Grab version and its date from a git repository."""
4347
# go to the repository directory
4448
dir_orig = os.getcwd()
4549
os.chdir(os.path.dirname(os.path.dirname(__file__)))
@@ -49,28 +53,42 @@ def get_version_info():
4953
cmd = "git describe --tags"
5054
version = subprocess.check_output(cmd.split(), stderr=subprocess.DEVNULL)
5155
version = version.decode('utf-8').strip()[1:]
52-
5356
# if there are new commits after the latest release
5457
if '-' in version:
5558
version, num_commit = version.split('-')[:2]
5659
version += f'.post{num_commit}'
57-
5860
cmd = "git log -1 --date=short --format=%cd"
59-
date = subprocess.check_output(cmd.split(), stderr=subprocess.DEVNULL)
60-
date = date.decode('utf-8').strip()
61-
61+
version_date = subprocess.check_output(cmd.split(), stderr=subprocess.DEVNULL)
62+
version_date = version_date.decode('utf-8').strip()
6263
except:
6364
# use the latest release version/date
64-
version = release_version
65-
date = release_date
65+
version = release_history[0].version
66+
version_date = release_history[0].date
6667

6768
# go back to the original directory
6869
os.chdir(dir_orig)
69-
return version, date
70+
return version, version_date
7071

7172

72-
###########################################################################
73+
def get_version_info_v2():
74+
"""Grab the version and its date from a git repository.
75+
Note by Yunjun on 5 Dec 2023: could not grab release/commit date info
76+
using importlib, thus, return None always.
77+
"""
78+
try:
79+
package_name = os.path.basename(os.path.dirname(__file__))
80+
package = metadata(package_name)
81+
version = package['Version']
82+
except PackageNotFoundError:
83+
print('package is not installed!\n'
84+
'Please follow the installation instructions in the README.md.\n'
85+
'Or, to just get the version number, use:\n'
86+
' python -m setuptools_scm')
87+
version = None
88+
return version, None
7389

90+
91+
###########################################################################
7492
version, version_date = get_version_info()
7593
version_description = """MintPy version {v}, date {d}""".format(
7694
v=version,

0 commit comments

Comments
 (0)