Skip to content

Commit

Permalink
Merge pull request #15 from SoleSearch-Demos/main
Browse files Browse the repository at this point in the history
OpenAPI metadata changes
  • Loading branch information
peterrauscher authored Feb 28, 2024
2 parents 7342b5b + 4cd0291 commit 5d397c9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.env
*.pyc
*__pycache__/
env/
dist/
cert.pem
Expand Down
58 changes: 36 additions & 22 deletions bump-release.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/api/__about__.py

This file was deleted.

5 changes: 3 additions & 2 deletions src/api/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__version__ = "1.0.5"

import os

from dotenv import load_dotenv
Expand All @@ -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
Expand All @@ -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": "[email protected]"
Expand Down

0 comments on commit 5d397c9

Please sign in to comment.