Skip to content

Commit 31febef

Browse files
aksakallihashhar
authored andcommitted
Refactor setup.py to avoid cyclic dependency on trino.__version__
__version__ is defined in __init__.py in trino module which means that we cannot easily use the module version in the library code because it introduces a cyclic dependency. This change introduces a _version.py which also includes other meta-information and changes setup.py to read those values from there instead of inline. The release script is also updated since the version now needs to be updated in a different file.
1 parent d6dee79 commit 31febef

File tree

5 files changed

+48
-21
lines changed

5 files changed

+48
-21
lines changed

.github/DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ the code base like `ttl` are allowed and encouraged.
118118
```bash
119119
git fetch -a && git status
120120
```
121-
- Change version in `trino/__init__.py` to a new version, e.g. `0.123.0`.
121+
- Change version in `trino/_version.py` to a new version, e.g. `0.123.0`.
122122
- Commit
123123
```bash
124124
git commit -a -m "Bump version to 0.123.0"

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
VERSION_NUMBER="$(./setup.py --version)"
2828
NEXT_VERSION_NUMBER="$(echo ${VERSION_NUMBER} | awk -F. -v OFS=. '{$2 += 1 ; print}')"
2929
echo "Current version: ${VERSION_NUMBER}; Next version number: ${NEXT_VERSION_NUMBER}"
30-
sed -i "s/${VERSION_NUMBER}/${NEXT_VERSION_NUMBER}/g" trino/__init__.py
30+
sed -i "s/${VERSION_NUMBER}/${NEXT_VERSION_NUMBER}/g" trino/_version.py
3131
3232
# Export for use in next steps
3333
echo "VERSION_NUMBER=${VERSION_NUMBER}" >> $GITHUB_ENV

setup.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import ast
16-
import re
15+
import os
1716
import textwrap
17+
from codecs import open
18+
from typing import Any
1819

1920
from setuptools import find_packages, setup
2021

21-
_version_re = re.compile(r"__version__\s+=\s+(.*)")
22-
23-
with open("trino/__init__.py", "rb") as f:
24-
trino_version = _version_re.search(f.read().decode("utf-8"))
25-
assert trino_version is not None
26-
version = str(ast.literal_eval(trino_version.group(1)))
22+
about = {} # type: dict[str, Any]
23+
here = os.path.abspath(os.path.dirname(__file__))
24+
with open(os.path.join(here, "trino", "_version.py"), "r", "utf-8") as f:
25+
exec(f.read(), about)
2726

2827
kerberos_require = ["requests_kerberos"]
2928
sqlalchemy_require = ["sqlalchemy >= 1.3"]
@@ -44,22 +43,22 @@
4443
]
4544

4645
setup(
47-
name="trino",
48-
author="Trino Team",
49-
author_email="[email protected]",
50-
version=version,
51-
url="https://github.com/trinodb/trino-python-client",
46+
name=about["__title__"],
47+
author=about["__author__"],
48+
author_email=about["__author_email__"],
49+
version=about["__version__"],
50+
url=about["__url__"],
5251
packages=find_packages(include=["trino", "trino.*"]),
5352
package_data={"": ["LICENSE", "README.md"]},
54-
description="Client for the Trino distributed SQL Engine",
53+
description=about["__description__"],
5554
long_description=textwrap.dedent(
5655
"""
5756
Client for Trino (https://trino.io), a distributed SQL engine for
5857
interactive and batch big data processing. Provides a low-level client and
5958
a DBAPI 2.0 implementation.
6059
"""
6160
),
62-
license="Apache 2.0",
61+
license=about["__license__"],
6362
classifiers=[
6463
"Development Status :: 4 - Beta",
6564
"Intended Audience :: Developers",
@@ -77,7 +76,7 @@
7776
"Programming Language :: Python :: Implementation :: PyPy",
7877
"Topic :: Database :: Front-Ends",
7978
],
80-
python_requires='>=3.7',
79+
python_requires=">=3.7",
8180
install_requires=[
8281
"backports.zoneinfo;python_version<'3.9'",
8382
"python-dateutil",

trino/__init__.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,28 @@
1111
# limitations under the License.
1212

1313
from . import auth, client, constants, dbapi, exceptions, logging
14+
from ._version import (
15+
__author__,
16+
__author_email__,
17+
__description__,
18+
__license__,
19+
__title__,
20+
__url__,
21+
__version__,
22+
)
1423

15-
__all__ = ['auth', 'dbapi', 'client', 'constants', 'exceptions', 'logging']
16-
17-
__version__ = "0.326.0"
24+
__all__ = [
25+
"auth",
26+
"client",
27+
"constants",
28+
"dbapi",
29+
"exceptions",
30+
"logging",
31+
"__author__",
32+
"__author_email__",
33+
"__description__",
34+
"__license__",
35+
"__title__",
36+
"__url__",
37+
"__version__",
38+
]

trino/_version.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
__title__ = "trino"
2+
__description__ = "Client for the Trino distributed SQL Engine"
3+
__url__ = "https://github.com/trinodb/trino-python-client"
4+
__version__ = "0.326.0"
5+
__author__ = "Trino Team"
6+
__author_email__ = "[email protected]"
7+
__license__ = "Apache 2.0"

0 commit comments

Comments
 (0)