-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
6 changed files
with
95 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from loguru import logger | ||
import toml | ||
import os | ||
from datetime import datetime | ||
import re | ||
|
||
|
||
def get_build_type(): | ||
return os.getenv("GUIDELLM_BUILD_TYPE", "dev") | ||
|
||
|
||
def get_build_number(): | ||
return os.getenv("GUIDELLM_BUILD_NUMBER", "0") | ||
|
||
|
||
def construct_project_name_and_version(build_type, build_number, current_version): | ||
if not re.match(r"^\d+\.\d+\.\d+$", current_version): | ||
raise ValueError( | ||
f"Version '{current_version}' does not match the " | ||
f"semantic versioning pattern '#.#.#'" | ||
) | ||
|
||
if build_type == "dev": | ||
project_name = "guidellm_dev" | ||
version = f"{current_version}.dev{build_number}" | ||
elif build_type == "nightly": | ||
project_name = "guidellm_nightly" | ||
date_str = datetime.now().strftime("%Y%m%d") | ||
version = f"{current_version}.{date_str}" | ||
elif build_type == "release": | ||
project_name = "guidellm" | ||
version = current_version | ||
else: | ||
raise ValueError(f"Unknown build type: {build_type}") | ||
|
||
return project_name, version | ||
|
||
|
||
def update_pyproject_toml(project_name, version): | ||
try: | ||
with open("pyproject.toml", "r") as file: | ||
data = toml.load(file) | ||
|
||
data["project"]["name"] = project_name | ||
data["project"]["version"] = version | ||
|
||
with open("pyproject.toml", "w") as file: | ||
toml.dump(data, file) | ||
|
||
logger.info( | ||
f"Updated project name to: {project_name} and version to: {version}" | ||
) | ||
except (FileNotFoundError, toml.TomlDecodeError) as e: | ||
logger.error(f"Error reading or writing pyproject.toml: {e}") | ||
raise | ||
|
||
|
||
def main(): | ||
try: | ||
build_type = get_build_type() | ||
build_number = get_build_number() | ||
|
||
with open("pyproject.toml", "r") as file: | ||
pyproject_data = toml.load(file) | ||
|
||
current_version = pyproject_data["project"]["version"] | ||
project_name, version = construct_project_name_and_version( | ||
build_type, build_number, current_version | ||
) | ||
|
||
if build_type != "release": | ||
update_pyproject_toml(project_name, version) | ||
except Exception as e: | ||
logger.error(f"An error occurred: {e}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |