|
14 | 14 | from setuptools.command.build_ext import build_ext |
15 | 15 | import subprocess |
16 | 16 |
|
| 17 | +SETUP_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 18 | + |
17 | 19 | # Name of the directory containing the python sources |
18 | 20 | python_module_name = "gattlib" |
19 | 21 | # Specified where the CMakeLists.txt is located |
|
23 | 25 | git_version_command = subprocess.Popen(['git', 'describe', '--abbrev=7', '--dirty', '--always', '--tags'], |
24 | 26 | stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
25 | 27 | 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 |
27 | 32 |
|
28 | 33 | # |
29 | 34 | # Create '_version.py' |
30 | 35 | # |
31 | 36 | 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") |
34 | 50 |
|
35 | 51 |
|
36 | 52 | class CMakeExtension(Extension): |
@@ -163,7 +179,7 @@ def build_extension(self, ext: CMakeExtension) -> None: |
163 | 179 | |
164 | 180 | description="Python wrapper for gattlib library", |
165 | 181 | 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(), |
167 | 183 | long_description_content_type='text/markdown', |
168 | 184 | packages=find_packages(), |
169 | 185 | install_requires=[ |
|
0 commit comments