Skip to content

DBAPI based on Query Service #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8ef5640
connection and cursor interface
vgvoleg Oct 29, 2024
b8f0f72
basic connection methods
vgvoleg Oct 29, 2024
251bfe6
Add isolation level settings
vgvoleg Oct 29, 2024
179124e
scheme&table queries
vgvoleg Oct 29, 2024
37600fa
remove parameters from YdbQuery
vgvoleg Oct 29, 2024
2d0c38a
ddl and dml queries
vgvoleg Oct 29, 2024
d63f863
update min version of ydb
vgvoleg Oct 29, 2024
39cfaad
basic tests
vgvoleg Oct 29, 2024
8b839d2
cursor methods
vgvoleg Oct 29, 2024
068707a
new tests and connection fixes
vgvoleg Oct 29, 2024
3e351d5
fix all tests
vgvoleg Oct 29, 2024
b9cb4ec
move docker to testcontainers
vgvoleg Oct 29, 2024
b82c344
refactor connection
vgvoleg Oct 29, 2024
55c2a2f
style fixes
vgvoleg Oct 29, 2024
234c07c
fix isolation level test
vgvoleg Oct 29, 2024
7aab016
sync interface
vgvoleg Oct 29, 2024
b2f0c05
add concurrent.futures.TimeoutError to connect
vgvoleg Oct 29, 2024
5e51764
refactor cursors
vgvoleg Oct 29, 2024
aa96014
small refactor connections
vgvoleg Oct 29, 2024
e194e4b
continue to move common parts from connections
vgvoleg Oct 29, 2024
cf53661
one more method to common interface
vgvoleg Oct 29, 2024
d36e60d
Enable autoscroll for fetchone
vgvoleg Oct 29, 2024
ad31eb5
implement autoscroll for all fetches
vgvoleg Oct 29, 2024
7532331
dbapi attributes
vgvoleg Oct 29, 2024
b397b24
Simple README added
vgvoleg Oct 29, 2024
3dd9e63
update pyproject.toml
vgvoleg Oct 29, 2024
a8e28b5
autoincrement version
vgvoleg Oct 29, 2024
7bc3bb2
publish action
vgvoleg Oct 29, 2024
86a282d
make cursor client-side
vgvoleg Oct 29, 2024
d33aa10
refactor test
vgvoleg Oct 29, 2024
c98d958
refactor cursor test
vgvoleg Oct 29, 2024
af51b1f
review fixes
vgvoleg Oct 30, 2024
9346679
rename test files
vgvoleg Oct 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions .github/scripts/increment_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#!/bin/env python
import argparse
from dataclasses import dataclass

from packaging.version import Version

PYPROJECT_PATH = "pyproject.toml"
DEFAULT_CHANGELOG_PATH = "CHANGELOG.md"
DEFAULT_YDB_VERSION_FILE = "ydb_dbapi/version.py"
MARKER = "# AUTOVERSION"


@dataclass(init=False)
class VersionLine:
old_line: str
major: int
minor: int
patch: int
pre: int

def __init__(self, old_line: str, version_str: str):
self.old_line = old_line

version = Version(version_str)
self.major = version.major
self.minor = version.minor
self.micro = version.micro

if version.pre is None:
self.pre = 0
else:
self.pre = version.pre[1]

def increment(self, part_name: str, with_beta: bool):
if part_name == "minor":
self.increment_minor(with_beta)
elif part_name == "patch" or part_name == "micro":
self.increment_micro(with_beta)
else:
raise Exception("unexpected increment type: '%s'" % part_name)

def increment_minor(self, with_beta: bool):
if with_beta:
if self.pre == 0 or self.micro != 0:
self.increment_minor(False)
self.pre += 1
return

if self.micro == 0 and self.pre > 0:
self.pre = 0
return

self.minor += 1
self.micro = 0
self.pre = 0

def increment_micro(self, with_beta: bool):
if with_beta:
if self.pre == 0:
self.increment_micro(False)
self.pre += 1
return

if self.pre > 0:
self.pre = 0
return

self.micro += 1

def __str__(self):
if self.pre > 0:
pre = "b%s" % self.pre
else:
pre = ""

return "%s.%s.%s%s" % (self.major, self.minor, self.micro, pre)

def version_line_with_mark(self):
return 'version = "%s" %s' % (str(self), MARKER)


def extract_version(pyproject_content: str):
version_line = ""
for line in pyproject_content.splitlines():
if MARKER in line:
version_line = line
break

if version_line == "":
raise Exception("Not found version line")

version_line = version_line.strip()

parts = version_line.split('"')
version_part = parts[1]

return VersionLine(old_line=version_line, version_str=version_part)


def increment_version_at_pyproject(
pyproject_path: str, inc_type: str, with_beta: bool
) -> str:
with open(pyproject_path, "rt") as f:
setup_content = f.read()

version = extract_version(setup_content)
version.increment(inc_type, with_beta)
setup_content = setup_content.replace(
version.old_line, version.version_line_with_mark()
)

with open(pyproject_path, "w") as f:
f.write(setup_content)

return str(version)


def add_changelog_version(changelog_path, version: str):
with open(changelog_path, "rt") as f:
content = f.read()
content = content.strip()

if content.startswith("##"):
return

content = """## %s ##
%s
""" % (version, content)
with open(changelog_path, "w") as f:
f.write(content)


