Skip to content

Commit

Permalink
Adapt build system for dynamic versioning and package naming based on…
Browse files Browse the repository at this point in the history
… 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
markurtz authored Jul 25, 2024
1 parent a6d115d commit 88e6c12
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 14 deletions.
11 changes: 2 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ repos:
rev: v0.5.2
hooks:
- id: ruff
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
hooks:
Expand All @@ -39,6 +31,7 @@ repos:

# types
types-click,
types-requests,
types-PyYAML,
types-requests,
types-toml,
]
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ dev = [

# type-checking
"types-click~=7.1.8",
"types-requests~=2.32.0",
"types-PyYAML~=6.0.1",
"types-requests~=2.32.0",
"types-toml",
]


Expand Down Expand Up @@ -85,7 +86,7 @@ show_error_codes = true
namespace_packages = true
exclude = ["venv", ".tox"]

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

Expand Down
6 changes: 5 additions & 1 deletion src/guidellm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@

from .logger import LoggerConfig, configure_logger, logger

__all__ = ["logger", "configure_logger", "LoggerConfig"]
__all__ = [
"logger",
"configure_logger",
"LoggerConfig",
]
Empty file removed src/guidellm/py.typed
Empty file.
9 changes: 7 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ description = Run all quality checks
deps =
.[dev]
commands =
ruff check src tests
ruff check src tests utils


[testenv:style]
description = Run style checks and fixes
deps =
.[dev]
commands =
ruff format src tests
ruff format src tests utils


[testenv:types]
Expand All @@ -65,7 +65,10 @@ deps =
build
setuptools
wheel
loguru
toml
commands =
python utils/inject_build_props.py
python -m build


Expand All @@ -82,3 +85,5 @@ commands =
rm -rf .mypy_cache
rm -rf .pytest_cache
rm -rf .tox
rm -rf .ruff_cache
rm -rf .coverage
78 changes: 78 additions & 0 deletions utils/inject_build_props.py
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()

0 comments on commit 88e6c12

Please sign in to comment.