RAPTOR v18.4: Исправлена отчетность, активированы выходные
This commit is contained in:
0
invest-python-master/scripts/__init__.py
Normal file
0
invest-python-master/scripts/__init__.py
Normal file
93
invest-python-master/scripts/download_protos.py
Normal file
93
invest-python-master/scripts/download_protos.py
Normal file
@@ -0,0 +1,93 @@
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
from http import HTTPStatus
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
|
||||
import requests
|
||||
|
||||
BRANCH = "master"
|
||||
URL = f"https://opensource.tbank.ru/invest/invest-contracts/-/archive/{BRANCH}/invest-contracts-{BRANCH}.zip?ref_type=heads"
|
||||
OUTPUT_PATH = "protos/t_tech/invest/grpc"
|
||||
PROTOS_TMP_ZIP = "protos.zip"
|
||||
ZIP_PROTOS_ROOT_PATH_BRANCH = BRANCH.replace("/", "-")
|
||||
ZIP_PROTOS_ROOT_PATH = f"invest-contracts-{ZIP_PROTOS_ROOT_PATH_BRANCH}"
|
||||
ZIP_PROTOS_PATH = f"{ZIP_PROTOS_ROOT_PATH}/src/docs/contracts"
|
||||
FILES = [
|
||||
"google/api/field_behavior.proto",
|
||||
"common.proto",
|
||||
"instruments.proto",
|
||||
"marketdata.proto",
|
||||
"operations.proto",
|
||||
"orders.proto",
|
||||
"sandbox.proto",
|
||||
"signals.proto",
|
||||
"stoporders.proto",
|
||||
"users.proto",
|
||||
]
|
||||
|
||||
LINES_TO_REPLACE = [
|
||||
(f'import "{file_name}";', f'import "t_tech/invest/grpc/{file_name}";')
|
||||
for file_name in FILES
|
||||
]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
_clear_in_start()
|
||||
_download_protos()
|
||||
_extract_protos()
|
||||
_move_protos()
|
||||
_clear_in_end()
|
||||
_modify_protos()
|
||||
return 0
|
||||
|
||||
|
||||
def _clear_in_start():
|
||||
shutil.rmtree(OUTPUT_PATH, ignore_errors=True)
|
||||
|
||||
|
||||
def _download_protos():
|
||||
session = requests.session()
|
||||
response = session.get(URL, stream=True)
|
||||
if response.status_code != HTTPStatus.OK:
|
||||
return
|
||||
|
||||
with open(PROTOS_TMP_ZIP, "wb") as f:
|
||||
for chunk in response:
|
||||
f.write(chunk)
|
||||
|
||||
|
||||
def _extract_protos():
|
||||
with ZipFile(PROTOS_TMP_ZIP) as zf:
|
||||
for name in FILES:
|
||||
zf.extract(f"{ZIP_PROTOS_PATH}/{name}", path=".")
|
||||
|
||||
|
||||
def _move_protos():
|
||||
os.makedirs(OUTPUT_PATH, exist_ok=True)
|
||||
for name in FILES:
|
||||
folders = "/".join(name.split("/")[:-1])
|
||||
Path(f"{OUTPUT_PATH}/{folders}").mkdir(parents=True, exist_ok=True)
|
||||
shutil.move(f"{ZIP_PROTOS_PATH}/{name}", f"{OUTPUT_PATH}/{folders}")
|
||||
|
||||
|
||||
def _clear_in_end():
|
||||
os.remove(PROTOS_TMP_ZIP)
|
||||
shutil.rmtree(ZIP_PROTOS_ROOT_PATH)
|
||||
|
||||
|
||||
def _modify_protos():
|
||||
for name in FILES:
|
||||
with open(f"{OUTPUT_PATH}/{name}", "r", encoding="utf-8") as f:
|
||||
protofile_text = f.read()
|
||||
|
||||
for str_to_replace, replaced_str in LINES_TO_REPLACE:
|
||||
protofile_text = protofile_text.replace(str_to_replace, replaced_str)
|
||||
|
||||
with open(f"{OUTPUT_PATH}/{name}", "w+", encoding="utf-8") as f:
|
||||
f.write(protofile_text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
28
invest-python-master/scripts/update_issue_templates.py
Normal file
28
invest-python-master/scripts/update_issue_templates.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import sys
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
def add_version(version: str, file: str) -> None:
|
||||
with open(file, "r", encoding="utf-8") as f:
|
||||
data = yaml.safe_load(f)
|
||||
for field in data["body"]:
|
||||
if field.get("id", "") == "package-version":
|
||||
field["attributes"]["options"] = [
|
||||
version,
|
||||
*field["attributes"]["options"],
|
||||
]
|
||||
with open(file, "w+", encoding="utf-8") as f:
|
||||
yaml.dump(
|
||||
data, f, default_flow_style=False, sort_keys=False, allow_unicode=True
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
version = sys.argv[1]
|
||||
add_version(version, ".github/ISSUE_TEMPLATE/bug_report.yaml")
|
||||
add_version(version, ".github/ISSUE_TEMPLATE/issue.yaml")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
23
invest-python-master/scripts/update_package_version.py
Normal file
23
invest-python-master/scripts/update_package_version.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def set_version(new_value: str, constant_name: str, file_path: str) -> None:
|
||||
with open(file_path, "r") as file:
|
||||
file_data = file.read()
|
||||
|
||||
constant_pattern = re.compile(rf'{constant_name}\s*=\s*["\'].*?["\']', re.MULTILINE)
|
||||
file_data = constant_pattern.sub(f'{constant_name} = "{new_value}"', file_data)
|
||||
|
||||
with open(file_path, "w") as file:
|
||||
file.write(file_data)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
version = sys.argv[1]
|
||||
set_version(version, "__version__", "t_tech/invest/__init__.py")
|
||||
set_version(version, "APP_VERSION", "t_tech/invest/constants.py")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
59
invest-python-master/scripts/version.py
Normal file
59
invest-python-master/scripts/version.py
Normal file
@@ -0,0 +1,59 @@
|
||||
import re
|
||||
from typing import Tuple
|
||||
|
||||
from tomlkit import loads
|
||||
|
||||
Version = Tuple[str, str, str, str, str]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
current_version = get_current_version()
|
||||
print( # noqa:T201,T001
|
||||
version_to_str(next_beta_version(parse_version(version=current_version)))
|
||||
)
|
||||
|
||||
|
||||
def get_current_version():
|
||||
with open("pyproject.toml", "r", encoding="utf-8") as f:
|
||||
pyproject = loads(f.read())
|
||||
current_version: str = pyproject["project"]["version"] # type:ignore
|
||||
return current_version
|
||||
|
||||
|
||||
def parse_version(version: str) -> Version:
|
||||
pattern = re.compile(
|
||||
r"^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$" # noqa:E501 # pylint:disable=line-too-long
|
||||
)
|
||||
match = pattern.search(version)
|
||||
if not match:
|
||||
raise ValueError(f"{version} is not a version")
|
||||
|
||||
return tuple(n and str(n) or "" for n in match.groups(0)) # type:ignore
|
||||
|
||||
|
||||
def next_beta_version(version: Version) -> Version:
|
||||
major, minor, patch, prerelease, buildmetadata = version
|
||||
if not prerelease:
|
||||
return major, minor, str(int(patch) + 1), prerelease, buildmetadata
|
||||
prerelease_n = int(remove_prefix(prerelease, "beta"))
|
||||
return (major, minor, patch, "beta" + str(prerelease_n + 1), buildmetadata)
|
||||
|
||||
|
||||
def version_to_str(version: Version) -> str:
|
||||
major, minor, patch, prerelease, _ = version
|
||||
return (
|
||||
f"{major}.{minor}.{patch}-{prerelease}"
|
||||
if prerelease
|
||||
else f"{major}.{minor}.{patch}"
|
||||
)
|
||||
|
||||
|
||||
def remove_prefix(text: str, prefix: str) -> str:
|
||||
if text.startswith(prefix):
|
||||
prefix_len = len(prefix)
|
||||
return text[prefix_len:]
|
||||
return text
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user