From 3bfb1141b42c2da8575999e1659844cc721e262d Mon Sep 17 00:00:00 2001 From: antondmtvch <antondmtvch@gmail.com> Date: Thu, 22 Jun 2023 18:49:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D1=8B=20=D0=BD=D0=B5=D0=BA=D0=BE?= =?UTF-8?q?=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D1=8B=D1=85=20=D0=B8=D0=BC?= =?UTF-8?q?=D0=BF=D0=BE=D1=80=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 3 ++- fix_imports.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 fix_imports.py diff --git a/Makefile b/Makefile index 11cf193..35d5d68 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ clean-build: rm -fr dist/ rm -fr .eggs/ find . -name '*.egg-info' -exec rm -fr {} + - find . -name '*.egg' -exec rm -f {} + + find . -name '*.egg' -exec rm -f {} + || true clean-pyc: find . -name '*.pyc' -exec rm -f {} + @@ -62,3 +62,4 @@ release: dist install: clean generate install-requirements python setup.py install + python fix_imports.py diff --git a/fix_imports.py b/fix_imports.py new file mode 100644 index 0000000..d5416a1 --- /dev/null +++ b/fix_imports.py @@ -0,0 +1,31 @@ +import re +import os + +from pathlib import Path + + +REGEXP = re.compile( + r"(from )" + r"(" + r"clients|collaborators|collections|common|delivery|environments|extensions|files|images|invitations" + r"|items|locales|members|organizations|references|roles|spaces|status|users|versions.+|" + r")" + r"( import.*pb2)" +) +PERXIS_DIR_NAME = "perxis" +PERXIS_PATH = (Path(__file__).parent.absolute()).joinpath(PERXIS_DIR_NAME) + + +def main(): + for path, _, files in os.walk(PERXIS_PATH): + for name in files: + file_path = os.path.join(path, name) + with open(file_path, "r+") as f: + text = f.read() + result = re.sub(REGEXP, rf"\1{PERXIS_DIR_NAME}.\2\3", text) + f.seek(0) + f.write(result) + + +if __name__ == "__main__": + main() -- GitLab