Skip to content

Commit

Permalink
libbtrfsutil: python: use version from primary VERSION file
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
kdave committed Feb 13, 2025
1 parent 2d4e15e commit 8d08b88
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ clean-gen:
configure.lineno config.status.lineno Makefile.inc \
Documentation/Makefile tags TAGS \
libbtrfsutil/libbtrfsutil.pc \
libbtrfsutil/python/version.py \
cscope.files cscope.out cscope.in.out cscope.po.out \
config.log include/config.h include/config.h.in~ aclocal.m4 \
configure configure~ autom4te.cache/
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ Makefile.inc
Documentation/Makefile
libbtrfs/version.h
libbtrfsutil/libbtrfsutil.pc
libbtrfsutil/python/version.py
])

AC_OUTPUT
Expand Down
1 change: 1 addition & 0 deletions libbtrfsutil/python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__
/build
/constants.c
/dist
/version.py
20 changes: 13 additions & 7 deletions libbtrfsutil/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@
import re
import os
import os.path
import sys
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import subprocess


def get_version():
f = open('../../VERSION', 'r')
version = f.readline().strip()
f.close()
return ".".join(version[1:].split('.'))
version = 0
try:
import version
version = version.btrfs_util_py_version
except:
# Don't fail if this is only the 'clean' target or no command
if 'clean' in sys.argv or len(sys.argv) == 1:
version = '0.0'
else:
raise Exception("No generated version.py found, please configure")
return version


def out_of_date(dependencies, target):
Expand Down Expand Up @@ -104,9 +112,7 @@ def run(self):

setup(
name='btrfsutil',
# FIXME: version file is not present when building outside of git
#version=get_version(),
version='6.12',
version=get_version(),
description='Library for managing Btrfs filesystems',
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
Expand Down
18 changes: 18 additions & 0 deletions libbtrfsutil/python/version.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3

# This file is part of libbtrfsutil.
#
# libbtrfsutil is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 2.1 of the License, or
# (at your option) any later version.
#
# libbtrfsutil is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with libbtrfsutil. If not, see <http://www.gnu.org/licenses/>.

btrfs_util_py_version = '@BTRFS_VERSION_PLAIN@'

0 comments on commit 8d08b88

Please sign in to comment.