Skip to content

Commit f4e97f4

Browse files
authored
Merge pull request #63 from ydb-platform/generate-protobuf
Generate protobuf from ydb-api-protos
2 parents 2317aba + f3e8a8d commit f4e97f4

File tree

141 files changed

+7816
-24957
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+7816
-24957
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
__pycache__
22
ydb.egg-info/
3+
/.idea
4+
/tox
5+
/venv
6+
/ydb_certs

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "ydb-api-protos"]
2+
path = ydb-api-protos
3+
url = https://github.com/ydb-platform/ydb-api-protos.git

BUILD.md

+8
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,11 @@ Use the command below to run unit tests.
4545
```sh
4646
tox -epy38
4747
```
48+
49+
### Regenerate protobuf
50+
51+
Use the command below for regenerate protobuf code.
52+
53+
```sh
54+
make protobuf
55+
```

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* Regenerate protobuf code from public api protos (some private protobufs was removed)
2+
* Remove internal S3 client code
3+
14
## 2.11.0 ##
25

36
* removed unused experimental client from ydb python sdk.

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
protobuf:
2+
docker build -f generate-protobuf.Dockerfile . -t ydb-python-sdk-proto-generator-env
3+
docker run --rm -it -v $${PWD}:$${PWD} -w $${PWD} ydb-python-sdk-proto-generator-env python generate_protoc.py

generate-protobuf.Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM python:3.9.15
2+
RUN \
3+
python -m pip install --upgrade pip && \
4+
python -m pip install grpcio==1.39.0 && \
5+
python -m pip install grpclib && \
6+
python -m pip install protobuf==3.20.3 && \
7+
python -m pip install grpcio-tools==1.38.0
8+
9+
ENV PROTOC_VER=21.8
10+
RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VER}/protoc-${PROTOC_VER}-linux-x86_64.zip && \
11+
unzip protoc-*.zip && \
12+
rm -f protoc-*.zip && \
13+
mv bin/protoc /usr/local/bin/protoc && \
14+
mv include well-known-protos

generate_protoc.py

+62-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,70 @@
11
import os
2+
import pathlib
3+
import shutil
4+
from typing import List
5+
26
from grpc_tools import command
37

4-
command.build_package_protos('.')
58

6-
init_files_to_create = []
9+
def files_filter(dir, items: List[str]) -> List[str]:
10+
ignored_names = ['.git']
11+
12+
ignore = []
13+
for item in items:
14+
fullpath = os.path.join(dir, item)
15+
if os.path.isdir(fullpath) and item not in ignored_names:
16+
continue
17+
if item.endswith(".proto"):
18+
continue
19+
ignore.append(item)
20+
21+
return ignore
22+
23+
24+
def create_init_files(rootdirpath: str):
25+
for root, _dirs, _files in os.walk(rootdirpath):
26+
init_path = pathlib.Path(os.path.join(root, '__init__.py'))
27+
if not init_path.exists():
28+
init_path.touch()
29+
30+
31+
def remove_protos(rootdirpath: str):
32+
for root, _dirs, files in os.walk(rootdirpath):
33+
for file in files:
34+
if file.endswith(".proto"):
35+
os.remove(os.path.join(root, file))
36+
37+
38+
def fix_file_contents(rootdir: str):
39+
flake_ignore_line = "# flake8: " + "noqa" # prevent ignore the file
40+
41+
for dirpath, _, fnames in os.walk(rootdir):
42+
for fname in fnames:
43+
if not fname.endswith(".py"):
44+
continue
45+
46+
with open(os.path.join(dirpath, fname), 'r+t') as f:
47+
content = f.read()
48+
49+
# Fix imports
50+
content = content.replace("from protos", "from ydb._grpc.protos")
51+
52+
# Add ignore style check
53+
content = content.replace("# -*- coding: utf-8 -*-", "# -*- coding: utf-8 -*-\n" + flake_ignore_line)
54+
f.seek(0)
55+
f.write(content)
56+
57+
58+
def generate_protobuf(src_proto_dir: str, dst_dir: str):
59+
shutil.rmtree(dst_dir, ignore_errors=True)
760

