Skip to content

Commit 88e6c12

Browse files
authored
Adapt build system for dynamic versioning and package naming based on build settings (#19)
## Summary Enhances the build system by introducing dynamic versioning and package naming based on the build type and build number, which are loaded from env variables. ## Details - Dynamic Versioning: The build version is now determined dynamically based on the environment variables GUIDELLM_BUILD_TYPE and GUIDELLM_BUILD_NUMBER. This allows for flexible versioning strategies such as dev, nightly, and release builds. - Package Naming: The package name is adapted according to the build type, supporting different names for dev, nightly, and release versions. - Script Addition: Added utils/inject_build_props.py to automate the injection of build properties into the pyproject.toml file. - Dependencies: Updated dependencies in pyproject.toml to enable pre script builds. - CI/CD Integration: Updated tox.ini to integrate the new build script and ensure all checks are aligned with the updated build process. - Code Cleanup: Removed unused dependencies from .pre-commit-config.yaml.. ## Test Plan - Manually tested the build process for dev, nightly, and release builds to ensure proper versioning and naming.
1 parent a6d115d commit 88e6c12

File tree

6 files changed

+95
-14
lines changed

6 files changed

+95
-14
lines changed

.pre-commit-config.yaml

+2-9
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ repos:
88
rev: v0.5.2
99
hooks:
1010
- id: ruff
11-
- repo: https://github.com/psf/black-pre-commit-mirror
12-
rev: 24.4.2
13-
hooks:
14-
- id: black
15-
- repo: https://github.com/pycqa/isort
16-
rev: 5.13.2
17-
hooks:
18-
- id: isort
1911
- repo: https://github.com/pre-commit/mirrors-mypy
2012
rev: v1.10.1
2113
hooks:
@@ -39,6 +31,7 @@ repos:
3931

4032
# types
4133
types-click,
42-
types-requests,
4334
types-PyYAML,
35+
types-requests,
36+
types-toml,
4437
]

pyproject.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ dev = [
5454

5555
# type-checking
5656
"types-click~=7.1.8",
57-
"types-requests~=2.32.0",
5857
"types-PyYAML~=6.0.1",
58+
"types-requests~=2.32.0",
59+
"types-toml",
5960
]
6061

6162

@@ -85,7 +86,7 @@ show_error_codes = true
8586
namespace_packages = true
8687
exclude = ["venv", ".tox"]
8788

88-
# Silint "type import errors" as our 3rd-party libs does not have types
89+
# Silence "type import errors" as our 3rd-party libs does not have types
8990
# Check: https://mypy.readthedocs.io/en/latest/config_file.html#import-discovery
9091
follow_imports = 'silent'
9192

src/guidellm/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55

66
from .logger import LoggerConfig, configure_logger, logger
77

8-
__all__ = ["logger", "configure_logger", "LoggerConfig"]
8+
__all__ = [
9+
"logger",
10+
"configure_logger",
11+
"LoggerConfig",
12+
]

src/guidellm/py.typed

Whitespace-only changes.

tox.ini

+7-2
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ description = Run all quality checks
4040
deps =
4141
.[dev]
4242
commands =
43-
ruff check src tests
43+
ruff check src tests utils
4444

4545

4646
[testenv:style]
4747
description = Run style checks and fixes
4848
deps =
4949
.[dev]
5050
commands =
51-
ruff format src tests
51+
ruff format src tests utils
5252

5353

5454
[testenv:types]
@@ -65,7 +65,10 @@ deps =
6565
build
6666
setuptools
6767
wheel
68+
loguru
69+
toml
6870
commands =
71+
python utils/inject_build_props.py
6972
python -m build
7073

7174

@@ -82,3 +85,5 @@ commands =
8285
rm -rf .mypy_cache
8386
rm -rf .pytest_cache
8487
rm -rf .tox
88+
rm -rf .ruff_cache
89+
rm -rf .coverage

utils/inject_build_props.py

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from loguru import logger
2+
import toml
3+
import os
4+
from datetime import datetime
5+
import re
6+
7+
8+
def get_build_type():
9+
return os.getenv("GUIDELLM_BUILD_TYPE", "dev")
10+
11+
12+
def get_build_number():
13+
return os.getenv("GUIDELLM_BUILD_NUMBER", "0")
14+
15+
16+
def construct_project_name_and_version(build_type, build_number, current_version):
17+
if not re.match(r"^\d+\.\d+\.\d+$", current_version):
18+
raise ValueError(
19+
f"Version '{current_version}' does not match the "
20+
f"semantic versioning pattern '#.#.#'"
21+
)
22+
23+
if build_type == "dev":
24+
project_name = "guidellm_dev"
25+
version = f"{current_version}.dev{build_number}"
26+
elif build_type == "nightly":
27+
project_name = "guidellm_nightly"
28+
date_str = datetime.now().strftime("%Y%m%d")
29+
version = f"{current_version}.{date_str}"
30+
elif build_type == "release":
31+
project_name = "guidellm"
32+
version = current_version
33+
else:
34+
raise ValueError(f"Unknown build type: {build_type}")
35+
36+
return project_name, version
37+
38+
39+
def update_pyproject_toml(project_name, version):
40+
try:
41+
with open("pyproject.toml", "r") as file:
42+
data = toml.load(file)
43+
44+
data["project"]["name"] = project_name
45+
data["project"]["version"] = version
46+
47+
with open("pyproject.toml", "w") as file:
48+
toml.dump(data, file)
49+
50+
logger.info(
51+
f"Updated project name to: {project_name} and version to: {version}"
52+
)
53+
except (FileNotFoundError, toml.TomlDecodeError) as e:
54+
logger.error(f"Error reading or writing pyproject.toml: {e}")
55+
raise
56+
57+
58+
def main():
59+
try:
60+
build_type = get_build_type()
61+
build_number = get_build_number()
62+
63+
with open("pyproject.toml", "r") as file:
64+
pyproject_data = toml.load(file)
65+
66+
current_version = pyproject_data["project"]["version"]
67+
project_name, version = construct_project_name_and_version(
68+
build_type, build_number, current_version
69+
)
70+
71+
if build_type != "release":
72+
update_pyproject_toml(project_name, version)
73+
except Exception as e:
74+
logger.error(f"An error occurred: {e}")
75+
76+
77+
if __name__ == "__main__":
78+
main()

0 commit comments

Comments
 (0)