From 4cd02917f0061db6c5ede559a8f223c9f1f136b4 Mon Sep 17 00:00:00 2001 From: Peter Rauscher Date: Wed, 28 Feb 2024 15:43:50 -0500 Subject: [PATCH] OpenAPI metadata changes --- .gitignore | 1 + bump-release.py | 58 +++++++++++++++++++++++++++----------------- pyproject.toml | 2 +- src/api/__about__.py | 1 - src/api/main.py | 5 ++-- 5 files changed, 41 insertions(+), 26 deletions(-) delete mode 100644 src/api/__about__.py diff --git a/.gitignore b/.gitignore index 83c3bfc..66cdce5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.env *.pyc +*__pycache__/ env/ dist/ cert.pem diff --git a/bump-release.py b/bump-release.py index 8f07e84..16f2eb8 100644 --- a/bump-release.py +++ b/bump-release.py @@ -1,28 +1,42 @@ -# updates the version number in the __about__.py file import subprocess - +import re def update_version(version_type): - with open("src/api/__about__.py", "r") as f: - version = f.read().split("=")[1].replace('"', "").strip() - patch_version = version.split(".")[2] - minor_version = version.split(".")[1] - major_version = version.split(".")[0] - if version_type == "major": - major_version = str(int(major_version) + 1) - minor_version = "0" - patch_version = "0" - elif version_type == "minor": - minor_version = str(int(minor_version) + 1) - patch_version = "0" - elif version_type == "patch": - patch_version = str(int(patch_version) + 1) - else: - raise ValueError("Invalid version type. Please use major, minor, or patch.") - with open("src/api/__about__.py", "w") as f: - new_version = f"{major_version}.{minor_version}.{patch_version}" - f.write(f'__version__ = "{new_version}"\n') - return f"v{new_version}" + filepath = "src/api/main.py" + with open(filepath, "r") as f: + lines = f.readlines() + + version_line_index = None + version_pattern = re.compile(r'^__version__\s*=\s*["\'](\d+)\.(\d+)\.(\d+)["\']\s*$') + for i, line in enumerate(lines): + if version_pattern.match(line): + version_line_index = i + break + + if version_line_index is None: + raise ValueError("Version line not found.") + + current_version = version_pattern.match(lines[version_line_index]) + major_version, minor_version, patch_version = current_version.groups() + if version_type == "major": + major_version = str(int(major_version) + 1) + minor_version = "0" + patch_version = "0" + elif version_type == "minor": + minor_version = str(int(minor_version) + 1) + patch_version = "0" + elif version_type == "patch": + patch_version = str(int(patch_version) + 1) + else: + raise ValueError("Invalid version type. Please use major, minor, or patch.") + + new_version = f'{major_version}.{minor_version}.{patch_version}' + lines[version_line_index] = f'__version__ = "{new_version}"\n' + + with open(filepath, "w") as file: + file.writelines(lines) + + return f"v{new_version}" # passes the command line argument to the function diff --git a/pyproject.toml b/pyproject.toml index ee9cdee..f108b10 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ dependencies = [ ] [tool.hatch.version] -path = "src/api/__about__.py" +path = "src/api/main.py" [tool.hatch.metadata] allow-direct-references = true diff --git a/src/api/__about__.py b/src/api/__about__.py deleted file mode 100644 index 92192ee..0000000 --- a/src/api/__about__.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "1.0.4" diff --git a/src/api/main.py b/src/api/main.py index 9349c96..ce59e1c 100644 --- a/src/api/main.py +++ b/src/api/main.py @@ -1,3 +1,5 @@ +__version__ = "1.0.5" + import os from dotenv import load_dotenv @@ -13,7 +15,6 @@ from api.data.instance import DATABASE_NAME, client from api.routes import auth, sneakers -import api.__about__.__version__ as api_version desc = """ # SoleSearch @@ -27,7 +28,7 @@ redoc_url=None, title="SoleSearch", summary="The sneaker reseller's Bloomberg Terminal.", - version=api_version, + version=__version__, contact={ "name": "SoleSearch Developer Support", "email": "support@solesearch.io"