8-
for root, dirs, files in os.walk('kikimr'):
9-
if '__init__.py' in files:
10-
continue
61+
shutil.copytree(src_proto_dir, dst_dir, ignore=files_filter)
62+
create_init_files(dst_dir)
1163

12-
init_files_to_create.append(
13-
os.path.join(
14-
root,
15-
'__init__.py'
16-
)
17-
)
64+
command.build_package_protos(dst_dir)
65+
remove_protos(dst_dir)
66+
fix_file_contents(dst_dir)
1867

1968

20-
for filename in init_files_to_create:
21-
with open(filename, 'w') as f:
22-
pass
69+
if __name__ == '__main__':
70+
generate_protobuf("ydb-api-protos", "ydb/_grpc")

requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
grpcio==1.38.0
2-
protobuf>3.17.3
1+
grpcio==1.39.0
2+
protobuf>3.17.3,<4.0.0
33
pytest==6.2.4
44
aiohttp==3.7.4

test-requirements.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ docker==5.0.0
1010
docker-compose==1.29.2
1111
dockerpty==0.4.1
1212
docopt==0.6.2
13-
grpcio>=1.38.0
13+
grpcio==1.39.0
14+
grpcio-tools==1.39.0
1415
idna==3.2
1516
importlib-metadata==4.6.1
1617
iniconfig==1.1.1
1718
jsonschema==3.2.0
1819
packaging==21.0
1920
paramiko==2.10.1
2021
pluggy==0.13.1
21-
protobuf>3.17.3
22+
protobuf>3.17.3,<4.0.0
2223
py==1.10.0
2324
pycparser==2.20
2425
PyNaCl==1.4.0

tox.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ commands =
4646
skip_install = true
4747
deps = black
4848
commands =
49-
black ydb examples tests --extend-exclude ydb/public/api
49+
black ydb examples tests --extend-exclude ydb/_grpc
5050

5151
[testenv:black]
5252
skip_install = true
5353
deps = black
5454
commands =
55-
black --check ydb examples tests --extend-exclude ydb/public/api
55+
black --check ydb examples tests --extend-exclude ydb/_grpc
5656

5757
[testenv:pylint]
5858
deps = pylint

ydb-api-protos

Submodule ydb-api-protos added at 07b827b

ydb/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from .settings import * # noqa
88
from .resolver import * # noqa
99
from .export import * # noqa
10-
from .s3list import * # noqa
1110
from .auth_helpers import * # noqa
1211
from .operation import * # noqa
1312
from .scripting import * # noqa

ydb/_apis.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# -*- coding: utf-8 -*-
2-
from ydb.public.api.grpc import (
2+
from ydb._grpc import (
33
ydb_cms_v1_pb2_grpc,
44
ydb_discovery_v1_pb2_grpc,
55
ydb_scheme_v1_pb2_grpc,
66
ydb_table_v1_pb2_grpc,
77
)
8-
from ydb.public.api.protos import (
8+
from ydb._grpc.protos import (
99
ydb_status_codes_pb2,
1010
ydb_discovery_pb2,
1111
ydb_scheme_pb2,
1212
ydb_table_pb2,
1313
ydb_value_pb2,
1414
)
15-
from ydb.public.api.protos import ydb_operation_pb2
16-
from ydb.public.api.protos import ydb_common_pb2
17-
from ydb.public.api.grpc import ydb_operation_v1_pb2_grpc
15+
from ydb._grpc.protos import ydb_operation_pb2
16+
from ydb._grpc.protos import ydb_common_pb2
17+
from ydb._grpc import ydb_operation_v1_pb2_grpc
1818

1919

2020
StatusIds = ydb_status_codes_pb2.StatusIds
File renamed without changes.

ydb/public/api/protos/annotations/validation_pb2.py renamed to ydb/_grpc/protos/annotations/validation_pb2.py

+14-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ydb/public/api/protos/ydb_auth_pb2.py renamed to ydb/_grpc/protos/ydb_auth_pb2.py

+18-17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)