ydb-python-sdk icon indicating copy to clipboard operation
ydb-python-sdk copied to clipboard

dev: replace all imports to relative

Open rekby opened this issue 1 year ago • 7 comments

  1. "from ydb import issues" -> "from .. import issues" and similars for all files inside ydb folder
  2. auto-replace imports im generated protobuf during generation step
  3. linter to enforce the rule

rekby avatar Mar 22 '23 06:03 rekby

Why? Absolute imports are recommended https://peps.python.org/pep-0008/#imports

Valeria1235 avatar Mar 22 '23 12:03 Valeria1235

The main reason of this change is to ease using YDB python SDK in YDB functional tests.

The pip package name clashes with ydb module from the repo, so we opt for using the actual SDK sources, which reside here.

And even in that case, invocations of import ydb inside SDK and outside SDK should point to different modules. That's why I would prefer SDK imports to be relative, so they do not cause a module clash.

I am looking for other solutions to the problem, but the one above seems to be the most natural one, despite breaking PEP standarts.

qrort avatar Mar 23 '23 08:03 qrort

why no to insert source dir path to sys.path for tests?

Valeria1235 avatar Mar 23 '23 14:03 Valeria1235

Because YDB tests will have two modules in syspath: ydb and ydb.public.sdk.python3.ydb, and all the imports wouldn't work because it is impossible to distinguish between those symbols in native Python.

qrort avatar Mar 23 '23 16:03 qrort

I think that first level relative import is ok, for example "from . import issues" is fine. Other options when we do second level imports like "from .. import something" is not ok, because it reduces code readability.

gridnevvvit avatar Mar 24 '23 09:03 gridnevvvit

I will invest more time in searching for alternative solutions to my problem and notify you if I can prove that relative imports is the least harmful way to fulfill the goal of launching YDB functional tests.

We can close the issue for now and reopen it if needed.

qrort avatar Mar 24 '23 10:03 qrort

Why do we need to have pip package installed for tests? We have all the source code including Python SDK and need to run tests against it.

alexv-smirnov avatar Apr 04 '23 19:04 alexv-smirnov