Skip to content
Snippets Groups Projects

Реализован скрипт замены некорректных импортов

Merged Anton Teplyakov requested to merge bugfix/import_errors into master
1 unresolved thread
1 file
+ 2
2
Compare changes
  • Side-by-side
  • Inline
fix_imports.py 0 → 100644
+ 31
0
 
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_DIR_PATH = (Path(__file__).parent.absolute()).joinpath(PERXIS_DIR_NAME)
 
 
 
def main():
 
for path, _, files in os.walk(PERXIS_DIR_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()
Loading