Skip to content

Commit

Permalink
Refactor setup.py to avoid cyclic dependency on trino.__version__
Browse files Browse the repository at this point in the history
__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.
  • Loading branch information
aksakalli authored and hashhar committed Sep 20, 2023
1 parent d6dee79 commit 53e69b6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ the code base like `ttl` are allowed and encouraged.
```bash
git fetch -a && git status
```
- Change version in `trino/__init__.py` to a new version, e.g. `0.123.0`.
- Change version in `trino/_version.py` to a new version, e.g. `0.123.0`.
- Commit
```bash
git commit -a -m "Bump version to 0.123.0"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
VERSION_NUMBER="$(./setup.py --version)"
NEXT_VERSION_NUMBER="$(echo ${VERSION_NUMBER} | awk -F. -v OFS=. '{$2 += 1 ; print}')"
echo "Current version: ${VERSION_NUMBER}; Next version number: ${NEXT_VERSION_NUMBER}"
sed -i "s/${VERSION_NUMBER}/${NEXT_VERSION_NUMBER}/g" trino/__init__.py
sed -i "s/${VERSION_NUMBER}/${NEXT_VERSION_NUMBER}/g" trino/_version.py
# Export for use in next steps
echo "VERSION_NUMBER=${VERSION_NUMBER}" >> $GITHUB_ENV
Expand Down
31 changes: 15 additions & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import ast
import re
import os
import textwrap
from codecs import open
from typing import Any

from setuptools import find_packages, setup

_version_re = re.compile(r"__version__\s+=\s+(.*)")

with open("trino/__init__.py", "rb") as f:
trino_version = _version_re.search(f.read().decode("utf-8"))
assert trino_version is not None
version = str(ast.literal_eval(trino_version.group(1)))
about = {} # type: dict[str, Any]
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, "trino", "_version.py"), "r", "utf-8") as f:
exec(f.read(), about)

kerberos_require = ["requests_kerberos"]
sqlalchemy_require = ["sqlalchemy >= 1.3"]
Expand All @@ -44,22 +43,22 @@
]

setup(
name="trino",
author="Trino Team",
author_email="python-client@trino.io",
version=version,
url="https://github.com/trinodb/trino-python-client",
name=about["__title__"],
author=about["__author__"],
author_email=about["__author_email__"],
version=about["__version__"],
url=about["__url__"],
packages=find_packages(include=["trino", "trino.*"]),
package_data={"": ["LICENSE", "README.md"]},
description="Client for the Trino distributed SQL Engine",
description=about["__description__"],
long_description=textwrap.dedent(
"""
Client for Trino (https://trino.io), a distributed SQL engine for
interactive and batch big data processing. Provides a low-level client and
a DBAPI 2.0 implementation.
"""
),
license="Apache 2.0",
license=about["__license__"],
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
Expand All @@ -77,7 +76,7 @@
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Database :: Front-Ends",
],
python_requires='>=3.7',
python_requires=">=3.7",
install_requires=[
"backports.zoneinfo;python_version<'3.9'",
"python-dateutil",
Expand Down
27 changes: 24 additions & 3 deletions trino/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,28 @@
# limitations under the License.

from . import auth, client, constants, dbapi, exceptions, logging
from ._version import (
__author__,
__author_email__,
__description__,
__license__,
__title__,
__url__,
__version__,
)

__all__ = ['auth', 'dbapi', 'client', 'constants', 'exceptions', 'logging']

__version__ = "0.326.0"
__all__ = [
"auth",
"client",
"constants",
"dbapi",
"exceptions",
"logging",
"__author__",
"__author_email__",
"__description__",
"__license__",
"__title__",
"__url__",
"__version__",
]
7 changes: 7 additions & 0 deletions trino/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__title__ = "trino"
__description__ = "Client for the Trino distributed SQL Engine"
__url__ = "https://github.com/trinodb/trino-python-client"
__version__ = "0.326.0"
__author__ = "Trino Team"
__author_email__ = "python-client@trino.io"
__license__ = "Apache 2.0"

0 comments on commit 53e69b6

Please sign in to comment.