def set_version_in_version_file(file_path: str, version: str):
with open(file_path, "w") as f:
f.write('VERSION = "%s"\n' % version)


def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--inc-type",
default="minor",
help="increment version type: patch or minor",
choices=["minor", "patch"],
)
parser.add_argument(
"--beta", choices=["true", "false"], help="is beta version"
)
parser.add_argument(
"--changelog-path",
default=DEFAULT_CHANGELOG_PATH,
help="path to changelog",
type=str,
)
parser.add_argument("--pyproject-path", default=PYPROJECT_PATH)

args = parser.parse_args()

is_beta = args.beta == "true"

new_version = increment_version_at_pyproject(
args.pyproject_path, args.inc_type, is_beta
)
add_changelog_version(args.changelog_path, new_version)
set_version_in_version_file(DEFAULT_YDB_VERSION_FILE, new_version)
print(new_version)


if __name__ == "__main__":
main()
28 changes: 28 additions & 0 deletions .github/scripts/increment_version_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest

from .increment_version import VersionLine


@pytest.mark.parametrize(
"source,inc_type,with_beta,result",
[
("0.0.0", "patch", False, "0.0.1"),
("0.0.1", "patch", False, "0.0.2"),
("0.0.1b1", "patch", False, "0.0.1"),
("0.0.0", "patch", True, "0.0.1b1"),
("0.0.1", "patch", True, "0.0.2b1"),
("0.0.2b1", "patch", True, "0.0.2b2"),
("0.0.1", "minor", False, "0.1.0"),
("0.0.1b1", "minor", False, "0.1.0"),
("0.1.0b1", "minor", False, "0.1.0"),
("0.1.0", "minor", True, "0.2.0b1"),
("0.1.0b1", "minor", True, "0.1.0b2"),
("0.1.1b1", "minor", True, "0.2.0b1"),
("3.0.0b1", "patch", True, "3.0.0b2"),
],
)
def test_increment_version(source, inc_type, with_beta, result):
version = VersionLine("", source)
version.increment(inc_type, with_beta)
incremented = str(version)
assert incremented == result
43 changes: 43 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Lint

on:
push:
branches:
- master
pull_request:

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version: [3.9]
poetry-version: [1.8]

steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry ${{ matrix.poetry-version }}
run: |
pip install "poetry~=${{ matrix.poetry-version }}.0"

# Ensure that Poetry is not upgraded past the version we are testing
poetry add "poetry@~${{ matrix.poetry-version }}" --lock

- name: Install packages
run: |
poetry install

- name: Run tests
run: |
poetry run poe lint
111 changes: 111 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Publish package release

on:
workflow_dispatch:
inputs:
version-change:
description: Version part
required: true
type: choice
default: minor
options:
- minor
- patch
beta:
description: Is beta version
required: true
type: boolean
default: True
jobs:
publish:
env:
VERSION_CHANGE: ${{ github.event.inputs.version-change }}
WITH_BETA: ${{ github.event.inputs.beta }}
GH_TOKEN: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }}
CHANGELOG_FILE: CHANGELOG.md
PYPROJECT_PATH: pyproject.toml

permissions:
contents: write
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.YDB_PLATFORM_BOT_TOKEN_REPO }}

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.9'

- name: read changelog
id: read-changelog
run: |
CHANGELOG=$(cat $CHANGELOG_FILE | sed -e '/^## .*$/,$d')
echo "CHANGELOG<<CHANGELOGEOF_MARKER" >> $GITHUB_ENV
echo "$CHANGELOG" >> $GITHUB_ENV
echo "CHANGELOGEOF_MARKER" >> $GITHUB_ENV
echo "# Changelog" >> $GITHUB_STEP_SUMMARY
echo "$CHANGELOG" >> $GITHUB_STEP_SUMMARY


- name: Increment version
id: increment-version
run: |
NEW_VERSION=$(python3 ./.github/scripts/increment_version.py --inc-type=$VERSION_CHANGE --beta=$WITH_BETA)
echo new version: $NEW_VERSION
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION" >> $GITHUB_STEP_SUMMARY

- name: Install Poetry
run: pip install poetry

- name: Build package
run: poetry build

- name: Publish release on github
run: |
if [[ -z "$CHANGELOG" ]]
then
echo "CHANGELOG empty"
exit 1;
fi;

TAG="${{ steps.increment-version.outputs.NEW_VERSION }}"

# Get previous version from changelog
# pre-incremented version not used for consistent changelog with release notes
# for example changelog may be rewrited when switch from beta to release
# and remove internal beta changes
LAST_TAG=$(cat $CHANGELOG_FILE | grep '^## .* ##$' | head -n 2 | tail -n 1 | cut -d ' ' -f 2)

git config --global user.email "robot@umbrella";
git config --global user.name "robot";
git commit -am "Release: $TAG";

git tag "$TAG"
git push && git push --tags

CHANGELOG="$CHANGELOG

Full Changelog: [$LAST_TAG...$TAG](https://github.com/ydb-platform/ydb-sqlalchemy/compare/$LAST_TAG...$TAG)"
if [ "$WITH_BETA" = true ]
then
gh release create --prerelease $TAG --title "$TAG" --notes "$CHANGELOG"
else
gh release create $TAG --title "$TAG" --notes "$CHANGELOG"
fi;

- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1.8
Loading
Loading