Skip to content

Commit

Permalink
Merge branch 'automatic-merge' into 'master'
Browse files Browse the repository at this point in the history
Add build_wheel.py changes from e3-cli

See merge request it/e3-core!88
  • Loading branch information
adanaja committed Jan 15, 2025
2 parents 55a4007 + 38bf5d6 commit 2597023
Showing 1 changed file with 46 additions and 18 deletions.
64 changes: 46 additions & 18 deletions build_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pathlib import Path
import re
import tomllib
from datetime import datetime, timezone

from e3.main import Main
from e3.os.process import Run
Expand Down Expand Up @@ -46,7 +47,22 @@ def main() -> None:
default="pyproject.toml",
help="Path to a Python project or pyproject.toml file",
)
parser.add_argument("--dry-run", action="store_true", help="Do not build the wheel")
parser.add_argument(
"--template", default="{major}.{minor}.{patch}", help="Version number template"
)
parser.add_argument(
"--dry-run",
action="store_true",
help="Do not change the version file nor build the wheel",
)
parser.add_argument(
"--no-build", action="store_true", help="Do not build the wheel"
)
parser.add_argument(
"--no-restore",
action="store_true",
help="Keep the modified version file with the computed build version",
)

main.parse_args()
assert main.args
Expand Down Expand Up @@ -131,7 +147,17 @@ def main() -> None:
["git", "rev-list", f"{previous_commit_sha}..HEAD", "--count"],
cwd=root_dir,
)
build_version = f"{version_major}.{version_minor}.{output.strip()}"

# Get the build version from custom version template
date = datetime.now(tz=timezone.utc)
build_version = main.args.template.format(
major=version_major,
minor=version_minor,
patch=output.strip(),
year=f"{date.year:04}",
month=f"{date.month:02}",
day=f"{date.day:02}",
)
logger.info(f"{version_major}.{version_minor} -> {build_version}")

if not main.args.dry_run:
Expand All @@ -141,24 +167,26 @@ def main() -> None:

try:
# Build the wheel
run(
[
sys.executable,
"-m",
"pip",
"wheel",
".",
"-q",
"--no-deps",
"-C--python-tag=py3",
"-w",
"build",
],
cwd=root_dir,
)
if not main.args.no_build:
run(
[
sys.executable,
"-m",
"pip",
"wheel",
".",
"-q",
"--no-deps",
"-C--python-tag=py3",
"-w",
"build",
],
cwd=root_dir,
)
finally:
# Revert change to version file
run(["git", "restore", version_path], cwd=root_dir, fail_ok=True)
if not main.args.no_restore:
run(["git", "restore", version_path], cwd=root_dir, fail_ok=True)


if __name__ == "__main__":
Expand Down

0 comments on commit 2597023

Please sign in to comment.