Skip to content

Commit 8d08b88

Browse files
committed
libbtrfsutil: python: use version from primary VERSION file
The version file of the python subpackage had to have the version set manually in setup.py due to the out-of-tree build where it was not possible to access the file VERSION. Manual update was error prone. Improve that by adding a separate file template that is finalized with the version during the configure phase. Then it's inclded in setup.py as it's in the same directory. There are two exceptions when the file is not required to run setup.py: - clean - allow running 'make clean' in partially configured directory - (no arguments) - show the help and commands In all other cases the file version.py must exist. Signed-off-by: David Sterba <[email protected]>
1 parent 2d4e15e commit 8d08b88

File tree

5 files changed

+34
-7
lines changed

5 files changed

+34
-7
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ clean-gen:
953953
configure.lineno config.status.lineno Makefile.inc \
954954
Documentation/Makefile tags TAGS \
955955
libbtrfsutil/libbtrfsutil.pc \
956+
libbtrfsutil/python/version.py \
956957
cscope.files cscope.out cscope.in.out cscope.po.out \
957958
config.log include/config.h include/config.h.in~ aclocal.m4 \
958959
configure configure~ autom4te.cache/

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ Makefile.inc
558558
Documentation/Makefile
559559
libbtrfs/version.h
560560
libbtrfsutil/libbtrfsutil.pc
561+
libbtrfsutil/python/version.py
561562
])
562563

563564
AC_OUTPUT

libbtrfsutil/python/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ __pycache__
55
/build
66
/constants.c
77
/dist
8+
/version.py

libbtrfsutil/python/setup.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,24 @@
2020
import re
2121
import os
2222
import os.path
23+
import sys
2324
from setuptools import setup, Extension
2425
from setuptools.command.build_ext import build_ext
2526
import subprocess
2627

2728

2829
def get_version():
29-
f = open('../../VERSION', 'r')
30-
version = f.readline().strip()
31-
f.close()
32-
return ".".join(version[1:].split('.'))
30+
version = 0
31+
try:
32+
import version
33+
version = version.btrfs_util_py_version
34+
except:
35+
# Don't fail if this is only the 'clean' target or no command
36+
if 'clean' in sys.argv or len(sys.argv) == 1:
37+
version = '0.0'
38+
else:
39+
raise Exception("No generated version.py found, please configure")
40+
return version
3341

3442

3543
def out_of_date(dependencies, target):
@@ -104,9 +112,7 @@ def run(self):
104112

105113
setup(
106114
name='btrfsutil',
107-
# FIXME: version file is not present when building outside of git
108-
#version=get_version(),
109-
version='6.12',
115+
version=get_version(),
110116
description='Library for managing Btrfs filesystems',
111117
long_description=open('README.md').read(),
112118
long_description_content_type='text/markdown',

libbtrfsutil/python/version.py.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
3+
# This file is part of libbtrfsutil.
4+
#
5+
# libbtrfsutil is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU Lesser General Public License as published by
7+
# the Free Software Foundation, either version 2.1 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# libbtrfsutil is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU Lesser General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU Lesser General Public License
16+
# along with libbtrfsutil. If not, see <http://www.gnu.org/licenses/>.
17+
18+
btrfs_util_py_version = '@BTRFS_VERSION_PLAIN@'

0 commit comments

Comments
 (0)