Skip to content

Commit f15686b

Browse files
committed
Add backup if PKG-INFO exists
1 parent a6692e2 commit f15686b

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

setuptools_git_ver.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from setuptools.dist import Distribution
44
from distutils.errors import DistutilsSetupError
55
from collections.abc import Mapping
6+
import os.path
67

78
DEFAULT_TEMPLATE: str = "{tag}"
89
DEFAULT_DEV_TEMPLATE: str = "{tag}.dev{ccount}+git.{sha}"
@@ -72,6 +73,15 @@ def version_from_git(template: str = DEFAULT_TEMPLATE,
7273
dev_template: str = DEFAULT_DEV_TEMPLATE,
7374
dirty_template: str = DEFAULT_DIRTY_TEMPLATE,
7475
) -> None:
76+
77+
# Check if PKG-INFO exists and return value in that if it does
78+
if os.path.exists('PKG-INFO'):
79+
with open('PKG-INFO', 'r') as f:
80+
lines = f.readlines()
81+
for line in lines:
82+
if line.startswith('Version:'):
83+
return line[8:].strip()
84+
7585
tag = _get_tag()
7686
if tag is None:
7787
raise Exception("Couldn't find tag to use.")

0 commit comments

Comments
 (0)