Skip to content

Commit 3914c0b

Browse files
setup: use git version instead of hardcoded one
setuptool_scm [1] package is a recommended way to set package version with git [2]. Version 6.4.2 was chosen due to Python 3.6 support, latest version 7.0.5 supports only Python 3.7+. Package version is displayed in documentation, so after this patch documentation for master branch won't be confused with the last tagged one. Version file is created when a user installs the package with `pip install` or on sources packing with `python setup.py bdist_wheel` command (readthedocs building pipelines install the package). If one would simply clone the repo, package `__version__` would be a `'dev'` placeholder. 1. https://pypi.org/project/setuptools-scm/ 2. https://packaging.python.org/en/latest/guides/single-sourcing-package-version/ Part of #238
1 parent cc20bdb commit 3914c0b

File tree

9 files changed

+78
-12
lines changed

9 files changed

+78
-12
lines changed

Diff for: .github/workflows/testing.yml

+3
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ jobs:
198198

199199
- name: Run tests
200200
run: python -m unittest discover -v
201+
env:
202+
TEST_PURE_INSTALL: true
201203

202204
run_tests_ce_windows:
203205
# We want to run on external PRs, but not on our own internal
@@ -348,6 +350,7 @@ jobs:
348350
env:
349351
REMOTE_TARANTOOL_HOST: localhost
350352
REMOTE_TARANTOOL_CONSOLE_PORT: 3302
353+
TEST_PURE_INSTALL: true
351354
run: python -m unittest discover -v
352355

353356
- name: Stop test tarantool instance

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ sophia
1919
.idea
2020

2121
venv/*
22+
23+
tarantool/version.py

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
143143
- Change documentation HTML theme (#67).
144144
- Update API documentation strings (#67).
145145
- Update documentation index, quick start and guide pages (#67).
146+
- Use git version to set package version (#238).
146147

147148
### Fixed
148149
- Package build (#238).

Diff for: doc/conf.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
# documentation root, use os.path.abspath to make it absolute, like shown here.
1717
# sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath('.')), "src"))
1818

19-
# Read package version without importing it
20-
for line in open(os.path.join(os.path.dirname(os.path.abspath('.')), "tarantool", "__init__.py")):
21-
if line.startswith("__version__"):
22-
exec(line)
23-
break
24-
2519
# -- General configuration -----------------------------------------------------
2620

2721
# If your documentation needs a minimal Sphinx version, state it here.
@@ -57,11 +51,13 @@
5751
# The version info for the project you're documenting, acts as replacement for
5852
# |version| and |release|, also used in various other places throughout the
5953
# built documents.
60-
#
54+
55+
import tarantool
56+
6157
# The short X.Y version.
62-
version = __version__
58+
version = tarantool.__version__
6359
# The full version, including alpha/beta/rc tags.
64-
release = __version__
60+
release = tarantool.__version__
6561

6662
# The language for content autogenerated by Sphinx. Refer to documentation
6763
# for a list of supported languages.

Diff for: requirements-test.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
dbapi-compliance==1.15.0
22
pyyaml==6.0
3+
importlib-metadata >= 1.0 ; python_version < '3.8'

Diff for: setup.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,34 @@
66

77
try:
88
from setuptools import setup, find_packages
9+
from setuptools.command.build_py import build_py
910
except ImportError:
1011
from distutils.core import setup, find_packages
12+
from distutils.command.build_py import build_py
1113

1214
# Extra commands for documentation management
1315
cmdclass = {}
1416
command_options = {}
1517

18+
# Build the package
19+
# python setup.py build_py
20+
# builds the package with generating correspondent VERSION file
21+
class BuildPyCommand(build_py):
22+
def run(self):
23+
# Import here to allow to run commands
24+
# like `python setup.py test` without setuptools_scm.
25+
from setuptools_scm import get_version
26+
version = get_version()
27+
28+
package_dir = self.get_package_dir('tarantool')
29+
version_file = os.path.join(package_dir, 'version.py')
30+
with open(version_file, 'w') as file:
31+
file.write(f"VERSION = '{version}'")
32+
33+
return super().run()
34+
35+
cmdclass["build_py"] = BuildPyCommand
36+
1637
# Build Sphinx documentation (html)
1738
# python setup.py build_sphinx
1839
# generates files into build/sphinx/html
@@ -74,7 +95,7 @@ def find_version(*file_paths):
7495
packages=packages,
7596
package_dir={"tarantool": "tarantool"},
7697
include_package_data=True,
77-
version=find_version('tarantool', '__init__.py'),
98+
use_scm_version=True,
7899
platforms=["all"],
79100
author="tarantool-python AUTHORS",
80101
author_email="[email protected]",
@@ -93,5 +114,8 @@ def find_version(*file_paths):
93114
cmdclass=cmdclass,
94115
command_options=command_options,
95116
install_requires=get_dependencies('requirements.txt'),
117+
setup_requires=[
118+
'setuptools_scm==6.4.2',
119+
],
96120
python_requires='>=3',
97121
)

Diff for: tarantool/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
Interval,
4141
)
4242

43-
__version__ = "0.9.0"
43+
try:
44+
from tarantool.version import VERSION
45+
__version__ = VERSION
46+
except ImportError:
47+
__version__ = '0.0.0-dev'
4448

4549

4650
def connect(host="localhost", port=33013, user=None, password=None,

Diff for: test/suites/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919
from .test_uuid import TestSuite_UUID
2020
from .test_datetime import TestSuite_Datetime
2121
from .test_interval import TestSuite_Interval
22+
from .test_package import TestSuite_Package
2223

2324
test_cases = (TestSuite_Schema_UnicodeConnection,
2425
TestSuite_Schema_BinaryConnection,
2526
TestSuite_Request, TestSuite_Protocol, TestSuite_Reconnect,
2627
TestSuite_Mesh, TestSuite_Execute, TestSuite_DBAPI,
2728
TestSuite_Encoding, TestSuite_Pool, TestSuite_Ssl,
2829
TestSuite_Decimal, TestSuite_UUID, TestSuite_Datetime,
29-
TestSuite_Interval)
30+
TestSuite_Interval, TestSuite_Package,)
3031

3132
def load_tests(loader, tests, pattern):
3233
suite = unittest.TestSuite()

Diff for: test/suites/test_package.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
import sys
3+
import unittest
4+
5+
if sys.version_info >= (3, 8):
6+
from importlib import metadata
7+
else:
8+
import importlib_metadata as metadata
9+
10+
import tarantool
11+
12+
13+
def is_test_pure_install():
14+
env = os.getenv("TEST_PURE_INSTALL")
15+
if env:
16+
env = env.upper()
17+
return env == "1" or env == "TRUE"
18+
return False
19+
20+
21+
class TestSuite_Package(unittest.TestCase):
22+
@classmethod
23+
def setUpClass(self):
24+
print(' PACKAGE '.center(70, '='), file=sys.stderr)
25+
print('-' * 70, file=sys.stderr)
26+
27+
28+
def test_version(self):
29+
if is_test_pure_install():
30+
self.assertEqual(tarantool.__version__, metadata.version('tarantool'))
31+
else:
32+
self.assertEqual(
33+
tarantool.__version__, '0.0.0-dev',
34+
'Ensure that there is no tarantool/version.py file in your dev build')

0 commit comments

Comments
 (0)