Skip to content

Commit 1658fe3

Browse files
committed
get package version from git
Use git describe to get a version string for the current place in the version history and/or whether the working directory is dirty. Also allow overriding the version using a VERSION environment variable.
1 parent 5b2d05b commit 1658fe3

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

setup.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import os
12
import re
3+
import subprocess
4+
25
import sdist_upip
36
from setuptools import setup
47

5-
VERSION = "1.0.0"
6-
78

89
def long_desc_from_readme():
910
with open('README.rst', 'r') as fd:
@@ -18,9 +19,17 @@ def long_desc_from_readme():
1819
return long_description
1920

2021

22+
def get_version():
23+
version = os.environ.get('VERSION', None)
24+
if not version:
25+
version = subprocess.check_output(['git', 'describe', '--always', '--tags', '--dirty'])
26+
version = str(version, 'utf-8').strip()
27+
return version
28+
29+
2130
setup(
2231
name="micropython-py-esp32-ulp",
23-
version=VERSION,
32+
version=get_version(),
2433
description="Assembler toolchain for the ESP32 ULP co-processor, written in MicroPython",
2534
long_description=long_desc_from_readme(),
2635
long_description_content_type='text/x-rst',

0 commit comments

Comments
 (0)