Skip to content

Commit 5c47ceb

Browse files
committed
Read version in setup.py
1 parent 8178aa3 commit 5c47ceb

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

setup.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
from setuptools import setup, Extension
2+
import re
3+
4+
def get_version():
5+
"""
6+
Extract the version number from arraydeque.c.
7+
Looks for a line of the form:
8+
#define ARRAYDEQUE_VERSION "0.1.0"
9+
"""
10+
with open("arraydeque.c", "r", encoding="utf-8") as f:
11+
content = f.read()
12+
match = re.search(r'#define\s+ARRAYDEQUE_VERSION\s+"([^"]+)"', content)
13+
if match:
14+
return match.group(1)
15+
raise RuntimeError("Unable to find version string in arraydeque.c.")
216

317
module = Extension('arraydeque', sources=['arraydeque.c'])
418

519
setup(
620
name='arraydeque',
7-
version='0.1',
21+
version=get_version(),
822
description='Array-backed deque implementation',
923
ext_modules=[module],
1024
)

0 commit comments

Comments
 (0)