Skip to content

Commit 35566d1

Browse files
committed
gattlib-py: Fix setup.py when building source package
1 parent f4ed88e commit 35566d1

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

ci/generate-python-package.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ mkdir ${gattlib_py_package_dir}/ci/
2828
cp -r ${ROOT_PATH}/ci/install-bluez.sh ${gattlib_py_package_dir}/ci/
2929

3030
# Create MANIFEST.in
31-
rm -f MANIFEST.in
32-
cat <<EOT >> MANIFEST.in
31+
rm -f ${gattlib_py_package_dir}/MANIFEST.in
32+
cat <<EOT >> ${gattlib_py_package_dir}/MANIFEST.in
3333
graft common
3434
graft bluez
3535
graft dbus
@@ -51,7 +51,7 @@ python3 -m cibuildwheel --output-dir dist
5151
python setup.py sdist
5252

5353
# Move generated artifact to project root path
54-
ls dist/*
54+
rm -Rf ${ROOT_PATH}/dist
5555
mv dist ${ROOT_PATH}
5656

5757
popd

gattlib-py/setup.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
from setuptools.command.build_ext import build_ext
1515
import subprocess
1616

17+
SETUP_DIR = os.path.dirname(os.path.realpath(__file__))
18+
1719
# Name of the directory containing the python sources
1820
python_module_name = "gattlib"
1921
# Specified where the CMakeLists.txt is located
@@ -23,14 +25,28 @@
2325
git_version_command = subprocess.Popen(['git', 'describe', '--abbrev=7', '--dirty', '--always', '--tags'],
2426
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
2527
stdout, stderr = git_version_command.communicate()
26-
git_version = stdout.decode('utf-8').strip()
28+
if git_version_command.returncode == 0:
29+
git_version = stdout.decode('utf-8').strip()
30+
else:
31+
git_version = None
2732

2833
#
2934
# Create '_version.py'
3035
#
3136
package_version = os.environ.get('GATTLIB_PY_VERSION', git_version)
32-
with open(os.path.join("gattlib", "_version.py"), "w") as f:
33-
f.write(f"__version__ = \"{package_version}\"\n")
37+
38+
GATTLIB_VERSION_FILE = os.path.join(SETUP_DIR, "gattlib", "_version.py")
39+
40+
# Case we are building from source package
41+
if package_version is None:
42+
with open(GATTLIB_VERSION_FILE, "r") as f:
43+
gattlib_version_statement = f.read()
44+
res = re.search(r'__version__ = "(.*)"', gattlib_version_statement)
45+
package_version = res.group(1)
46+
47+
if package_version:
48+
with open(GATTLIB_VERSION_FILE, "w") as f:
49+
f.write(f"__version__ = \"{package_version}\"\n")
3450

3551

3652
class CMakeExtension(Extension):
@@ -163,7 +179,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
163179
author_email="[email protected]",
164180
description="Python wrapper for gattlib library",
165181
url="https://github.com/labapart/gattlib/gattlib-py",
166-
long_description=open('README.md').read(),
182+
long_description=open(os.path.join(SETUP_DIR, 'README.md')).read(),
167183
long_description_content_type='text/markdown',
168184
packages=find_packages(),
169185
install_requires=[

0 commit comments

Comments
 (0)